[aadk-commits] dbailey: u-boot/trunk r206 - /u-boot/trunk/u-boot_1.1.3/board/s800i/

aadk-commits at lists.digium.com aadk-commits at lists.digium.com
Tue Mar 6 09:29:47 MST 2007


Author: dbailey
Date: Tue Mar  6 10:29:47 2007
New Revision: 206

URL: http://svn.digium.com/view/aadk?view=rev&rev=206
Log:
Guarantee return value in rx function in ether_bf537.c
Get rid of unnecessary function that was throwing warnings in i2c.c 
implement function that pulls board config data from the i2C eeprom and places the data as arguments in the linux command line

Modified:
    u-boot/trunk/u-boot_1.1.3/board/s800i/dig_i2c_eeprom.h
    u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c
    u-boot/trunk/u-boot_1.1.3/board/s800i/i2c.c
    u-boot/trunk/u-boot_1.1.3/board/s800i/i2c_cfg.c
    u-boot/trunk/u-boot_1.1.3/board/s800i/s800i.c

Modified: 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=diff&rev=206&r1=205&r2=206
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/dig_i2c_eeprom.h (original)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/dig_i2c_eeprom.h Tue Mar  6 10:29:47 2007
@@ -35,6 +35,7 @@
 extern const struct rom_location eeprom_map[];
 
 /*** Prototype ***/
