Skip to content

Commit

Permalink
iot2050-eio-manager: Add module firmware update
Browse files Browse the repository at this point in the history
Signed-off-by: Li Hua Qian <huaqian.li@siemens.com>
  • Loading branch information
huaqianli committed Dec 18, 2023
1 parent c762743 commit 01654cd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
36 changes: 33 additions & 3 deletions recipes-app/iot2050-eio-manager/files/iot2050-eio-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)

20 changes: 20 additions & 0 deletions recipes-app/iot2050-eio-manager/files/iot2050_eio_fwu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from iot2050_eio_global import (
EIO_FS_FW_VER,
EIO_FWU_META,
EIO_MODULE_PATH,
EIO_FWU_MAP3_FW_BIN
)

Expand Down Expand Up @@ -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
Expand 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"""
Expand Down
4 changes: 4 additions & 0 deletions recipes-app/iot2050-eio-manager/files/iot2050_eio_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit 01654cd

Please sign in to comment.