|
1 | 1 | # Copyright (c) 2018 Open Source Foundries Limited.
|
2 | 2 | # Copyright (c) 2023 Nordic Semiconductor ASA
|
| 3 | +# Copyright (c) 2025 Aerlync Labs Inc. |
3 | 4 | #
|
4 | 5 | # SPDX-License-Identifier: Apache-2.0
|
5 | 6 |
|
@@ -181,6 +182,34 @@ def add_parser_common(command, parser_adder=None, parser=None):
|
181 | 182 |
|
182 | 183 | return parser
|
183 | 184 |
|
| 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 | + |
184 | 213 | def do_run_common(command, user_args, user_runner_args, domain_file=None):
|
185 | 214 | # This is the main routine for all the "west flash", "west debug",
|
186 | 215 | # etc. commands.
|
@@ -218,18 +247,7 @@ def do_run_common(command, user_args, user_runner_args, domain_file=None):
|
218 | 247 | if not user_args.skip_rebuild:
|
219 | 248 | rebuild(command, build_dir, user_args)
|
220 | 249 |
|
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) |
233 | 251 |
|
234 | 252 | if len(domains) > 1:
|
235 | 253 | if len(user_runner_args) > 0:
|
@@ -694,40 +712,71 @@ def dump_traceback():
|
694 | 712 |
|
695 | 713 | def dump_context(command, args, unknown_args):
|
696 | 714 | build_dir = get_build_dir(args, die_if_none=False)
|
| 715 | + get_all_domain = False |
| 716 | + |
697 | 717 | if build_dir is None:
|
698 | 718 | 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 |
705 | 724 |
|
706 | 725 | # Re-build unless asked not to, to make sure the output is up to date.
|
707 | 726 | if build_dir and not args.skip_rebuild:
|
708 | 727 | rebuild(command, build_dir, args)
|
709 | 728 |
|
| 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}') |
710 | 771 | if args.runner:
|
711 | 772 | try:
|
712 | 773 | cls = get_runner_cls(args.runner)
|
| 774 | + dump_runner_context(command, cls, runners_yaml) |
713 | 775 | 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}") |
717 | 778 | 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) |
731 | 780 |
|
732 | 781 | def dump_context_no_config(command, cls):
|
733 | 782 | if not cls:
|
|
0 commit comments