Other Parts Discussed in Thread: AM3352
I have a custom AM3352 based board. We use the config. EEPROM same as the BB and ref. design. I'm having problems trying to program the device. I've added a new command to U-BOOT, a "set_board_info" command where the user can specify the board revision and serial # and it then tries to write this to the EEPROM. When I go to read back the contents at next reboot they're mostly 0xFFs, except for the serial number. I'd like to work out why my EEPROM writes are not working. I do have code in there to toggle the WP pin low to enable writing. The code for my new U-Boot command is below:
int do_set_board_info(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
struct am335x_baseboard_id header;
int v;
int i;
unsigned char* pheader;
if (argc != 3) {
return CMD_RET_USAGE;
}
printf("setting board info to SUNDAC %s %s\n", argv[1], argv[2]);
memset(&header, 0xff, sizeof header);
header.magic = EEPROM_MAGIC_HEADER;
strcpy(header.name, "SUNDAC");
strncpy(header.version, argv[1], 4);
strncpy(header.serial, argv[2], 12);
if ((v = gpio_direction_output(GPIO_EEPROM_WP, 0)) != 0) {
printf("gpio_direction_output for eeprom_wp failed with code %d\n", v);
}
pheader = (unsigned char*)&header;
printf("header to write : ");
for (i = 0;i < sizeof header;i++) {
printf("%02x ", *(pheader + i));
}
printf("\n");
if ((v = eeprom_write(CONFIG_SYS_I2C_EEPROM_ADDR, 0, (unsigned char*)&header, sizeof header)) != 0) {
printf("eeprom_write failed with code %d\n", v);
}
if ((v = gpio_direction_output(GPIO_EEPROM_WP, 1)) != 0) {
printf("gpio_direction_output for eeprom_wp failed with code %d\n", v);
}
return 0;
}
When I reset the board I read back this:
magic ffffffff
name ÿÿÿÿÿÿÿÿ
version ÿÿÿÿ
serial 000000000003 (only this field is valid)
config ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
MAC 0 ff ff ff ff ff ff
MAC 1 ff ff ff ff ff ff
MAC 2 ff ff ff ff ff ff
How do I get eeprom_write to work correctly?
Additionally I think some type of wrapping is occuring. For the next test I wrote vaues 0..sizeof header bytes (turned out to be 0..5f, incrementing one at a time). The result was this:
magic 43424140
name DEFGHIJK
version LMNO
serial
onfig 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b
MAC 0 3c 3d 3e 3f ff ff
MAC 1 ff ff ff ff ff ff
MAC 2 ff ff ff ff ff ff
so it looks like the data was written then wrapped at 0x40 back to the start of the header struct.