diff options
-rw-r--r-- | test-cli/test/flashers/flasheeprom.py | 53 | ||||
-rw-r--r-- | test-cli/test/flashers/flashmemory.py | 2 | ||||
-rw-r--r-- | test-cli/test_main.py | 4 |
3 files changed, 39 insertions, 20 deletions
diff --git a/test-cli/test/flashers/flasheeprom.py b/test-cli/test/flashers/flasheeprom.py index e427b87..bdeb7e6 100644 --- a/test-cli/test/flashers/flasheeprom.py +++ b/test-cli/test/flashers/flasheeprom.py @@ -2,24 +2,41 @@ import os import binascii +def _generate_data_bytes(boarduuid, mac0, mac1): + 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 + return data + + +def _generate_output_data(data_rx): + boarduuid = data_rx[8:45].decode + mac0 = binascii.hexlify(data_rx[45:53]).decode() + mac1 = binascii.hexlify(data_rx[53:61]).decode() + smac0 = '-'.join(mac0[i:i + 2] for i in range(0, len(mac0), 2)) + smac1 = '-'.join(mac1[i:i + 2] for i in range(0, len(mac1), 2)) + eepromdata = "UUID :" + boarduuid + " MAC0:" + smac0 + " MAC1:" + smac1 + + return eepromdata + + +# returns exitcode and data saved into eeprom 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 + data = _generate_data_bytes(boarduuid, mac0, mac1) # write into eeprom and read back f = open(eeprompath, "r+b") f.write(data) @@ -28,9 +45,11 @@ def flash_eeprom(eeprompath, boarduuid, mac0, mac1=None): for i in range(57): if data_rx[i] != data[i]: print("Error while programming eeprom memory.") - return 1 + return 1, None print("Eeprom programmed succesfully.") - return 0 + # generated eeprom read data + eepromdata = _generate_output_data(data_rx) + return 0, eepromdata else: - print("eeprom memory not found.") - return 1 + print("Eeprom memory not found.") + return 1, None diff --git a/test-cli/test/flashers/flashmemory.py b/test-cli/test/flashers/flashmemory.py index ac59be5..c7267c6 100644 --- a/test-cli/test/flashers/flashmemory.py +++ b/test-cli/test/flashers/flashmemory.py @@ -2,7 +2,7 @@ import sh def flash_memory(imagefile): - print("Sart programming Nand memory...") + print("Start programming Nand memory...") p = sh.bash("/usr/bin/igep-flash", "--skip-nandtest", "--image", "/opt/firmware/" + imagefile) if p.exit_code != 0: print("Flasher: Could not complete flashing task.") diff --git a/test-cli/test_main.py b/test-cli/test_main.py index 37207cc..ddd62aa 100644 --- a/test-cli/test_main.py +++ b/test-cli/test_main.py @@ -142,9 +142,9 @@ def main(): resulteeprom = 0 if "eeprompath" in varlist and len(varlist["eeprompath"]) > 0: mac0 = psdbObj.get_board_macaddr(globalVar.g_uuid) - resulteeprom = flash_eeprom(varlist["eeprompath"], globalVar.g_uuid, mac0) + resulteeprom, eepromdata = flash_eeprom(varlist["eeprompath"], globalVar.g_uuid, mac0) psdbObj.create_task_result(globalVar.taskid_ctl, "FLASHEEPROM", - "TASK_OK" if resulteeprom == 0 else "TASK_FAIL", varlist["eeprompath"]) + "TASK_OK" if resulteeprom == 0 else "TASK_FAIL", eepromdata) # flash non-volatile memory resultmemory = 0 |