scripts: runners: stm32cubeprogrammer: Review f/w selection algorithm

Aim is to avoid 2 issues:
- Requesting --download-address to flash hex files
- Flashing hex files (non signed) on N6 which works but doesn't allow
persistent firmware

Hence this changes binds --download-address with usage of .bin files.
If --download-address was not provided, default to hex flashing.

File existence done with isfile() will ensure the required file
is available before flashing and report an error if this is not the
case.
Note: In specific N6 case, we're verifying zephyr.signed.bin is
available instead of zephyr.bin. This is ensure since self.cfg.bin_file
matches runners_yaml_props_target configuration (set to
zephyr.signed.bin on STM32N6).

Signed-off-by: Erwan Gouriou <erwan.gouriou@st.com>
This commit is contained in:
Erwan Gouriou 2025-02-06 17:19:31 +01:00 committed by Benjamin Cabé
commit 1be4025550

View file

@ -169,7 +169,7 @@ class STM32CubeProgrammerBinaryRunner(ZephyrBinaryRunner):
# is displayed when an invalid value is provided for this argument. # is displayed when an invalid value is provided for this argument.
type=functools.wraps(int)(lambda s: int(s, base=0)), type=functools.wraps(int)(lambda s: int(s, base=0)),
required=False, required=False,
help="Address where flashing should be done" help="Flashing location address. To be used only with .bin files"
) )
parser.add_argument( parser.add_argument(
"--download-modifiers", "--download-modifiers",
@ -271,15 +271,19 @@ class STM32CubeProgrammerBinaryRunner(ZephyrBinaryRunner):
if self._erase: if self._erase:
self.check_call(cmd + ["--erase", "all"]) self.check_call(cmd + ["--erase", "all"])
# flash image and run application # Define binary to be loaded
if self._use_elf: if self._use_elf:
# Use elf file if instructed to do so.
dl_file = self.cfg.elf_file dl_file = self.cfg.elf_file
elif self.cfg.bin_file is not None and os.path.isfile(self.cfg.bin_file) and \ elif self.cfg.bin_file is not None and self._download_address is not None:
"zephyr.signed" in self.cfg.bin_file: # Use bin file if a binary is available and --download-address provided
dl_file = self.cfg.bin_file dl_file = self.cfg.bin_file
elif self.cfg.hex_file is not None and os.path.isfile(self.cfg.hex_file): elif self.cfg.hex_file is not None:
# --user-elf not used and no bin file given, default to hex # Neither --use-elf nor --download-address are present:
# default to flashing using hex file.
dl_file = self.cfg.hex_file dl_file = self.cfg.hex_file
# Verify file configuration
if dl_file is None: if dl_file is None:
raise RuntimeError('cannot flash; no download file was specified') raise RuntimeError('cannot flash; no download file was specified')
elif not os.path.isfile(dl_file): elif not os.path.isfile(dl_file):