summaryrefslogtreecommitdiff
path: root/test-cli/test/flashers/flasheeprom.py
diff options
context:
space:
mode:
Diffstat (limited to 'test-cli/test/flashers/flasheeprom.py')
-rw-r--r--test-cli/test/flashers/flasheeprom.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/test-cli/test/flashers/flasheeprom.py b/test-cli/test/flashers/flasheeprom.py
new file mode 100644
index 0000000..e427b87
--- /dev/null
+++ b/test-cli/test/flashers/flasheeprom.py
@@ -0,0 +1,36 @@
+import os
+import binascii
+
+
+def flash_eeprom(eeprompath, boarduuid, mac0, mac1=None):
+ print("Start programming Eeprom...")
+ # check if eeprompath is correct
+ if os.path.isfile(eeprompath):
+ # create u-boot data struct
+ data = bytearray()
+ data += (2029785358).to_bytes(4, 'big') # magicid --> 0x78FC110E
+ data += bytearray([0, 0, 0, 0]) # crc32 = 0
+ data += bytearray(boarduuid + "\0",
+ 'ascii') # uuid --> 'c0846c8a-5fa5-11ea-8576-f8b156ac62d7' and \0 at the end
+ data += binascii.unhexlify(mac0.replace(':', '')) # mac0 --> 'f8:b1:56:ac:62:d7'
+ if mac1 is not None:
+ data += binascii.unhexlify(mac1.replace(':', '')) # mac1 --> 'f8:b1:56:ac:62:d7'
+ else:
+ data += bytearray([0, 0, 0, 0, 0, 0]) # mac1 --> 0:0:0:0:0:0
+ # calculate crc
+ crc = (binascii.crc32(data, 0)).to_bytes(4, 'big')
+ data[4:8] = crc
+ # write into eeprom and read back
+ f = open(eeprompath, "r+b")
+ f.write(data)
+ f.seek(0)
+ data_rx = f.read(57)
+ for i in range(57):
+ if data_rx[i] != data[i]:
+ print("Error while programming eeprom memory.")
+ return 1
+ print("Eeprom programmed succesfully.")
+ return 0
+ else:
+ print("eeprom memory not found.")
+ return 1