forked from quartiq/kasli-i2c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash_ee.py
48 lines (41 loc) · 1.46 KB
/
flash_ee.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import logging
import sys
from sinara import Sinara
from kasli import Kasli
from chips import EEPROM
logger = logging.getLogger(__name__)
if __name__ == "__main__":
logging.basicConfig(level=logging.WARNING)
serial = int(sys.argv[1])
logger.info("serial: %s", serial)
ee_data = Sinara(
name="Kasli",
board=Sinara.boards.index("Kasli"),
data_rev=0, major=1, minor=1, variant=0, port=0,
vendor=Sinara.vendors.index("Technosystem"),
vendor_data=serial.to_bytes(8, "big"))
ft_serial = "Kasli-v1.1-{}".format(serial)
url = "ftdi://ftdi:4232h:{}/2".format(ft_serial)
with Kasli().configure(url) as bus:
#bus.reset()
# slot = 3
# bus.enable(bus.EEM[slot])
try:
bus.enable("LOC0")
ee = EEPROM(bus)
try:
logger.info("valid data %s", Sinara.unpack(ee.dump()))
except:
logger.info("invalid data") # , exc_info=True)
eui48 = ee.eui48()
print(ee.fmt_eui48())
data = ee_data._replace(eui48=eui48)
ee.write(0, data.pack()[:128])
open("data/{}.bin".format(ee.fmt_eui48(eui48)), "wb").write(data.pack())
data = ee.dump()
try:
logger.info("data readback valid %s", Sinara.unpack(data))
except:
logger.error("data readback invalid %r", data, exc_info=True)
finally:
bus.enable()