Skip to contentSkip to conversation

board: ti: common: board_detect: Fix EEPROM offset read for 1-byte

PATCH Superseded Prasanth Babu Mantena 3 participants 3 messages Oct 26, 2023

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 board: ti: common: board_detect: Fix EEPROM offset read for 1-byte

EEPROM detection logic in ti_i2c_eeprom_get() involves reading the total size followed by reading 1-byte size with an offset 1. This commit fixes the header matching issue in commit 9f393a2d7af8 ("board: ti: common:
board_detect: Fix EEPROM read quirk for 2-byte").

In the previous commit, the value with one offset is being read into offset_test, but the pointer used to match was still ep. ep is the pointer where previously read data is stored, resulting in an invalid comparision of the values. The intent is to identify bad 2-byte addressing eerpoms, which respond to the initial 1-byte addressing request and gets stuck on the succesive reads. After successive read with an offset 1, the 1-byte data is compared with the second byte of the header to ensure it as a valid 1byte addressing eeprom.
This is taken care by comparing proper first byte value from, header with an offset 1 byte, to offset_test having the 1-byte data read from eeprom.

Fixes 9f393a2d7af8 (board: ti: common: board_detect: Fix EEPROM read quirk for 2-byte)

---
v2 <--> v1:
Fix inplace for the else condition of CONFIG_IS_ENABLED(DM_I2C). Improved commit message.

 board/ti/common/board_detect.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
board/ti/common/board_detect.c +2 -2
index 9a53884c98..869f7a47f8 100644
@@ -128,7 +128,7 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
 
 	rc = dm_i2c_read(dev, 0x1, &offset_test, sizeof(offset_test));
 
-	if (*((u32 *)ep) != (header & 0xFF))
+	if (offset_test != ((header >> 8) & 0xFF))
 		one_byte_addressing = false;
 
 	/* Corrupted data??? */
@@ -180,7 +180,7 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
 
 	rc = i2c_read(dev_addr, 0x1, byte, &offset_test, sizeof(offset_test));
 
-	if (*((u32 *)ep) != (header & 0xFF))
+	if (offset_test != ((header >> 8) & 0xFF))
 		one_byte_addressing = false;
 
 	/* Corrupted data??? */
Signature · 1 line
2.39.0
Tested-by on v2 1/1
#1 lore raw

чт, 26 окт. 2023 г. в 15:24, Prasanth Babu Mantena <[email protected]>:

Quoted 17 lines

EEPROM detection logic in ti_i2c_eeprom_get() involves reading the total size followed by reading 1-byte size with an offset 1. This commit fixes the header matching issue in commit 9f393a2d7af8 ("board: ti: common:
board_detect: Fix EEPROM read quirk for 2-byte").

In the previous commit, the value with one offset is being read into offset_test, but the pointer used to match was still ep. ep is the pointer where previously read data is stored, resulting in an invalid comparision of the values. The intent is to identify bad 2-byte addressing eerpoms, which respond to the initial 1-byte addressing request and gets stuck on the succesive reads. After successive read with an offset 1, the 1-byte data is compared with the second byte of the header to ensure it as a valid 1byte addressing eeprom.
This is taken care by comparing proper first byte value from, header with an offset 1 byte, to offset_test having the 1-byte data read from eeprom.

Quoted 2 lines
Fixes 9f393a2d7af8 (board: ti: common: board_detect: Fix EEPROM read quirk for 2-byte)

At least I see no regressions here.

Quoted 33 lines

---
v2 <--> v1:
Fix inplace for the else condition of CONFIG_IS_ENABLED(DM_I2C). Improved commit message.

 board/ti/common/board_detect.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
board/ti/common/board_detect.c +2 -3
index 9a53884c98..869f7a47f8 100644
@@ -128,7 +128,7 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
 
        rc = dm_i2c_read(dev, 0x1, &offset_test, sizeof(offset_test));
 
-       if (*((u32 *)ep) != (header & 0xFF))
+       if (offset_test != ((header >> 8) & 0xFF))
                one_byte_addressing = false;
 
        /* Corrupted data??? */
@@ -180,7 +180,7 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
 
        rc = i2c_read(dev_addr, 0x1, byte, &offset_test, sizeof(offset_test));
 
-       if (*((u32 *)ep) != (header & 0xFF))
+       if (offset_test != ((header >> 8) & 0xFF))
                one_byte_addressing = false;
 
        /* Corrupted data??? */
--

2.39.0

Signature · 2 lines
With best regards,
Matwey V. Kornilov
#2 lore raw
In reply to Prasanth Babu Mantena
Quoted 5 lines · Prasanth Babu Mantena

EEPROM detection logic in ti_i2c_eeprom_get() involves reading the total size followed by reading 1-byte size with an offset 1. This commit fixes the header matching issue in commit 9f393a2d7af8 ("board: ti: common:
board_detect: Fix EEPROM read quirk for 2-byte").

Quoted 10 lines

In the previous commit, the value with one offset is being read into offset_test, but the pointer used to match was still ep. ep is the pointer where previously read data is stored, resulting in an invalid comparision of the values. The intent is to identify bad 2-byte addressing eerpoms, which respond to the initial 1-byte addressing request and gets stuck on the succesive reads. After successive read with an offset 1, the 1-byte data is compared with the second byte of the header to ensure it as a valid 1byte addressing eeprom.
This is taken care by comparing proper first byte value from, header with an offset 1 byte, to offset_test having the 1-byte data read from eeprom.

Rephrase (I at times go to grammarly.com to make sure I use the right verbage): So, keep it simple (we can read code - no need to give us the detail readup). Stuff like "in the previous commit" leaves us wondering which commit.

EEPROM detection logic in ti_i2c_eeprom_get() involves reading the total size followed by reading 1-byte size with an offset 1.
The commit 9f393a2d7af8 ("board: ti: common: board_detect: Fix EEPROM read quirk for 2-byte") that attempts to fix this uses the wrong pointer to to compare.

Quoted 36 lines
Fixes 9f393a2d7af8 (board: ti: common: board_detect: Fix EEPROM read quirk for 2-byte)

---
v2 <--> v1:
Fix inplace for the else condition of CONFIG_IS_ENABLED(DM_I2C). Improved commit message.

 board/ti/common/board_detect.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
board/ti/common/board_detect.c +2 -2
index 9a53884c98..869f7a47f8 100644
@@ -128,7 +128,7 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
 
 	rc = dm_i2c_read(dev, 0x1, &offset_test, sizeof(offset_test));
 
-	if (*((u32 *)ep) != (header & 0xFF))
+	if (offset_test != ((header >> 8) & 0xFF))
 		one_byte_addressing = false;
 
 	/* Corrupted data??? */
@@ -180,7 +180,7 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
 
 	rc = i2c_read(dev_addr, 0x1, byte, &offset_test, sizeof(offset_test));
 
-	if (*((u32 *)ep) != (header & 0xFF))
+	if (offset_test != ((header >> 8) & 0xFF))
 		one_byte_addressing = false;
 
 	/* Corrupted data??? */
Signature · 1 line
2.39.0
Signature · 3 lines
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D