Skip to content

Commit

Permalink
iot2050-module-firmware-update: Add module firmware update
Browse files Browse the repository at this point in the history
The firmware update for the module should not be included with the
image. This is because the image becomes too large and cumbersome to
release when only the update tool needs to be released. Instead, the
module firmware update should be packaged separately in its own
Debian package for a more efficient and manageable release process.

Signed-off-by: Li Hua Qian <[email protected]>
  • Loading branch information
huaqianli committed Mar 25, 2024
1 parent 9c9b900 commit 650ceda
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3
#
# Copyright (c) Siemens AG, 2024
#
# Authors:
# Li Hua Qian <[email protected]>
#
# SPDX-License-Identifier: MIT

import os
import sys
import argparse
import textwrap

def main(args):
description=textwrap.dedent('''\
Script for updating module firmware on IoT2050
Examples usage:
1. iot2050-module-firmware-update -s 1 -fwa firmwareA.bin
2. iot2050-module-firmware-update -s 1 -fwa firmwareA.bin -fwb firmwareB.bin
''')
parser = argparse.ArgumentParser(
description=description,
formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument(
"-s", "--slot",
type=int,
help="Slot number"
)
parser.add_argument(
"-fwa", "--firmware-a",
help="Path to firmware A file",
type=argparse.FileType('rb')
)
parser.add_argument(
"-fwb", "--firmware-b",
help="Path to firmware B file",
type=argparse.FileType('rb')
)
args = parser.parse_args(args)

if not any(vars(args).values()):
parser.print_help()
return 0

if not args.firmware_a and not args.firmware_b:
print("Error: No firmware file specified")
parser.print_help()
return 1
if not args.slot:
print("Error: No slot number specified")
parser.print_help()
return 1
else:
slot = args.slot
if not os.path.exists(f"/eiofs/controller/slot{slot}"):
print(f"Error: Invalid slot number {slot}")
return 1
else:
slot_path = f"/eiofs/controller/slot{slot}"

if args.firmware_a:
print("Updating firmware A ...")
with open(slot_path + "/fwa", "wb") as f:
ret = f.write(args.firmware_a.read())
if ret < 0:
print("Error: Failed to write firmware A")
return 1
if args.firmware_b:
print("Updating firmware B ...")
with open(slot_path + "/fwb", "wb") as f:
ret = f.write(args.firmware_b.read())
if ret < 0:
print("Error: Failed to write firmware B")
return 1

print("Firmware updated successfully")

return 0

if __name__ == '__main__':
CODE = main(sys.argv[1:])
sys.exit(CODE)

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) Siemens AG, 2024
#
# Authors:
# Li Hua Qian <[email protected]>
#
# This file is subject to the terms and conditions of the MIT License. See
# COPYING.MIT file in the top-level directory.
#

DESCRIPTION = "Customized Module(Special DI) Firmware Update Scripts"
MAINTAINER = "[email protected]"

SRC_URI = " \
file://iot2050-module-firmware-update.tmpl"

TEMPLATE_FILES = "iot2050-module-firmware-update.tmpl"

inherit dpkg-raw

do_install() {
install -v -d ${D}/usr/sbin/
install -v -m 755 ${WORKDIR}/iot2050-module-firmware-update ${D}/usr/sbin/
}

do_deploy_deb[dirs] = "${DEPLOY_DIR_IMAGE}"
1 change: 1 addition & 0 deletions recipes-core/images/iot2050-image-example.bb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ IMAGE_INSTALL += " \
customizations-example \
switchserialmode \
iot2050-firmware-update \
iot2050-module-firmware-update \
tcf-agent \
mraa \
${@ 'board-conf-tools' if d.getVar('QEMU_IMAGE') != '1' else '' } \
Expand Down

0 comments on commit 650ceda

Please sign in to comment.