Skip to content

Commit f20168f

Browse files
carlescufikartben
authored andcommitted
scripts: runners: nrf: Honor the --erase flag for external memory
Both backends supported as runners for nRF ICs, nrfjprog and nrfutil, support erasing external memory as part of the programming operation. Before this patch, and when the firmware was detected to be partially or fully placed in external flash by inspecting the .hex address range, the runner would instruct the backend tool to fully erase the external flash (but the nrfjprog runner would ignore that, always erasing only the sectors required). Instead, correctly default to erasing only the sectors that are required to program the new firmware image in both tools, and erase it completely only when the --erase flag is provided by the user. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
1 parent 90b989c commit f20168f

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

doc/releases/migration-guide-4.1.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ Boards
5454
instead of pin reset when flashing with ``west flash``. If you want to keep
5555
using pin reset on the nRF52 family of ICs you can use ``west flash --pinreset``.
5656

57+
* Erasing the external memory when programming a new firmware image with ``west
58+
flash`` on the nRF52 and nRF53 series now always correctly honors the
59+
``--erase`` flag (and its absence) both when using the ``nrfjprog`` and
60+
``nrfutil`` backends. Prior to this release, the ``nrjfprog`` backend would
61+
always erase only the sectors of the external flash used by the new firmware,
62+
and the ``nrfutil`` one would always erase the whole external flash.
63+
5764
Devicetree
5865
**********
5966

scripts/west_commands/runners/nrf_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def program_hex(self):
411411
if self.family in xip_ranges:
412412
xip_start, xip_end = xip_ranges[self.family]
413413
if self.hex_refers_region(xip_start, xip_end):
414-
ext_mem_erase_opt = 'ERASE_ALL'
414+
ext_mem_erase_opt = erase_arg
415415

416416
self.op_program(self.hex_, erase_arg, ext_mem_erase_opt, defer=True, core=core)
417417
self.flush(force=False)

scripts/west_commands/runners/nrfjprog.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,11 @@ def do_exec_op(self, op, force=False):
9191
raise RuntimeError(f'Invalid erase mode: {erase}')
9292

9393
if opts.get('ext_mem_erase_mode'):
94-
# In the future there might be multiple QSPI erase modes
95-
cmd.append('--qspisectorerase')
94+
if opts['ext_mem_erase_mode'] == 'ERASE_RANGES_TOUCHED_BY_FIRMWARE':
95+
cmd.append('--qspisectorerase')
96+
elif opts['ext_mem_erase_mode'] == 'ERASE_ALL':
97+
cmd.append('--qspichiperase')
98+
9699
if opts.get('verify'):
97100
# In the future there might be multiple verify modes
98101
cmd.append('--verify')

0 commit comments

Comments
 (0)