diff options
| author | Kevin Wallace <kevin@pentabarf.net> | 2025-12-28 02:30:34 -0800 |
|---|---|---|
| committer | Kevin Wallace <kevin@pentabarf.net> | 2025-12-28 03:15:13 -0800 |
| commit | c9ad9097ccfd558baa4e9a52069abf512b37e8d5 (patch) | |
| tree | b725d2c2e1206093e52ec4007b874be0558be7ae | |
| parent | silkscreen, gnd via (diff) | |
i2c eeprom flash script
| -rw-r--r-- | flash.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/flash.py b/flash.py new file mode 100644 index 0000000..6a29159 --- /dev/null +++ b/flash.py @@ -0,0 +1,50 @@ +# usage: +# glasgow script flash.py i2c-controller -V 3.3 +import struct +import sys +import time + +addr = 0x50 +size = 0x2000 + +ini = b""" +[FzgParam] +Fahrzeugadresse=11111111 +MontageplattenNr=22222222 +[TestMode] +0=if [ -e /init/efad/mp_sd/autorun.sh ]; then systemctl stop init-abtproxy; sh /init/efad/mp_sd/autorun.sh; else systemctl --no-block start nx; fi +""".lstrip() +write_data = ini.strip().replace(b'\n', b'\r\n').ljust(size, b'\xff') + +await i2c_iface.write(addr, struct.pack('>h', 0)) +print("reading eeprom data") +read_data = await i2c_iface.read(addr, len(write_data)) +if read_data == write_data: + print("already written, skipping") + sys.exit(0) +else: + print(f"overwriting eeprom data: {read_data.hex()}") + +chunk_size = 32 +for i in range(0, size, chunk_size): + read_chunk = read_data[i:i+chunk_size] + write_chunk = write_data[i:i+chunk_size] + if read_chunk == write_chunk: + continue + print(f"writing chunk {struct.pack('>h', i).hex()}") + await i2c_iface.write(addr, struct.pack('>h', i) + write_chunk) + time.sleep(0.01) + print("wrote, reading back") + await i2c_iface.write(addr, struct.pack('>h', i)) + read_chunk = await i2c_iface.read(addr, chunk_size) + if read_chunk == write_chunk: + print(f"wrote {i+chunk_size}") +print("write complete") +await i2c_iface.write(addr, struct.pack('>h', 0)) +read_data = await i2c_iface.read(addr, len(write_data)) +if read_data == write_data: + print("read back successful") +else: + print("read back unsuccessful") + print(f"expected: {write_data.hex()}") + print(f" got: {read_data.hex()}") |