From a58147c2dbbfbc436ba84463678e943146bcae7d Mon Sep 17 00:00:00 2001 From: Nishanth Menon Date: Fri, 17 Jun 2022 13:26:12 -0500 Subject: [PATCH] board: ti: common: board_detect: Do 1byte address checks first. 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 Reviewed-by: Tom Rini --- board/ti/common/board_detect.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c index 0806dea..ed34991 100644 --- a/board/ti/common/board_detect.c +++ b/board/ti/common/board_detect.c @@ -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); @@ -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; @@ -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); @@ -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) -- 2.7.4