From dcaabb860f65ae48fb8f20a4cddce05b99180178 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Tue, 23 Feb 2021 18:46:28 +1000 Subject: [PATCH] west: runners: jlink: prefer .hex over .bin Update the jlink runner to prefer flashing .hex files instead of .bin. This can increase programming speed in cases where there are large amounts of padding in an application. Signed-off-by: Jordan Yates --- scripts/west_commands/runners/jlink.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/west_commands/runners/jlink.py b/scripts/west_commands/runners/jlink.py index 7c64479637d..043e8508e9e 100644 --- a/scripts/west_commands/runners/jlink.py +++ b/scripts/west_commands/runners/jlink.py @@ -35,6 +35,7 @@ class JLinkBinaryRunner(ZephyrBinaryRunner): gdbserver='JLinkGDBServer', gdb_port=DEFAULT_JLINK_GDB_PORT, tui=False, tool_opt=[]): super().__init__(cfg) + self.hex_name = cfg.hex_file self.bin_name = cfg.bin_file self.elf_name = cfg.elf_file self.gdb_cmd = [cfg.gdb] if cfg.gdb else None @@ -179,15 +180,26 @@ class JLinkBinaryRunner(ZephyrBinaryRunner): def flash(self, **kwargs): self.require(self.commander) - self.ensure_output('bin') lines = ['r'] # Reset and halt the target if self.erase: lines.append('erase') # Erase all flash sectors - lines.append('loadfile {} 0x{:x}'.format(self.bin_name, - self.flash_addr)) + # Get the build artifact to flash, prefering .hex over .bin + if self.hex_name is not None and os.path.isfile(self.hex_name): + flash_file = self.hex_name + flash_fmt = 'loadfile {}' + elif self.bin_name is not None and os.path.isfile(self.bin_name): + flash_file = self.bin_name + flash_fmt = 'loadfile {} 0x{:x}' + else: + err = 'Cannot flash; no hex ({}) or bin ({}) files found.' + raise ValueError(err.format(self.hex_name, self.bin_name)) + + # Flash the selected build artifact + lines.append(flash_fmt.format(flash_file, self.flash_addr)) + if self.reset_after_load: lines.append('r') # Reset and halt the target @@ -226,5 +238,5 @@ class JLinkBinaryRunner(ZephyrBinaryRunner): '-CommanderScript', fname] + self.tool_opt) - self.logger.info('Flashing file: {}'.format(self.bin_name)) + self.logger.info('Flashing file: {}'.format(flash_file)) self.check_call(cmd)