Skip to content

Commit fec5ad1

Browse files
carlescufiArekBalysNordic
authored andcommitted
[nrf fromtree] 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 <[email protected]> (cherry picked from commit f20168f)
1 parent 77425f1 commit fec5ad1

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

doc/releases/migration-guide-4.1.rst

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ Boards
4646
instead of pin reset when flashing with ``west flash``. If you want to keep
4747
using pin reset on the nRF52 family of ICs you can use ``west flash --pinreset``.
4848

49+
* Erasing the external memory when programming a new firmware image with ``west
50+
flash`` on the nRF52 and nRF53 series now always correctly honors the
51+
``--erase`` flag (and its absence) both when using the ``nrfjprog`` and
52+
``nrfutil`` backends. Prior to this release, the ``nrjfprog`` backend would
53+
always erase only the sectors of the external flash used by the new firmware,
54+
and the ``nrfutil`` one would always erase the whole external flash.
55+
4956
Devicetree
5057
**********
5158

scripts/west_commands/runners/nrf_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def program_hex(self):
416416
if self.family in xip_ranges:
417417
xip_start, xip_end = xip_ranges[self.family]
418418
if self.hex_refers_region(xip_start, xip_end):
419-
ext_mem_erase_opt = 'ERASE_ALL'
419+
ext_mem_erase_opt = erase_arg
420420

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

scripts/west_commands/runners/nrfjprog.py

+5-2
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)