Skip to content

Commit ae8acbd

Browse files
committed
[nrf fromtree] scripts: runners: nrf: Remove the nRF5340 special handling
This is no longer necessary, because thanks to sysbuild we no longer invoke a runner with a .hex file that is the result of merging builds for more than one core. Signed-off-by: Carles Cufi <[email protected]> (cherry picked from commit aaefaad)
1 parent 9278113 commit ae8acbd

File tree

6 files changed

+41
-260
lines changed

6 files changed

+41
-260
lines changed

scripts/west_commands/runners/nrf_common.py

Lines changed: 22 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -295,31 +295,37 @@ def recover_target(self):
295295

296296
self.exec_op('recover')
297297

298+
def _get_core(self):
299+
if self.family in ('nrf54h', 'nrf92'):
300+
if (self.build_conf.getboolean('CONFIG_SOC_NRF54H20_CPUAPP') or
301+
self.build_conf.getboolean('CONFIG_SOC_NRF9280_CPUAPP')):
302+
return 'Application'
303+
if (self.build_conf.getboolean('CONFIG_SOC_NRF54H20_CPURAD') or
304+
self.build_conf.getboolean('CONFIG_SOC_NRF9280_CPURAD')):
305+
return 'Network'
306+
raise RuntimeError(f'Core not found for family: {self.family}')
307+
308+
if self.family in ('nrf53'):
309+
if self.build_conf.getboolean('CONFIG_SOC_NRF5340_CPUAPP'):
310+
return 'Application'
311+
if self.build_conf.getboolean('CONFIG_SOC_NRF5340_CPUNET'):
312+
return 'Network'
313+
raise RuntimeError(f'Core not found for family: {self.family}')
314+
315+
return None
316+
298317
def program_hex(self):
299318
# Get the command use to actually program self.hex_.
300319
self.logger.info(f'Flashing file: {self.hex_}')
301320

302321
# What type of erase/core arguments should we pass to the tool?
303-
core = None
322+
core = self._get_core()
304323

305324
if self.family in ('nrf54h', 'nrf92'):
306325
erase_arg = 'ERASE_NONE'
307326

308-
cpuapp = (
309-
self.build_conf.getboolean('CONFIG_SOC_NRF54H20_CPUAPP') or
310-
self.build_conf.getboolean('CONFIG_SOC_NRF9280_CPUAPP')
311-
)
312-
cpurad = (
313-
self.build_conf.getboolean('CONFIG_SOC_NRF54H20_CPURAD') or
314-
self.build_conf.getboolean('CONFIG_SOC_NRF9280_CPURAD')
315-
)
316327
generated_uicr = self.build_conf.getboolean('CONFIG_NRF_REGTOOL_GENERATE_UICR')
317328

