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 <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2021-02-23 18:46:28 +10:00 committed by Maureen Helm
parent b5a3fe1471
commit dcaabb860f

View file

@ -35,6 +35,7 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
gdbserver='JLinkGDBServer', gdb_port=DEFAULT_JLINK_GDB_PORT, gdbserver='JLinkGDBServer', gdb_port=DEFAULT_JLINK_GDB_PORT,
tui=False, tool_opt=[]): tui=False, tool_opt=[]):
super().__init__(cfg) super().__init__(cfg)
self.hex_name = cfg.hex_file
self.bin_name = cfg.bin_file self.bin_name = cfg.bin_file
self.elf_name = cfg.elf_file self.elf_name = cfg.elf_file
self.gdb_cmd = [cfg.gdb] if cfg.gdb else None self.gdb_cmd = [cfg.gdb] if cfg.gdb else None
@ -179,15 +180,26 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
def flash(self, **kwargs): def flash(self, **kwargs):
self.require(self.commander) self.require(self.commander)
self.ensure_output('bin')
lines = ['r'] # Reset and halt the target lines = ['r'] # Reset and halt the target
if self.erase: if self.erase:
lines.append('erase') # Erase all flash sectors lines.append('erase') # Erase all flash sectors
lines.append('loadfile {} 0x{:x}'.format(self.bin_name, # Get the build artifact to flash, prefering .hex over .bin
self.flash_addr)) 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: if self.reset_after_load:
lines.append('r') # Reset and halt the target lines.append('r') # Reset and halt the target
@ -226,5 +238,5 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
'-CommanderScript', fname] + '-CommanderScript', fname] +
self.tool_opt) self.tool_opt)
self.logger.info('Flashing file: {}'.format(self.bin_name)) self.logger.info('Flashing file: {}'.format(flash_file))
self.check_call(cmd) self.check_call(cmd)