[aadk-commits] dbailey: u-boot/trunk r140 - in
/u-boot/trunk/u-boot_1.1.3: board/s800i/ comm...
aadk-commits at lists.digium.com
aadk-commits at lists.digium.com
Tue Jan 30 13:37:29 MST 2007
Author: dbailey
Date: Tue Jan 30 14:37:28 2007
New Revision: 140
URL: http://svn.digium.com/view/aadk?view=rev&rev=140
Log:
Made u-boot aware of I2C eeprom device. Added a command to display the parameters stored in the eeprom.
Changed code so that MAC address is pulled from I2C device as opposed to the SPI based u-boot environment.
Changed the order of initialization so that I2C is initialized before MAC address is loaded.
Added:
u-boot/trunk/u-boot_1.1.3/board/s800i/dig_i2c_eeprom.h (with props)
u-boot/trunk/u-boot_1.1.3/board/s800i/i2c_cfg.c (with props)
Modified:
u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile
u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c
u-boot/trunk/u-boot_1.1.3/common/cmd_nvedit.c
u-boot/trunk/u-boot_1.1.3/include/configs/s800i.h
u-boot/trunk/u-boot_1.1.3/lib_blackfin/board.c
Modified: u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile?view=diff&rev=140&r1=139&r2=140
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile (original)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile Tue Jan 30 14:37:28 2007
@@ -29,7 +29,7 @@
LIB = lib$(BOARD).a
-OBJS = $(BOARD).o flash.o ether_bf537.o post-memory.o stm_m25p64.o adm.o i2c.o
+OBJS = $(BOARD).o flash.o ether_bf537.o post-memory.o stm_m25p64.o adm.o i2c.o i2c_cfg.o
$(LIB): .depend $(OBJS)
$(AR) crv $@ $(OBJS)
Added: u-boot/trunk/u-boot_1.1.3/board/s800i/dig_i2c_eeprom.h
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/dig_i2c_eeprom.h?view=auto&rev=140
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/dig_i2c_eeprom.h (added)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/dig_i2c_eeprom.h Tue Jan 30 14:37:28 2007
@@ -1,0 +1,40 @@
+#ifndef _UBOOT_DIG_I2C_ESEPROM_H
+#define _UBOOT_DIG_I2C_ESEPROM_H
+
+#define I2C_PROM_ADDRESS (0x50)
+#define I2C_PROM_SIZE (128)
+
+#define CRC_LOC (I2C_PROM_SIZE-4)
+#define I2C_24C01_PAGE_SIZE (8)
+
+/*
+ * Enumerate the fields stored in the I2C eeprom
+ * (DIGCMD_NULL used as an end of data marker)
+ */
+enum cmd_state {
+ DIGCMD_BOARD_REVISION = 0,
+ DIGCMD_MAC_ADDRESS,
+ DIGCMD_PRODUCT_SKU,
+ DIGCMD_MFG_DATE,
+ DIGCMD_MFG_VENDOR,
+ DIGCMD_CAPABILITY_CODE,
+ DIGCMD_CRC,
+ DIGCMD_NULL
+};
+
+/*
+ * Structure indicating the type of data, the size of the data,
+ * and where it is located in the memory block
+ */
+struct rom_location {
+ enum cmd_state state;
+ int offset;
+ int size;
+};
+
+extern const struct rom_location eeprom_map[];
+
+/*** Prototype ***/
+int get_i2c_mac(unsigned char * mac); //DBDEBUG temporary
+
+#endif
Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/dig_i2c_eeprom.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/dig_i2c_eeprom.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c?view=diff&rev=140&r1=139&r2=140
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c (original)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c Tue Jan 30 14:37:28 2007
@@ -31,6 +31,10 @@
#ifdef CONFIG_POST
#include <post.h>
+#endif
+
+#ifdef CONFIG_S800I
+#include "dig_i2c_eeprom.h"
#endif
#undef DEBUG_ETHERNET
@@ -251,10 +255,54 @@
}
+#ifdef CONFIG_S800I
void SetupMacAddr(u8 *MACaddr)
{
+ DECLARE_GLOBAL_DATA_PTR;
+
+ bd_t *bd = gd->bd;
+ char *tmp = NULL;
+ char *end;
+ char mac_str[6*3];
+ int i, j;
+ int valid;
+ int res;
+
+ /* First attempt to get the MAC from the i2c eeprom */
+ valid = !get_i2c_mac(MACaddr);
+ /* If the i2c is not available the standard u-boot variable */
+ if(!valid){
+ tmp = getenv("ethaddr");
+ if(tmp){
+ valid = 1;
+
+ for(i=0;i<6;i++){
+ MACaddr[i] = (u8)(simple_strtoul(tmp, &end, 16));
+ tmp = (*end)?end+1:end;
+ }
+ }
+ }
+ /* If I have a valid MAC address, load the appropriate varaibles */
+ if(valid){
+ sprintf(mac_str,"%02X:%02X:%02X:%02X:%02X:%02X", MACaddr[0],MACaddr[1],
+ MACaddr[2],MACaddr[3],MACaddr[4],MACaddr[5]);
+ printf("EthMAC: %s\n", mac_str);
+ /* Set the device registers */
+ *pEMAC_ADDRLO = *(u32 *)&MACaddr[0];
+ *pEMAC_ADDRHI = *(u16 *)&MACaddr[4];
+ /* Make the MAC available to the net functions */
+ memcpy (bd->bi_enetaddr, MACaddr, 6);
+ /* If the MAC was not pulled from the u-boot MAC environment */
+ if(NULL == tmp) {
+ setenv("ethaddr", mac_str);
+ }
+ }
+}
+#else
+void SetupMacAddr(u8 *MACaddr)
+{
char *tmp,*end;
- int i;
+ int i;
/* this depends on a little-endian machine */
tmp = getenv("ethaddr");
if(tmp){
@@ -263,13 +311,14 @@
if(tmp)
tmp = (*end)?end+1:end;
}
-
- printf("EthMAC: %02X:%02X:%02X:%02X:%02X:%02X\n",MACaddr[0],MACaddr[1],
- MACaddr[2],MACaddr[3],MACaddr[4],MACaddr[5]);
- *pEMAC_ADDRLO = *(u32 *)&MACaddr[0];
- *pEMAC_ADDRHI = *(u16 *)&MACaddr[4];
- }
-}
+
+ printf("Using MAC Address %02X:%02X:%02X:%02X:%02X:%02X\n",MACaddr[0],MACaddr[1],
+ MACaddr[2],MACaddr[3],MACaddr[4],MACaddr[5]);
+ *pEMAC_ADDRLO = MACaddr[0] | MACaddr[1]<<8 | MACaddr[2] <<16 | MACaddr[3] << 24;
+ *pEMAC_ADDRHI = MACaddr[4] | MACaddr[5]<<8;
+ }
+}
+#endif
#if 0
void SoftResetPHY(void)
Added: u-boot/trunk/u-boot_1.1.3/board/s800i/i2c_cfg.c
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/i2c_cfg.c?view=auto&rev=140
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/i2c_cfg.c (added)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/i2c_cfg.c Tue Jan 30 14:37:28 2007
@@ -1,0 +1,165 @@
+/*
+ * (C) Copyright 2007
+ * Doug Bailey, Digium Inc., dbailey at digium.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <common.h>
+#include <command.h>
+#include <i2c.h>
+#include <asm/byteorder.h>
+
+#include "dig_i2c_eeprom.h"
+
+/* Map of where data is stored in the i2c eeprom */
+const struct rom_location eeprom_map[] = {
+ { .state = DIGCMD_BOARD_REVISION, .offset = 0, .size = 16},
+ { .state = DIGCMD_PRODUCT_SKU, .offset =16, .size = 16},
+ { .state = DIGCMD_MAC_ADDRESS, .offset =32, .size = 6},
+ { .state = DIGCMD_MFG_DATE, .offset =38, .size = 4},
+ { .state = DIGCMD_MFG_VENDOR, .offset =42, .size = 4},
+ { .state = DIGCMD_CAPABILITY_CODE, .offset =46, .size = 32},
+ { .state = DIGCMD_CRC, .offset =CRC_LOC,.size = 4},
+ { .state = DIGCMD_NULL, .offset =0, .size = I2C_PROM_SIZE}
+};
+
+
+/*
+ * Retrieve the MAC address stored in i2c EEPROM memory
+ */
+int get_i2c_mac(unsigned char * mac)
+{
+ int i, j;
+ unsigned char prom_image[I2C_PROM_SIZE +1];
+ ulong conv_num;
+ uchar chip = I2C_PROM_ADDRESS;
+
+ /* Get the contents of the existing eeprom */
+ if (0 != i2c_read(chip, 0, 1, prom_image,I2C_PROM_SIZE)) {
+ printf("Cannot read the I2C memory IC\n");
+ return -1;
+ }
+ /* Validate the data in the field. */
+ conv_num = crc32(0, prom_image, CRC_LOC);
+ if(*(ulong *)(&prom_image[CRC_LOC]) != conv_num) {
+ printf("CRC is not valid on the I2C memory IC\n");
+ return -1;
+ }
+
+ for(i = 0; DIGCMD_NULL != eeprom_map[i].state; i++) {
+ /* Set the MAC address to what was stored here */
+ if(DIGCMD_MAC_ADDRESS == eeprom_map[i].state) {
+ for(j = 0; j < 6; j++){
+ mac[j] = prom_image[eeprom_map[i].offset +j];
+ }
+ break;
+ }
+ }
+ return 0;
+}
+
+
+/*
+ * Command to display the settings stored in the I2C PROM
+ */
+static int do_print_i2c_cfg( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ unsigned char prom_image[I2C_PROM_SIZE +1];
+ unsigned char disp_buffer[I2C_PROM_SIZE];
+ ulong conv_num;
+ int i;
+ char * parse;
+ struct rom_location * curr_field;
+ int nbytes;
+ uchar chip = I2C_PROM_ADDRESS;
+
+ /* Get the contents of the existing eeprom */
+ if (0 != i2c_read(chip, 0, 1, prom_image,I2C_PROM_SIZE)) {
+ printf("Cannot access serial EEPROM\n");
+ return -1;
+ }
+
+ conv_num = crc32(0, prom_image, CRC_LOC);
+ if(*(ulong *)(&prom_image[CRC_LOC]) != conv_num) {
+ printf("Existing eeprom is are invalid\n");
+ return -1;
+ }
+
+ printf("************* I2C Configuration Data ************\n");
+ curr_field = &eeprom_map[0];
+
+ while(curr_field->state != DIGCMD_NULL){
+ switch(curr_field->state){
+ case DIGCMD_BOARD_REVISION:
+ strncpy(disp_buffer, &prom_image[curr_field->offset], curr_field->size);
+ disp_buffer[curr_field->size] = '\0';
+ printf("Board Revision=%s\n", disp_buffer);
+ break;
+
+ case DIGCMD_PRODUCT_SKU:
+ strncpy(disp_buffer, &prom_image[curr_field->offset], curr_field->size);
+ disp_buffer[curr_field->size] = '\0';
+ printf("Product SKU=%s\n", disp_buffer);
+ break;
+
+ case DIGCMD_MFG_VENDOR:
+ strncpy(disp_buffer, &prom_image[curr_field->offset], curr_field->size);
+ disp_buffer[curr_field->size] = '\0';
+ printf("MFG Vendor Code=%s\n", disp_buffer);
+ break;
+
+ case DIGCMD_MAC_ADDRESS:
+ sprintf(disp_buffer, "%02x:%02x:%02x:%02x:%02x:%02x",
+ prom_image[curr_field->offset],
+ prom_image[curr_field->offset +1],
+ prom_image[curr_field->offset +2],
+ prom_image[curr_field->offset +3],
+ prom_image[curr_field->offset +4],
+ prom_image[curr_field->offset +5]);
+ printf("MAC address=%s\n", disp_buffer);
+ break;
+
+ case DIGCMD_MFG_DATE:
+ strncpy(disp_buffer, &prom_image[curr_field->offset], curr_field->size);
+ disp_buffer[curr_field->size] = '\0';
+ printf("MFG Date Code=%s\n", disp_buffer);
+ break;
+
+ case DIGCMD_CAPABILITY_CODE:
+ strncpy(disp_buffer, &prom_image[curr_field->offset], curr_field->size);
+ disp_buffer[curr_field->size] = '\0';
+ printf("MFG Date Code=%s\n", disp_buffer);
+ break;
+ case DIGCMD_CRC:
+ break;
+ default:
+ printf("INTERNAL ERROR: Unrecognised data entry field\n");
+ break;
+ }
+ curr_field++;
+ }
+
+ return 0;
+}
+
+/***************************************************/
+
+U_BOOT_CMD(
+ pri2c, 1, 1, do_print_i2c_cfg, \
+ "pri2c - Print cfg stored in I2C memory\n", \
+ "\n - Format and Print configuration settings stored in I2C eeprom\n" \
+ );
+
Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/i2c_cfg.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/i2c_cfg.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: u-boot/trunk/u-boot_1.1.3/common/cmd_nvedit.c
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/common/cmd_nvedit.c?view=diff&rev=140&r1=139&r2=140
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/common/cmd_nvedit.c (original)
+++ u-boot/trunk/u-boot_1.1.3/common/cmd_nvedit.c Tue Jan 30 14:37:28 2007
@@ -330,7 +330,8 @@
* Some variables should be updated when the corresponding
* entry in the enviornment is changed
*/
-
+#ifndef CONFIG_S800I
+ /* S800I gets its mac address from a different source */
if (strcmp(argv[1],"ethaddr") == 0) {
char *s = argv[2]; /* always use only one arg */
char *e;
@@ -343,7 +344,8 @@
#endif
return 0;
}
-
+#endif
+
if (strcmp(argv[1],"ipaddr") == 0) {
char *s = argv[2]; /* always use only one arg */
char *e;
Modified: u-boot/trunk/u-boot_1.1.3/include/configs/s800i.h
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/include/configs/s800i.h?view=diff&rev=140&r1=139&r2=140
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/include/configs/s800i.h (original)
+++ u-boot/trunk/u-boot_1.1.3/include/configs/s800i.h Tue Jan 30 14:37:28 2007
@@ -70,6 +70,10 @@
#define CONFIG_SERVERIP 10.16.1.34
#define CONFIG_HOSTNAME BF537
#define CONFIG_ROOTPATH /romfs
+
+/* Allow for MAC to be overwritten in u-boot environment as i2c stores actual value */
+#define CONFIG_ENV_OVERWRITE 1
+
/* Uncomment next line to use fixed MAC address */
/* #define CONFIG_ETHADDR 02:80:ad:20:31:b8 */
/* This is the routine that copies the MAC in Flash to the 'ethaddr' setting */
@@ -270,6 +274,8 @@
#define AMBCTL1VAL 0xFFC27BB0
#define CONFIG_VDSP 1
+
+/* Following definition used to determine if image boots from SPI FLASH or serial port */
#undef BF537_UART_BOOT
#ifdef CONFIG_VDSP
@@ -310,6 +316,7 @@
#define CFG_ATA_STRIDE 1 /* CF.A0 --> Blackfin.A1 */
#endif
+#define CONFIG_S800I 1
/*
* Turn soft resets into hardware reset option with the s800i board
* Uses PortG pin 14.
Modified: u-boot/trunk/u-boot_1.1.3/lib_blackfin/board.c
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/lib_blackfin/board.c?view=diff&rev=140&r1=139&r2=140
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/lib_blackfin/board.c (original)
+++ u-boot/trunk/u-boot_1.1.3/lib_blackfin/board.c Tue Jan 30 14:37:28 2007
@@ -242,7 +242,6 @@
{
puts("I2C: ");
i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE);
- puts("ready\n");
return (0);
}
#endif
@@ -282,6 +281,10 @@
mem_malloc_init();
malloc_bin_reloc();
+#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
+ init_func_i2c();
+#endif
+
#ifdef CONFIG_SPI
# if ! defined(CFG_ENV_IS_IN_EEPROM)
spi_init_f();
@@ -350,9 +353,6 @@
swap_to(FLASH);
#endif
#endif
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
- init_func_i2c();
-#endif
#ifdef DEBUG
display_global_data();
More information about the aadk-commits
mailing list