Skip to content

Commit 8fc161f

Browse files
57300mmahadevan108
authored andcommitted
west: runners: nrf: Check for missing UICR
On nRF54H and nRF92, booting certain cores requires programming a UICR, which is normally generated using nrf-regtool. This should be considered an optional dependency, because we do not wish to force non-Nordic users to install it just to work with Zephyr, or just for build-only tests. When nrf-regtool is not installed, a CMake warning will be displayed, but people ignore warnings all the time. As the last line of defense, check for missing UICR in the nrfutil flash runner, to prevent our users from unintentionally programming unbootable firmware. Show a fatal error specifically if CONFIG_NRF_REGTOOL_GENERATE_UICR=y, yet no UICR exists. Signed-off-by: Grzegorz Swiderski <[email protected]>
1 parent ce02d0c commit 8fc161f

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

scripts/west_commands/runners/nrf_common.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@
3535
'NRFDL_DEVICE_CORE_APPLICATION': (0x00FF8000, 0x00FF8800),
3636
'NRFDL_DEVICE_CORE_NETWORK': (0x01FF8000, 0x01FF8800),
3737
},
38+
'NRF54H_FAMILY': {
39+
'NRFDL_DEVICE_CORE_APPLICATION': (0x0FFF8000, 0x0FFF8800),
40+
'NRFDL_DEVICE_CORE_NETWORK': (0x0FFFA000, 0x0FFFA800),
41+
},
3842
'NRF91_FAMILY': {
3943
'NRFDL_DEVICE_CORE_APPLICATION': (0x00FF8000, 0x00FF8800),
40-
}
44+
},
45+
'NRF92_FAMILY': {
46+
'NRFDL_DEVICE_CORE_APPLICATION': (0x0FFF8000, 0x0FFF8800),
47+
'NRFDL_DEVICE_CORE_NETWORK': (0x0FFFA000, 0x0FFFA800),
48+
},
4149
}
4250

4351
# Relative to the root of the hal_nordic module
@@ -307,6 +315,19 @@ def program_hex(self):
307315
self.build_conf.getboolean('CONFIG_SOC_NRF54H20_ENGB_CPURAD') or
308316
self.build_conf.getboolean('CONFIG_SOC_NRF9280_CPURAD')
309317
)
318+
generated_uicr = self.build_conf.getboolean('CONFIG_NRF_REGTOOL_GENERATE_UICR')
319+
320+
if cpuapp:
321+
core = 'NRFDL_DEVICE_CORE_APPLICATION'
322+
elif cpurad:
323+
core = 'NRFDL_DEVICE_CORE_NETWORK'
324+
325+
if generated_uicr and not self.hex_get_uicrs().get(core):
326+
raise RuntimeError(
327+
f"Expected a UICR to be contained in: {self.hex_}\n"
328+
"Please ensure that the correct version of nrf-regtool is "
329+
"installed, then run 'west build --cmake' to try again."
330+
)
310331

311332
if self.erase:
312333
self.exec_op('erase', core='NRFDL_DEVICE_CORE_APPLICATION')
@@ -335,18 +356,9 @@ def program_hex(self):
335356
mpi_hex_dir / 'suit_installed_envelopes_application_merged.hex')
336357
self.op_program(app_root_envelope_hex_file, 'ERASE_NONE', None, defer=True, core='NRFDL_DEVICE_CORE_APPLICATION')
337358

338-
if cpuapp:
339-
if not self.erase and self.build_conf.getboolean('CONFIG_NRF_REGTOOL_GENERATE_UICR'):
340-
self.exec_op('erase', core='NRFDL_DEVICE_CORE_APPLICATION',
341-
option={'chip_erase_mode': 'ERASE_UICR',
342-
'qspi_erase_mode': 'ERASE_NONE'})
343-
core = 'NRFDL_DEVICE_CORE_APPLICATION'
344-
elif cpurad:
345-
if not self.erase and self.build_conf.getboolean('CONFIG_NRF_REGTOOL_GENERATE_UICR'):
346-
self.exec_op('erase', core='NRFDL_DEVICE_CORE_NETWORK',
347-
option={'chip_erase_mode': 'ERASE_UICR',
348-
'qspi_erase_mode': 'ERASE_NONE'})
349-
core = 'NRFDL_DEVICE_CORE_NETWORK'
359+
if not self.erase and generated_uicr:
360+
self.exec_op('erase', core=core, option={'chip_erase_mode': 'ERASE_UICR',
361+
'qspi_erase_mode': 'ERASE_NONE'})
350362
else:
351363
if self.erase:
352364
erase_arg = 'ERASE_ALL'

0 commit comments

Comments
 (0)