hw/nvram: at24 return 0xff if 1 byte address
authorPatrick Venture <venture@google.com>
Mon, 20 Dec 2021 21:21:37 +0000 (13:21 -0800)
committerPhilippe Mathieu-Daudé <f4bug@amsat.org>
Mon, 14 Mar 2022 13:48:35 +0000 (14:48 +0100)
The at24 eeproms are 2 byte devices that return 0xff when they are read
from with a partial (1-byte) address written.  This distinction was
found comparing model behavior to real hardware testing.

Tested: `i2ctransfer -f -y 45 w1@85 0 r1` returns 0xff instead of next
byte

Signed-off-by: Patrick Venture <venture@google.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20211220212137.1244511-1-venture@google.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
hw/nvram/eeprom_at24c.c

index da435500baca7e92690504a8b57315934a224660..01a3093600fa0ca43ab9bf9c748518230707a2ed 100644 (file)
@@ -58,9 +58,10 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
 
     switch (event) {
     case I2C_START_SEND:
-    case I2C_START_RECV:
     case I2C_FINISH:
         ee->haveaddr = 0;
+        /* fallthrough */
+    case I2C_START_RECV:
         DPRINTK("clear\n");
         if (ee->blk && ee->changed) {
             int len = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0);
@@ -84,6 +85,10 @@ uint8_t at24c_eeprom_recv(I2CSlave *s)
     EEPROMState *ee = AT24C_EE(s);
     uint8_t ret;
 
+    if (ee->haveaddr == 1) {
+        return 0xff;
+    }
+
     ret = ee->mem[ee->cur];
 
     ee->cur = (ee->cur + 1u) % ee->rsize;