From 01654cdbbacfe8ecc51d109722cd82beab004b5c Mon Sep 17 00:00:00 2001 From: Li Hua Qian Date: Mon, 18 Dec 2023 14:01:19 +0800 Subject: [PATCH] iot2050-eio-manager: Add module firmware update Signed-off-by: Li Hua Qian --- .../files/iot2050-eio-cli.py | 36 +++++++++++++++++-- .../files/iot2050_eio_fwu.py | 20 +++++++++++ .../files/iot2050_eio_global.py | 4 +++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/recipes-app/iot2050-eio-manager/files/iot2050-eio-cli.py b/recipes-app/iot2050-eio-manager/files/iot2050-eio-cli.py index 112d9f04d..a9839dcd3 100755 --- a/recipes-app/iot2050-eio-manager/files/iot2050-eio-cli.py +++ b/recipes-app/iot2050-eio-manager/files/iot2050-eio-cli.py @@ -89,6 +89,8 @@ def do_update_firmware(firmware, firmware_type): 3. %(prog)s fwu controller [firmware.bin] Update firmware for Extended IO Controller, using firmware.bin if provided, otherwise using the stock firmware file. + 3. %(prog)s fwu module -s 1 -fwa fwa.bin + Update firmware a of the module in slot 1 Example Configuration File: @@ -120,6 +122,20 @@ def do_update_firmware(firmware, firmware_type): controller_parser.add_argument('firmware', nargs='?', metavar='FIRMWARE', type=argparse.FileType('rb'), help='Firmware file') + module_parser = fwu_subparsers.add_parser("module", help='module help') + module_parser.add_argument('firmware', nargs='?', metavar='FIRMWARE', + type=argparse.FileType('rb'), + help='Firmware file') + module_parser.add_argument('-s', '--slot', + help='Specify the slot number', + nargs=1) + group = module_parser.add_mutually_exclusive_group() + group.add_argument('-fwa', '--firmware-a', + help='Update firmware a of module', + action='store_true') + group.add_argument('-fwb', '--firmware-b', + help='Update firmware b of module', + action='store_true') args = parser.parse_args() @@ -156,13 +172,27 @@ def do_update_firmware(firmware, firmware_type): print(message) sys.exit(0) - response = do_update_firmware(firmware) + response = do_update_firmware(firmware, "map3") + elif args.fwu_command == 'module': + if not args.slot or \ + (not args.firmware_a and not args.firmware_b): + module_parser.print_help(sys.stderr) + sys.exit(1) + if args.firmware_a: + firmware_type = f'slot{args.slot[0]}/fwa' + elif args.firmware_b: + firmware_type = f'slot{args.slot[0]}/fwb' + firmware = args.firmware.read() + response = do_update_firmware(firmware, firmware_type) + if response.status: print(f"ERROR: {response.message}") - print("EIO firmware update failed, please try again!") + print(f"EIO {args.fwu_command} firmware update failed, please try again!") sys.exit(1) - print("EIO firmware update completed. Please reboot the device.") + print(f"EIO {args.fwu_command} firmware update completed." + f" Please reboot the {args.fwu_command}!") else: parser.print_help(sys.stderr) sys.exit(1) + diff --git a/recipes-app/iot2050-eio-manager/files/iot2050_eio_fwu.py b/recipes-app/iot2050-eio-manager/files/iot2050_eio_fwu.py index 70761cdf3..88968b905 100755 --- a/recipes-app/iot2050-eio-manager/files/iot2050_eio_fwu.py +++ b/recipes-app/iot2050-eio-manager/files/iot2050_eio_fwu.py @@ -15,6 +15,7 @@ from iot2050_eio_global import ( EIO_FS_FW_VER, EIO_FWU_META, + EIO_MODULE_PATH, EIO_FWU_MAP3_FW_BIN ) @@ -129,6 +130,19 @@ def __del__(self): self.flash_prog.release() +class ModuleFirmware(): + def __init__(self, firmware, firmware_type): + self.firmware = firmware + self.firmware_target = EIO_MODULE_PATH + firmware_type + + def write(self): + with open(self.firmware_target, "wb") as f: + try: + f.write(self.firmware) + except OSError as e: + raise UpgradeError(f"ModuleFirmware writes failed: {e}") + + class FirmwareUpdate(): """ The FirmwareUpdate models the firmware updating behavior for all @@ -139,6 +153,12 @@ def __init__(self, firmware, firmware_type): self.to_verify = True if "map3" == firmware_type: self.firmwares[firmware_type] = EIOFirmware(firmware) + if "slot" in firmware_type: + self.firmwares[firmware_type] = ModuleFirmware(firmware, firmware_type) + self.to_verify = False + + if not self.firmwares: + raise UpgradeError("No valid firmware!") def update(self): """Update the firmware to the specified flash""" diff --git a/recipes-app/iot2050-eio-manager/files/iot2050_eio_global.py b/recipes-app/iot2050-eio-manager/files/iot2050_eio_global.py index 2c402d8f1..c37bed3ef 100644 --- a/recipes-app/iot2050-eio-manager/files/iot2050_eio_global.py +++ b/recipes-app/iot2050-eio-manager/files/iot2050_eio_global.py @@ -29,6 +29,9 @@ # Extended IO FUSE filesystem path for eio events 'EIO_FS_EVENT': '/eiofs/log/event', + # Extended IO FUSE filesystem path for modules + 'EIO_MODULE_PATH': '/eiofs/controller/', + # EIO Firmware Update: Meta data 'EIO_FWU_META': '/usr/lib/iot2050/eio/firmware-version', @@ -57,6 +60,7 @@ EIO_FS_CONFIG = effective_conf['EIO_FS_CONFIG'] EIO_FS_FW_VER = effective_conf['EIO_FS_FW_VER'] EIO_FS_EVENT = effective_conf['EIO_FS_EVENT'] +EIO_MODULE_PATH = effective_conf['EIO_MODULE_PATH'] EIO_FWU_META = effective_conf['EIO_FWU_META'] EIO_FWU_MAP3_FW_BIN = effective_conf['EIO_FWU_MAP3_FW_BIN'] EIO_SCHEMA_ROOT = effective_conf['EIO_SCHEMA_ROOT']