-int get_i2c_mac(unsigned char * mac); //DBDEBUG temporary
-
+int get_i2c_mac(unsigned char * mac); 
+void set_bootcmd_args(void);
+		
 #endif

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=206&r1=205&r2=206
==============================================================================
--- 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 Mar  6 10:29:47 2007
@@ -141,7 +141,7 @@
 
 int eth_rx(void)
 {	
-	int length;
+	int length = -1;
 	
 	for(;;){
 	if((rxbuf[rxIdx]->StatusWord & RX_COMP) == 0){

Modified: u-boot/trunk/u-boot_1.1.3/board/s800i/i2c.c
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/i2c.c?view=diff&rev=206&r1=205&r2=206
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/i2c.c (original)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/i2c.c Tue Mar  6 10:29:47 2007
@@ -375,42 +375,6 @@
 	return 0;
 }
 
-#define PAGE_SIZE (8)
-int i2c_writeDB(uchar chip, uint addr, int alen, uchar *buffer, int len)
-{
-	struct i2c_msg msg;
-	u8 addr_bytes[3]; /* lowest...highest byte of data address */
-	u8 msg_buf[PAGE_SIZE+3];
-	int i = 0;
-	int j = 0;
-	
-	PRINTD("i2c_writeDB: chip=0x%x, addr=0x%x, alen=0x%x, len=0x%x, buf0=0x%x\n", chip, addr, alen, len, buffer[0]);
-
-	/* chip address write */
-	if(alen>0) {
-		msg_buf[i++] = (u8)((addr >>  0) & 0x000000FF);
-	}
-	if(alen>1) {
-		msg_buf[i++] = (u8)((addr >>  8) & 0x000000FF);
-	}
-	if(alen>2) {
-		msg_buf[i++] = (u8)((addr >> 16) & 0x000000FF);
-	}
-	
-	for(j = 0; j < len && j < PAGE_SIZE; j++){
-		msg_buf[i++] = buffer[j];
-	}
-	msg.addr = chip;
-	msg.flags = 0;
-	msg.len = i;
-	msg.buf = msg_buf;
-
-	if (i2c_transfer(&msg)) return -1;
-
-	return 0;
-
-}
-
 /**
  *   i2c_write: -  Write multiple bytes to an i2c device
  *

Modified: 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=diff&rev=206&r1=205&r2=206
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/i2c_cfg.c (original)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/i2c_cfg.c Tue Mar  6 10:29:47 2007
@@ -24,6 +24,10 @@
 
 #include "dig_i2c_eeprom.h"
 
+#define  BOARDREV_ARG	"boardrev"
+#define  PRODSKU_ARG	"productsku"
+#define  CAPABILITY_ARG	"capability"
+		
 /* Map of where data is stored in the i2c eeprom */
 const struct rom_location eeprom_map[] = {
 	{ .state = DIGCMD_BOARD_REVISION, 	.offset = 0, .size = 16},
@@ -36,16 +40,36 @@
 	{ .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)
-{
+/*
+ *	Helper function that copies a configuration field to specified buffer.
+ *	Assumes that enough space is available in the buffer
+ */
+static int copy_i2c_field(enum cmd_state item, unsigned char * target, unsigned char * source)
+{
+	int length = 0;
 	int i, j;
-	unsigned char   prom_image[I2C_PROM_SIZE +1];
+	
+	for(i = 0; DIGCMD_NULL != eeprom_map[i].state; i++) {
+		/* Set the MAC address to what was stored here */
+		if(item == eeprom_map[i].state) {
+			for(j = 0; j < eeprom_map[i].size; j++){
+				target[j] = source[eeprom_map[i].offset +j];
+			}
+			length = j;
+			break;
+		}	
+	}
+	return length;
+}
+
+/*
+ *	Helper function that extracts the full contents of the I2C eeprom and puts it into memory
+ *	The data's CRC is validated as part of the function.
+ */
+static int get_i2c_eeprom_data(unsigned char * prom_image)
+{
+	uchar chip = I2C_PROM_ADDRESS;
 	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)) {
@@ -58,19 +82,85 @@
 		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;
+}
+
+/*
+ * 	Retrieve the MAC address stored in i2c EEPROM memory
+ */
+int get_i2c_mac(unsigned char * mac)
+{
+	unsigned char   prom_image[I2C_PROM_SIZE +1];
+	
+	/* Get the contents of the existing eeprom */
+	if (0 != get_i2c_eeprom_data(prom_image)) {
+		return -1;
+	}
+	
+	copy_i2c_field(DIGCMD_MAC_ADDRESS, mac, prom_image);
 	return 0; 
 }
 
+/* 
+ * 	Modify Boot Arguments
+ *	If the following arguments are not set in the bootargs environment parameter, 
+ * 	then get set them from the contents of the I2C configuration eeprom
+ *
+ *	boardrev
+ *	productsku
+ *	capability
+ */
+void set_bootcmd_args(void)
+{
+	unsigned char   prom_image[I2C_PROM_SIZE +1];
+	int bad_rom = 1;
+	int len;
+	char * tmp;
+	char set_parm[128];
+	char parm_val[128];
+	char new_bootargs[256];
+	
+	tmp = getenv("bootargs");
+	strcpy(new_bootargs, tmp);
+	
+	if (0 == get_i2c_eeprom_data(prom_image)) {
+		bad_rom = 0;
+	}
+
+	/* If the Board Rev is not set, then set the board rev from the contents 
+	*	If data cannot be read from the i2c, assume that this is a REV A board 
+	*		(Rev A's do not have this device resident.) 
+	*/
+	if(NULL == strstr(new_bootargs, BOARDREV_ARG)) {
+		if(0 == bad_rom && 0 < (len = copy_i2c_field(DIGCMD_BOARD_REVISION, parm_val, prom_image))) {
+			parm_val[len] = '\0';
+			sprintf(set_parm, " %s=%s", BOARDREV_ARG, parm_val);
+		} else {
+			sprintf(set_parm, " %s=A", BOARDREV_ARG);
+		}
+		strcat(new_bootargs, set_parm);
+	}
+	/* If the SKU is not set, then set the SKU from the contents */
+	if(NULL == strstr(new_bootargs, PRODSKU_ARG)){
+		parm_val[0] = '\0';
+		if(0 == bad_rom) {
+			copy_i2c_field(DIGCMD_PRODUCT_SKU, parm_val, prom_image);
+		}
+		sprintf(set_parm, " %s=%s", PRODSKU_ARG, parm_val);
+		strcat(new_bootargs, set_parm);
+	}
+	/* If the Capability not set, then set the Capaiblity from the contents */
+	if(NULL == strstr(new_bootargs, CAPABILITY_ARG)){
+		parm_val[0] = '\0';
+		if(0 == bad_rom) {
+			copy_i2c_field(DIGCMD_CAPABILITY_CODE, parm_val, prom_image);
+		}
+		sprintf(set_parm, " %s=%s", CAPABILITY_ARG, parm_val);
+		strcat(new_bootargs, set_parm);
+	}
+	setenv("bootargs", new_bootargs);
+	return;
+}
 
 /*
  *	Command to display the settings stored in the I2C PROM 
@@ -79,27 +169,15 @@
 {
 	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");
+	if (0 != get_i2c_eeprom_data(prom_image)) {
 		return -1;
 	}
 	
 	printf("************* I2C Configuration Data ************\n");
-	curr_field = &eeprom_map[0];
+	curr_field = (struct rom_location *)(&eeprom_map[0]);
 	
 	while(curr_field->state != DIGCMD_NULL){
 		switch(curr_field->state){
@@ -141,7 +219,7 @@
 			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);
+				printf("Capability=%s\n", disp_buffer);
 				break;
 			case DIGCMD_CRC:
 				break;

Modified: u-boot/trunk/u-boot_1.1.3/board/s800i/s800i.c
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/s800i.c?view=diff&rev=206&r1=205&r2=206
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/s800i.c (original)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/s800i.c Tue Mar  6 10:29:47 2007
@@ -31,6 +31,7 @@
 #include <asm/blackfin.h>
 #include "adm.h"
 #include "ether_bf537.h"
+#include "dig_i2c_eeprom.h"
 
 #define POST_WORD_ADDR 0xFF903FFC
 
@@ -174,6 +175,9 @@
 #endif
 	adm_init();	
 	SetupMacAddr(nid);
+
+	set_bootcmd_args();		/* Modify arguments that are passed to OS */
+
 	return 0;
 }
 #endif



More information about the aadk-commits mailing list