1717#
1818
1919import argparse
20+ import pathlib
2021import logging
2122import os
2223import sys
@@ -59,6 +60,12 @@ class AddSignatureError(Exception):
5960 adding signature to Secure Boot image
6061 """
6162
63+
64+ class ArtefactsError (Exception ):
65+ """An exception to indicate that the artefact(s) needed for processing
66+ ave not been found."""
67+
68+
6269# Base class for all configuration exceptions
6370class ConfigException (Exception ):
6471 """Config system only exception. Makes it easier to distinguish config
@@ -306,13 +313,29 @@ def complete(message_func, elf0, hexf0, hexf1=None):
306313
307314def merge_action (args ):
308315 """Entry point for the "merge" CLI command."""
316+ try :
317+ elf_file = list (pathlib .Path (args .artefacts_location ).glob ("*.elf" ))[0 ]
318+ m4hex_file = list (pathlib .Path (args .artefacts_location ).glob ("*.hex" ))[0 ]
319+ except IndexError :
320+ raise ArtefactsError (
321+ f"Could not find elf and/or hex file in { args .artefacts_location } "
322+ )
323+
309324 complete_func (
310- print , args . elf , args . m4hex , args .m0hex
325+ print , elf_file , m4hex_file , args .m0hex
311326 )
312327
313328
314329def sign_action (args ):
315330 """Entry point for the "sign" CLI command."""
331+ try :
332+ elf_file = list (pathlib .Path (args .artefacts_location ).glob ("*.elf" ))[0 ]
333+ m4hex_file = list (pathlib .Path (args .artefacts_location ).glob ("*.hex" ))[0 ]
334+ except IndexError :
335+ raise ArtefactsError (
336+ f"Could not find elf and/or hex file in { args .artefacts_location } "
337+ )
338+
316339 sign_hex (
317340 args .build_dir ,
318341 args .m0hex_filename ,
@@ -322,8 +345,8 @@ def sign_action(args):
322345 args .boot_scheme ,
323346 args .cm0_img_id ,
324347 args .cm4_img_id ,
325- args . elf ,
326- args . m4hex ,
348+ elf_file ,
349+ m4hex_file ,
327350 args .m0hex
328351 )
329352
@@ -340,10 +363,7 @@ def parse_args():
340363 "merge" , help = "Merge Cortex-M4 and Cortex-M0 HEX files."
341364 )
342365 merge_subcommand .add_argument (
343- "--elf" , required = True , help = "the application ELF file."
344- )
345- merge_subcommand .add_argument (
346- "--m4hex" , required = True , help = "the path to the Cortex-M4 HEX to merge."
366+ "--artefacts-location" , required = True , help = "the path to the application artefacts."
347367 )
348368 merge_subcommand .add_argument (
349369 "--m0hex" , help = "the path to the Cortex-M0 HEX to merge."
@@ -375,10 +395,7 @@ def parse_args():
375395 "--cm4-img-id" , type = int , help = "the Cortex-M4 image ID."
376396 )
377397 sign_subcommand .add_argument (
378- "--elf" , required = True , help = "the application ELF file."
379- )
380- sign_subcommand .add_argument (
381- "--m4hex" , required = True , help = "the path to the Cortex-M4 HEX to merge."
398+ "--artefacts-location" , required = True , help = "the path to the application artefacts."
382399 )
383400 sign_subcommand .add_argument (
384401 "--m0hex" , help = "the path to the Cortex-M0 HEX to merge."
0 commit comments