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>
This commit is contained in:
Carles Cufi 2025-02-03 12:22:47 +01:00 committed by Benjamin Cabé
commit f20168fe89
3 changed files with 13 additions and 3 deletions

View file

@ -54,6 +54,13 @@ Boards
instead of pin reset when flashing with ``west flash``. If you want to keep
using pin reset on the nRF52 family of ICs you can use ``west flash --pinreset``.
* Erasing the external memory when programming a new firmware image with ``west
flash`` on the nRF52 and nRF53 series now always correctly honors the
``--erase`` flag (and its absence) both when using the ``nrfjprog`` and
``nrfutil`` backends. Prior to this release, the ``nrjfprog`` backend would
always erase only the sectors of the external flash used by the new firmware,
and the ``nrfutil`` one would always erase the whole external flash.
Devicetree
**********

View file

@ -411,7 +411,7 @@ class NrfBinaryRunner(ZephyrBinaryRunner):
if self.family in xip_ranges:
xip_start, xip_end = xip_ranges[self.family]
if self.hex_refers_region(xip_start, xip_end):
ext_mem_erase_opt = 'ERASE_ALL'
ext_mem_erase_opt = erase_arg
self.op_program(self.hex_, erase_arg, ext_mem_erase_opt, defer=True, core=core)
self.flush(force=False)

View file

@ -91,8 +91,11 @@ class NrfJprogBinaryRunner(NrfBinaryRunner):
raise RuntimeError(f'Invalid erase mode: {erase}')
if opts.get('ext_mem_erase_mode'):
# In the future there might be multiple QSPI erase modes
cmd.append('--qspisectorerase')
if opts['ext_mem_erase_mode'] == 'ERASE_RANGES_TOUCHED_BY_FIRMWARE':
cmd.append('--qspisectorerase')
elif opts['ext_mem_erase_mode'] == 'ERASE_ALL':
cmd.append('--qspichiperase')
if opts.get('verify'):
# In the future there might be multiple verify modes
cmd.append('--verify')