11# pyOCD debugger
22# Copyright (c) 2021-2022 Chris Reed
3+ # Copyright (c) 2025 Arm Limited
34# SPDX-License-Identifier: Apache-2.0
45#
56# Licensed under the Apache License, Version 2.0 (the "License");
@@ -65,9 +66,9 @@ def get_args(cls) -> List[argparse.ArgumentParser]:
6566 parser_options .add_argument ("--no-reset" , action = "store_true" ,
6667 help = "Specify to prevent resetting device after programming has finished." )
6768
68- parser .add_argument ("file" , metavar = "<file-path>" , nargs = "+ " ,
69+ parser .add_argument ("file" , metavar = "<file-path>" , nargs = "* " ,
6970 help = "File to write to memory. Binary files can have an optional base address appended to the file "
70- "name as '@<address>', for instance 'app.bin@0x20000'." )
71+ "name as '@<address>', for instance 'app.bin@0x20000'. Optional if '--cbuild-run' is used. " )
7172
7273 return [cls .CommonOptions .COMMON , cls .CommonOptions .CONNECT , parser ]
7374
@@ -76,6 +77,9 @@ def invoke(self) -> int:
7677 self ._increase_logging (["pyocd.flash.loader" , __name__ ])
7778
7879 # Validate arguments.
80+ if (self ._args .cbuild_run is None ) and not self ._args .file :
81+ raise ValueError ("Positional argument <file-path> is required when '--cbuild-run' is not used." )
82+
7983 if (self ._args .base_address is not None ) and (len (self ._args .file ) > 1 ):
8084 raise ValueError ("--base-address cannot be set when loading more than one file; "
8185 "use a base address suffix instead" )
@@ -86,6 +90,7 @@ def invoke(self) -> int:
8690 user_script = self ._args .script ,
8791 no_config = self ._args .no_config ,
8892 pack = self ._args .pack ,
93+ cbuild_run = self ._args .cbuild_run ,
8994 unique_id = self ._args .unique_id ,
9095 target_override = self ._args .target_override ,
9196 frequency = self ._args .frequency ,
@@ -102,6 +107,10 @@ def invoke(self) -> int:
102107 chip_erase = self ._args .erase ,
103108 trust_crc = self ._args .trust_crc ,
104109 no_reset = self ._args .no_reset )
110+ if not self ._args .file and self ._args .cbuild_run :
111+ # Populate file list from cbuild-run output if not provided explicitly
112+ cbuild_files = session .target .get_output ()
113+ self ._args .file = cbuild_files .keys ()
105114 for filename in self ._args .file :
106115 # Get an initial path with the argument as-is.
107116 file_path = Path (filename ).expanduser ()
@@ -117,6 +126,8 @@ def invoke(self) -> int:
117126 return 1
118127 else :
119128 base_address = self ._args .base_address
129+ if base_address is None and self ._args .cbuild_run :
130+ base_address = cbuild_files [filename ]
120131
121132 # Resolve our path.
122133 file_path = Path (filename ).expanduser ().resolve ()
@@ -133,5 +144,3 @@ def invoke(self) -> int:
133144 file_format = self ._args .format )
134145
135146 return 0
136-
137-
0 commit comments