Skip to content

Commit f72aef1

Browse files
oyvindronningstadnashif
authored andcommitted
sanitycheck: Make --hardware-map and --west-flash together
When passing a using --hardware-map, sanitycheck would ignore extra args passed via --west-flash, such as --west-flash="--erase". This is because the command with the extra args was overwritten by the command with the runner info from the hardware map. This patch merges those code paths so they are aware of each other and of --west-runner. Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
1 parent e7f4074 commit f72aef1

File tree

1 file changed

+46
-47
lines changed

1 file changed

+46
-47
lines changed

scripts/sanity_chk/sanitylib.py

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -562,59 +562,13 @@ def run_custom_script(script, timeout):
562562
def handle(self):
563563
out_state = "failed"
564564

565-
if self.suite.west_flash is not None:
566-
command = ["west", "flash", "--skip-rebuild", "-d", self.build_dir]
567-
if self.suite.west_runner:
568-
command.append("--runner")
569-
command.append(self.suite.west_runner)
570-
# There are three ways this option is used.
571-
# 1) bare: --west-flash
572-
# This results in options.west_flash == []
573-
# 2) with a value: --west-flash="--board-id=42"
574-
# This results in options.west_flash == "--board-id=42"
575-
# 3) Multiple values: --west-flash="--board-id=42,--erase"
576-
# This results in options.west_flash == "--board-id=42 --erase"
577-
if self.suite.west_flash != []:
578-
command.append('--')
579-
command.extend(self.suite.west_flash.split(','))
580-
else:
581-
command = [self.generator_cmd, "-C", self.build_dir, "flash"]
582-
583565
while not self.device_is_available(self.instance):
584566
logger.debug("Waiting for device {} to become available".format(self.instance.platform.name))
585567
time.sleep(1)
586568

587569
hardware = self.get_available_device(self.instance)
588-
589570
if hardware:
590-
runner = hardware.get('runner', None)
591-
if runner:
592-
board_id = hardware.get("probe_id", hardware.get("id", None))
593-
product = hardware.get("product", None)
594-
command = ["west", "flash", "--skip-rebuild", "-d", self.build_dir]
595-
command.append("--runner")
596-
command.append(hardware.get('runner', None))
597-
if runner == "pyocd":
598-
command.append("--board-id")
599-
command.append(board_id)
600-
elif runner == "nrfjprog":
601-
command.append('--')
602-
command.append("--snr")
603-
command.append(board_id)
604-
elif runner == "openocd" and product == "STM32 STLink":
605-
command.append('--')
606-
command.append("--cmd-pre-init")
607-
command.append("hla_serial %s" % (board_id))
608-
elif runner == "openocd" and product == "STLINK-V3":
609-
command.append('--')
610-
command.append("--cmd-pre-init")
611-
command.append("hla_serial %s" % (board_id))
612-
elif runner == "openocd" and product == "EDBG CMSIS-DAP":
613-
command.append('--')
614-
command.append("--cmd-pre-init")
615-
command.append("cmsis_dap_serial %s" % (board_id))
616-
elif runner == "jlink":
617-
command.append("--tool-opt=-SelectEmuBySN %s" % (board_id))
571+
runner = hardware.get('runner', None) or self.suite.west_runner
618572

619573
serial_pty = hardware.get('serial_pty', None)
620574
if serial_pty:
@@ -632,6 +586,51 @@ def handle(self):
632586

633587
logger.debug("Using serial device {}".format(serial_device))
634588

589+
if (self.suite.west_flash is not None) or runner:
590+
command = ["west", "flash", "--skip-rebuild", "-d", self.build_dir]
591+
command_extra_args = []
592+
593+
# There are three ways this option is used.
594+
# 1) bare: --west-flash
595+
# This results in options.west_flash == []
596+
# 2) with a value: --west-flash="--board-id=42"
597+
# This results in options.west_flash == "--board-id=42"
598+
# 3) Multiple values: --west-flash="--board-id=42,--erase"
599+
# This results in options.west_flash == "--board-id=42 --erase"
600+
if self.suite.west_flash and self.suite.west_flash != []:
601+
command_extra_args.extend(self.suite.west_flash.split(','))
602+
603+
if runner:
604+
command.append("--runner")
605+
command.append(runner)
606+
607+
board_id = hardware.get("probe_id", hardware.get("id", None))
608+
product = hardware.get("product", None)
609+
if board_id is not None:
610+
if runner == "pyocd":
611+
command_extra_args.append("--board-id")
612+
command_extra_args.append(board_id)
613+
elif runner == "nrfjprog":
614+
command_extra_args.append("--snr")
615+
command_extra_args.append(board_id)
616+
elif runner == "openocd" and product == "STM32 STLink":
617+
command_extra_args.append("--cmd-pre-init")
618+
command_extra_args.append("hla_serial %s" % (board_id))
619+
elif runner == "openocd" and product == "STLINK-V3":
620+
command_extra_args.append("--cmd-pre-init")
621+
command_extra_args.append("hla_serial %s" % (board_id))
622+
elif runner == "openocd" and product == "EDBG CMSIS-DAP":
623+
command_extra_args.append("--cmd-pre-init")
624+
command_extra_args.append("cmsis_dap_serial %s" % (board_id))
625+
elif runner == "jlink":
626+
command.append("--tool-opt=-SelectEmuBySN %s" % (board_id))
627+
628+
if command_extra_args != []:
629+
command.append('--')
630+
command.extend(command_extra_args)
631+
else:
632+
command = [self.generator_cmd, "-C", self.build_dir, "flash"]
633+
635634
try:
636635
ser = serial.Serial(
637636
serial_device,

0 commit comments

Comments
 (0)