Reading EEPROM Data in U-Boot SPL
Hai,
I am trying to read the data stored in the EEPROM via I²C during the U-Boot SPL stage.
The EEPROM data can be read successfully from both U-Boot and user space, as shown below.
Uboot Area:
iWave-G62H>
iWave-G62H> i2c dev 0
Setting bus to 0
iWave-G62H> i2c md 0x50 0x0000.2 1
0000: 99 .
iWave-G62H> i2c md 0x50 0x0000.2 1
0000: 99 .
iWave-G62H> i2c mw 0x50 0x0000.2 0x01 1
iWave-G62H>
iWave-G62H> i2c md 0x50 0x0000.2 1
0000: 01 .
iWave-G62H> i2c md 0x50 0x0000.2 1
0000: 01 .
iWave-G62H>
User Space:
root@imx91-iwg62h:~#
root@imx91-iwg62h:~# dd if=/sys/bus/i2c/devices/0-0050/eeprom bs=1 count=1 2>/dev/null | hexdump -C
00000000 01 |.|
00000001
root@imx91-iwg62h:~#
root@imx91-iwg62h:~#
root@imx91-iwg62h:~# printf '\x99' | dd of=/sys/bus/i2c/devices/0-0050/eeprom bs=1 count=1
1+0 records in
1+0 records out
1 byte copied, 0.00047425 s, 2.1 kB/s
root@imx91-iwg62h:~#
root@imx91-iwg62h:~#
root@imx91-iwg62h:~# dd if=/sys/bus/i2c/devices/0-0050/eeprom bs=1 count=1 2>/dev/null | hexdump -C
00000000 99 |.|
00000001
root@imx91-iwg62h:~#
However, the issue is that the SPL implementation is not retrieving the correct EEPROM value. Regardless of how many times I attempt to read the data using the implementation below, it consistently returns 0x00 instead of the expected value.
The SPL logs are provided below for reference.
U-Boot SPL 2025.04-g83e346594a6d-dirty (Oct 16 2026 - 07:26:28 +0000)
SPL: EEPROM value = 0x00
SPL: Read value: 0x00
Could you please review the implementation in the U-Boot SPL code and confirm whether it is correct? Additionally, could you suggest how to retrieve the expected EEPROM value during the SPL stage?
I have also attached the implementation added to the SPL section of the U-Boot source code.
static int read_eeprom_value(u8 *value)
{
struct udevice *chip;
int ret;
ret = i2c_get_chip_for_busnum(0, 0x50, 2, &chip);
if (ret)
{
printf("SPL: Failed to access EEPROM: %d\n", ret);
return ret;
}
/* Read 1 byte from EEPROM offset 0x0000 */
ret = dm_i2c_read(chip, 0x0000, value, 1);
if (ret)
{
printf("SPL: EEPROM read failed: %d\n", ret);
return ret;
}
printf("SPL: EEPROM value = 0x%02X\n", *value);
return 0;
}
void board_init_f(ulong dummy)
{
int ret;
/* Clear the BSS. */
memset(__bss_start, 0, __bss_end - __bss_start);
timer_init();
arch_cpu_init();
board_early_init_f();
spl_early_init();
preloader_console_init();
u8 eeprom_value = 0xFF;
ret = read_eeprom_value(&eeprom_value);
if (ret == 0)
{
printf("SPL: Read value: 0x%02X\n", eeprom_value);
}
else
{
printf("SPL: Failed to read EEPROM value\n");
}
}
Thank you
