17
17
#
18
18
19
19
import argparse
20
+ import pathlib
20
21
import logging
21
22
import os
22
23
import sys
@@ -59,6 +60,12 @@ class AddSignatureError(Exception):
59
60
adding signature to Secure Boot image
60
61
"""
61
62
63
+
64
+ class ArtefactsError (Exception ):
65
+ """An exception to indicate that the artefact(s) needed for processing
66
+ ave not been found."""
67
+
68
+
62
69
# Base class for all configuration exceptions
63
70
class ConfigException (Exception ):
64
71
"""Config system only exception. Makes it easier to distinguish config
@@ -306,13 +313,29 @@ def complete(message_func, elf0, hexf0, hexf1=None):
306
313
307
314
def merge_action (args ):
308
315
"""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
+
309
324
complete_func (
310
- print , args . elf , args . m4hex , args .m0hex
325
+ print , elf_file , m4hex_file , args .m0hex
311
326
)
312
327
313
328
314
329
def sign_action (args ):
315
330
"""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
+
316
339
sign_hex (
317
340
args .build_dir ,
318
341
args .m0hex_filename ,
@@ -322,8 +345,8 @@ def sign_action(args):
322
345
args .boot_scheme ,
323
346
args .cm0_img_id ,
324
347
args .cm4_img_id ,
325
- args . elf ,
326
- args . m4hex ,
348
+ elf_file ,
349
+ m4hex_file ,
327
350
args .m0hex
328
351
)
329
352
@@ -340,10 +363,7 @@ def parse_args():
340
363
"merge" , help = "Merge Cortex-M4 and Cortex-M0 HEX files."
341
364
)
342
365
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."
347
367
)
348
368
merge_subcommand .add_argument (
349
369
"--m0hex" , help = "the path to the Cortex-M0 HEX to merge."
@@ -375,10 +395,7 @@ def parse_args():
375
395
"--cm4-img-id" , type = int , help = "the Cortex-M4 image ID."
376
396
)
377
397
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."
382
399
)
383
400
sign_subcommand .add_argument (
384
401
"--m0hex" , help = "the path to the Cortex-M0 HEX to merge."
0 commit comments