Skip to content

Commit d750daa

Browse files
vignesh-aerlynckartben
authored andcommitted
west: fix for west flash --context with sysbuild.
Fix west flash --context fails for Sysbuild projects issue. Signed-off-by: Vignesh Pandian <vignesh@aerlync.com>
1 parent 1c46508 commit d750daa

File tree

1 file changed

+83
-34
lines changed

1 file changed

+83
-34
lines changed

scripts/west_commands/run_common.py

Lines changed: 83 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) 2018 Open Source Foundries Limited.
22
# Copyright (c) 2023 Nordic Semiconductor ASA
3+
# Copyright (c) 2025 Aerlync Labs Inc.
34
#
45
# SPDX-License-Identifier: Apache-2.0
56

@@ -181,6 +182,34 @@ def add_parser_common(command, parser_adder=None, parser=None):
181182

182183
return parser
183184

185+
def is_sysbuild(build_dir):
186+
# Check if the build directory is part of a sysbuild (multi-image build).
187+
domains_yaml_path = path.join(build_dir, "domains.yaml")
188+
return path.exists(domains_yaml_path)
189+
190+
def get_domains_to_process(build_dir, args, domain_file, get_all_domain=False):
191+
try:
192+
domains = load_domains(build_dir)
193+
except Exception as e:
194+
log.die(f"Failed to load domains: {e}")
195+
196+
if domain_file is None:
197+
if getattr(args, "domain", None) is None and get_all_domain:
198+
# This option for getting all available domains in the case of --context
199+
# So default domain will be used.
200+
return domains.get_domains()
201+
if getattr(args, "domain", None) is None:
202+
# No domains are passed down and no domains specified by the user.
203+
# So default domain will be used.
204+
return [domains.get_default_domain()]
205+
else:
206+
# No domains are passed down, but user has specified domains to use.
207+
# Get the user specified domains.
208+
return domains.get_domains(args.domain)
209+
else:
210+
# Use domains from domain file with flash order
211+
return domains.get_domains(args.domain, default_flash_order=True)
212+
184213
def do_run_common(command, user_args, user_runner_args, domain_file=None):
185214
# This is the main routine for all the "west flash", "west debug",
186215
# etc. commands.
@@ -218,18 +247,7 @@ def do_run_common(command, user_args, user_runner_args, domain_file=None):
218247
if not user_args.skip_rebuild:
219248
rebuild(command, build_dir, user_args)
220249

221-
if domain_file is None:
222-
if user_args.domain is None:
223-
# No domains are passed down and no domains specified by the user.
224-
# So default domain will be used.
225-
domains = [load_domains(build_dir).get_default_domain()]
226-
else:
227-
# No domains are passed down, but user has specified domains to use.
228-
# Get the user specified domains.
229-
domains = load_domains(build_dir).get_domains(user_args.domain)
230-
else:
231-
domains = load_domains(build_dir).get_domains(user_args.domain,
232-
default_flash_order=True)
250+
domains = get_domains_to_process(build_dir, user_args, domain_file)
233251

234252
if len(domains) > 1:
235253
if len(user_runner_args) > 0:
@@ -694,40 +712,71 @@ def dump_traceback():
694712

695713
def dump_context(command, args, unknown_args):
696714
build_dir = get_build_dir(args, die_if_none=False)
715+
get_all_domain = False
716+
697717
if build_dir is None:
698718
log.wrn('no --build-dir given or found; output will be limited')
699-
runners_yaml = None
700-
else:
701-
build_conf = BuildConfiguration(build_dir)
702-
board = build_conf.get('CONFIG_BOARD_TARGET')
703-
yaml_path = runners_yaml_path(build_dir, board)
704-
runners_yaml = load_runners_yaml(yaml_path)
719+
dump_context_no_config(command, None)
720+
return
721+
722+
if is_sysbuild(build_dir):
723+
get_all_domain = True
705724

706725
# Re-build unless asked not to, to make sure the output is up to date.
707726
if build_dir and not args.skip_rebuild:
708727
rebuild(command, build_dir, args)
709728

729+
domains = get_domains_to_process(build_dir, args, None, get_all_domain)
730+
731+
if len(domains) > 1 and not getattr(args, "domain", None):
732+
log.inf("Multiple domains available:")
733+
for i, domain in enumerate(domains, 1):
734+
log.inf(f"{INDENT}{i}. {domain.name} (build_dir: {domain.build_dir})")
735+
736+
while True:
737+
try:
738+
choice = input(f"Select domain (1-{len(domains)}): ")
739+
choice = int(choice)
740+
if 1 <= choice <= len(domains):
741+
domains = [domains[choice-1]]
742+
break
743+
log.wrn(f"Please enter a number between 1 and {len(domains)}")
744+
except ValueError:
745+
log.wrn("Please enter a valid number")
746+
except EOFError:
747+
log.die("Input cancelled, exiting")
748+
749+
selected_build_dir = domains[0].build_dir
750+
751+
if not path.exists(selected_build_dir):
752+
log.die(f"Build directory does not exist: {selected_build_dir}")
753+
754+
build_conf = BuildConfiguration(selected_build_dir)
755+
756+
board = build_conf.get('CONFIG_BOARD_TARGET')
757+
if not board:
758+
log.die("CONFIG_BOARD_TARGET not found in build configuration.")
759+
760+
yaml_path = runners_yaml_path(selected_build_dir, board)
761+
if not path.exists(yaml_path):
762+
log.die(f"runners.yaml not found in: {yaml_path}")
763+
764+
runners_yaml = load_runners_yaml(yaml_path)
765+
766+
# Dump runner info
767+
log.inf(f'build configuration:', colorize=True)
768+
log.inf(f'{INDENT}build directory: {build_dir}')
769+
log.inf(f'{INDENT}board: {board}')
770+
log.inf(f'{INDENT}runners.yaml: {yaml_path}')
710771
if args.runner:
711772
try:
712773
cls = get_runner_cls(args.runner)
774+
dump_runner_context(command, cls, runners_yaml)
713775
except ValueError:
714-
log.die(f'invalid runner name {args.runner}; choices: ' +
715-
', '.join(cls.name() for cls in
716-
ZephyrBinaryRunner.get_runners()))
776+
available_runners = ", ".join(cls.name() for cls in ZephyrBinaryRunner.get_runners())
777+
log.die(f"Invalid runner name {args.runner}; choices: {available_runners}")
717778
else:
718-
cls = None
719-
720-
if runners_yaml is None:
721-
dump_context_no_config(command, cls)
722-
else:
723-
log.inf(f'build configuration:', colorize=True)
724-
log.inf(f'{INDENT}build directory: {build_dir}')
725-
log.inf(f'{INDENT}board: {board}')
726-
log.inf(f'{INDENT}runners.yaml: {yaml_path}')
727-
if cls:
728-
dump_runner_context(command, cls, runners_yaml)
729-
else:
730-
dump_all_runner_context(command, runners_yaml, board, build_dir)
779+
dump_all_runner_context(command, runners_yaml, board, selected_build_dir)
731780

732781
def dump_context_no_config(command, cls):
733782
if not cls:

0 commit comments

Comments
 (0)