Skip to content

Commit 48ed1a7

Browse files
JiafeiPankartben
authored andcommitted
scripts: runners: jlink: add support to flash to sram
Add new parameter "--flash-sram" for J-Link runner to flash the image to SRAM and modify the PC register to start of SRAM. Signed-off-by: Jiafei Pan <[email protected]>
1 parent 31b7565 commit 48ed1a7

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

scripts/west_commands/runners/core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,12 @@ def flash_address_from_build_conf(build_conf: BuildConfiguration):
727727
else:
728728
return build_conf['CONFIG_FLASH_BASE_ADDRESS']
729729

730+
@staticmethod
731+
def sram_address_from_build_conf(build_conf: BuildConfiguration):
732+
'''return CONFIG_SRAM_BASE_ADDRESS.
733+
'''
734+
return build_conf['CONFIG_SRAM_BASE_ADDRESS']
735+
730736
def run(self, command: str, **kwargs):
731737
'''Runs command ('flash', 'debug', 'debugserver', 'attach').
732738

scripts/west_commands/runners/jlink.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, cfg, device, dev_id=None,
5454
commander=DEFAULT_JLINK_EXE,
5555
dt_flash=True, erase=True, reset=False,
5656
iface='swd', speed='auto', flash_script = None,
57-
loader=None,
57+
loader=None, flash_sram=False,
5858
gdbserver='JLinkGDBServer',
5959
gdb_host='',
6060
gdb_port=DEFAULT_JLINK_GDB_PORT,
@@ -73,6 +73,7 @@ def __init__(self, cfg, device, dev_id=None,
7373
self.commander = commander
7474
self.flash_script = flash_script
7575
self.dt_flash = dt_flash
76+
self.flash_sram = flash_sram
7677
self.erase = erase
7778
self.reset = reset
7879
self.gdbserver = gdbserver
@@ -173,6 +174,9 @@ def do_add_parser(cls, parser):
173174
help='RTT client, default is JLinkRTTClient')
174175
parser.add_argument('--rtt-port', default=DEFAULT_JLINK_RTT_PORT,
175176
help=f'jlink rtt port, defaults to {DEFAULT_JLINK_RTT_PORT}')
177+
parser.add_argument('--flash-sram', default=False, action='store_true',
178+
help='if given, flashing the image to SRAM and '
179+
'modify PC register to be SRAM base address')
176180

177181
parser.set_defaults(reset=False)
178182

@@ -182,6 +186,7 @@ def do_create(cls, cfg, args):
182186
dev_id=args.dev_id,
183187
commander=args.commander,
184188
dt_flash=args.dt_flash,
189+
flash_sram=args.flash_sram,
185190
erase=args.erase,
186191
reset=args.reset,
187192
iface=args.iface, speed=args.speed,
@@ -386,7 +391,9 @@ def get_default_flash_commands(self):
386391
if self.file_type == FileType.HEX:
387392
flash_cmd = f'loadfile "{self.file}"'
388393
elif self.file_type == (FileType.BIN or FileType.MOT):
389-
if self.dt_flash:
394+
if self.flash_sram:
395+
flash_addr = self.sram_address_from_build_conf(self.build_conf)
396+
elif self.dt_flash:
390397
flash_addr = self.flash_address_from_build_conf(self.build_conf)
391398
else:
392399
flash_addr = 0
@@ -407,7 +414,9 @@ def get_default_flash_commands(self):
407414
flash_cmd = f'loadfile {self.mot_name}'
408415
# Preferring .bin over .elf
409416
elif self.bin_name is not None and os.path.isfile(self.bin_name):
410-
if self.dt_flash:
417+
if self.flash_sram:
418+
flash_addr = self.sram_address_from_build_conf(self.build_conf)
419+
elif self.dt_flash:
411420
flash_addr = self.flash_address_from_build_conf(self.build_conf)
412421
else:
413422
flash_addr = 0
@@ -429,6 +438,10 @@ def get_default_flash_commands(self):
429438
if self.reset:
430439
lines.append('r') # Reset and halt the target
431440

441+
if self.flash_sram:
442+
sram_addr = self.sram_address_from_build_conf(self.build_conf)
443+
lines.append(f'WReg PC 0x{sram_addr:x}') # Change PC to start of SRAM
444+
432445
lines.append('g') # Start the CPU
433446

434447
# Reset the Debug Port CTRL/STAT register

0 commit comments

Comments
 (0)