Skip to content

Commit

Permalink
board: ti: common: board_detect: Do 1byte address checks first.
Browse files Browse the repository at this point in the history
Do 1 byte address checks first prior to doing 2 byte address checks.
When performing 2 byte addressing on 1 byte addressing eeprom, the
second byte is taken in as a write operation and ends up erasing the
eeprom region we want to preserve.

While we could have theoretically handled this by ensuring the write
protect of the eeproms are properly managed, this is not true in case
where board are updated with 1 byte eeproms to handle supply status.

Flipping the checks by checking for 1 byte addressing prior to 2 byte
addressing check prevents this problem at the minor cost of additional
overhead for boards with 2 byte addressing eeproms.

Signed-off-by: Nishanth Menon <nm@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
  • Loading branch information
nmenon authored and trini committed Jul 6, 2022
1 parent bc1de48 commit a58147c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions board/ti/common/board_detect.c
Expand Up @@ -103,14 +103,14 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
/*
* Read the header first then only read the other contents.
*/
rc = i2c_set_chip_offset_len(dev, 2);
rc = i2c_set_chip_offset_len(dev, 1);
if (rc)
return rc;

/*
* Skip checking result here since this could be a valid i2c read fail
* on some boards that use 1 byte addressing.
* We must allow for fall through to check the data if 1 byte
* on some boards that use 2 byte addressing.
* We must allow for fall through to check the data if 2 byte
* addressing works
*/
(void)dm_i2c_read(dev, 0, (uint8_t *)&hdr_read, 4);
Expand All @@ -119,9 +119,9 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
if (hdr_read != header) {
/*
* read the eeprom header using i2c again, but use only a
* 1 byte address (some legacy boards need this..)
* 2 byte address (some newer boards need this..)
*/
rc = i2c_set_chip_offset_len(dev, 1);
rc = i2c_set_chip_offset_len(dev, 2);
if (rc)
return rc;

Expand All @@ -146,12 +146,12 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
/*
* Read the header first then only read the other contents.
*/
byte = 2;
byte = 1;

/*
* Skip checking result here since this could be a valid i2c read fail
* on some boards that use 1 byte addressing.
* We must allow for fall through to check the data if 1 byte
* on some boards that use 2 byte addressing.
* We must allow for fall through to check the data if 2 byte
* addressing works
*/
(void)i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read, 4);
Expand All @@ -160,9 +160,9 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
if (hdr_read != header) {
/*
* read the eeprom header using i2c again, but use only a
* 1 byte address (some legacy boards need this..)
* 2 byte address (some newer boards need this..)
*/
byte = 1;
byte = 2;
rc = i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read,
4);
if (rc)
Expand Down

0 comments on commit a58147c

Please sign in to comment.