Skip to content

Commit

Permalink
Adds changes for the script
Browse files Browse the repository at this point in the history
  • Loading branch information
shgutte committed Feb 24, 2025
1 parent 61e095a commit 80b36ac
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions scripts/tools/silabs/ota/ota_multi_image_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class TAG:
APPLICATION = 1
BOOTLOADER = 2
FACTORY_DATA = 3
WIFI_TA_M4 = 4


def set_logger():
Expand Down Expand Up @@ -201,6 +202,32 @@ def validate_json(data: str):
sys.exit(1)


def generate_wifi_image(args: object):
"""
Generate app payload with descriptor. If a certain option is not specified, use the default values.
"""
logging.info("App descriptor information:")

descriptor = generate_descriptor(args.app_version, args.app_version_str, args.app_build_date)
logging.info(f"App encryption enable: {args.enc_enable}")
if args.enc_enable:
inputFile = open(args.wifi_input_file, "rb")
enc_file = crypto_utils.encryptData(inputFile.read(), args.input_ota_key, INITIALIZATION_VECTOR)
enc_file1 = bytes([ord(x) for x in enc_file])
file_size = len(enc_file1)
payload = generate_header(TAG.WIFI_TA_M4, len(descriptor) + file_size) + descriptor + enc_file1
else:
file_size = os.path.getsize(args.wifi_input_file)
logging.info(f"file size: {file_size}")
payload = generate_header(TAG.WIFI_TA_M4, len(descriptor) + file_size) + descriptor

write_to_temp(OTA_APP_TLV_TEMP, payload)
if args.enc_enable:
return [OTA_APP_TLV_TEMP]
else:
return [OTA_APP_TLV_TEMP, args.wifi_input_file]


def generate_custom_tlvs(data):
"""
Generate custom OTA payload from a JSON object following a predefined schema.
Expand Down Expand Up @@ -259,6 +286,9 @@ def create_image(args: object):
if args.app_input_file:
input_files += generate_app(args)

if args.wifi_input_file:
input_files += generate_wifi_image(args)

if len(input_files) == 0:
print("Please specify an input option.")
sys.exit(1)
Expand Down Expand Up @@ -327,6 +357,8 @@ def any_base_int(s): return int(s, 0)
help='Bootloader Software version (string)')
create_parser.add_argument('--bl-build-date', type=str,
help='Bootloader build date (string)')
create_parser.add_argument('-wifi', "--wifi-input-file",
help='Path to OTA image for SiWx917 (TA/M4/Combined file)')

# Factory data specific arguments. Will be used to generate the TLV payload.
create_parser.add_argument('-fd', '--factory-data', action='store_true',
Expand Down

0 comments on commit 80b36ac

Please sign in to comment.