318-
if cpuapp:
319-
core = 'Application'
320-
elif cpurad:
321-
core = 'Network'
322-
323329
if generated_uicr and not self.hex_get_uicrs().get(core):
324330
raise RuntimeError(
325331
f"Expected a UICR to be contained in: {self.hex_}\n"
@@ -367,7 +373,7 @@ def program_hex(self):
367373
# Handle SUIT root manifest if application manifests are not used.
368374
# If an application firmware is built, the root envelope is merged
369375
# with other application manifests as well as the output HEX file.
370-
if not cpuapp and self.sysbuild_conf.get('SB_CONFIG_SUIT_ENVELOPE'):
376+
if core != 'Application' and self.sysbuild_conf.get('SB_CONFIG_SUIT_ENVELOPE'):
371377
app_root_envelope_hex_file = os.fspath(
372378
mpi_hex_dir / 'suit_installed_envelopes_application_merged.hex'
373379
)
@@ -399,83 +405,9 @@ def program_hex(self):
399405
if self.hex_refers_region(xip_start, xip_end):
400406
ext_mem_erase_opt = 'ERASE_ALL'
401407

402-
# What tool commands do we need to flash this target?
403-
if self.family == 'nrf53':
404-
# nRF53 requires special treatment due to the extra coprocessor.
405-
self.program_hex_nrf53(erase_arg, ext_mem_erase_opt)
406-
else:
407-
self.op_program(self.hex_, erase_arg, ext_mem_erase_opt, defer=True, core=core)
408-
408+
self.op_program(self.hex_, erase_arg, ext_mem_erase_opt, defer=True, core=core)
409409
self.flush(force=False)
410410

411-
def program_hex_nrf53(self, erase_arg, ext_mem_erase_opt):
412-
# program_hex() helper for nRF53.
413-
414-
# *********************** NOTE *******************************
415-
# self.hex_ can contain code for both the application core and
416-
# the network core.
417-
#
418-
# We can't assume, for example, that
419-
# CONFIG_SOC_NRF5340_CPUAPP=y means self.hex_ only contains
420-
# data for the app core's flash: the user can put arbitrary
421-
# addresses into one of the files in HEX_FILES_TO_MERGE.
422-
#
423-
# Therefore, on this family, we may need to generate two new
424-
# hex files, one for each core, and flash them individually
425-
# with the correct '--coprocessor' arguments.
426-
#
427-
# Kind of hacky, but it works, and the tools are not capable of
428-
# flashing to both cores at once. If self.hex_ only affects
429-
# one core's flash, then we skip the extra work to save time.
430-
# ************************************************************
431-
432-
# Address range of the network coprocessor's flash. From nRF5340 OPS.
433-
# We should get this from DTS instead if multiple values are possible,
434-
# but this is fine for now.
435-
net_flash_start = 0x01000000
436-
net_flash_end = 0x0103FFFF
437-
438-
# If there is nothing in the hex file for the network core,
439-
# only the application core is programmed.
440-
if not self.hex_refers_region(net_flash_start, net_flash_end):
441-
self.op_program(self.hex_, erase_arg, ext_mem_erase_opt, defer=True,
442-
core='Application')
443-
# If there is some content that addresses a region beyond the network
444-
# core flash range, two hex files are generated and the two cores
445-
# are programmed one by one.
446-
elif self.hex_contents.minaddr() < net_flash_start or \
447-
self.hex_contents.maxaddr() > net_flash_end:
448-
449-
net_hex, app_hex = IntelHex(), IntelHex()
450-
for start, end in self.hex_contents.segments():
451-
if net_flash_start <= start <= net_flash_end:
452-
net_hex.merge(self.hex_contents[start:end])
453-
else:
454-
app_hex.merge(self.hex_contents[start:end])
455-
456-
hex_path = Path(self.hex_)
457-
hex_dir, hex_name = hex_path.parent, hex_path.name
458-
459-
net_hex_file = os.fspath(
460-
hex_dir / f'GENERATED_CP_NETWORK_{hex_name}')
461-
app_hex_file = os.fspath(
462-
hex_dir / f'GENERATED_CP_APPLICATION_{hex_name}')
463-
464-
self.logger.info(
465-
f'{self.hex_} targets both nRF53 coprocessors; '
466-
f'splitting it into: {net_hex_file} and {app_hex_file}')
467-
468-
net_hex.write_hex_file(net_hex_file)
469-
app_hex.write_hex_file(app_hex_file)
470-
471-
self.op_program(net_hex_file, erase_arg, None, defer=True,
472-
core='Network')
473-
self.op_program(app_hex_file, erase_arg, ext_mem_erase_opt, defer=True,
474-
core='Application')
475-
# Otherwise, only the network core is programmed.
476-
else:
477-
self.op_program(self.hex_, erase_arg, None, defer=True,
478-
core='Network')
479411

480412
def reset_target(self):
481413
if self.family == 'nrf52' and not self.softreset:

scripts/west_commands/tests/nrf/README.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/west_commands/tests/nrf/nrf5340_app_and_net.hex

Lines changed: 0 additions & 5 deletions
This file was deleted.

scripts/west_commands/tests/nrf/nrf5340_app_only.hex

Lines changed: 0 additions & 2 deletions
This file was deleted.

scripts/west_commands/tests/nrf/nrf5340_net_only.hex

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)