Commit aaefaad8 authored by Carles Cufi's avatar Carles Cufi Committed by Benjamin Cabé
Browse files

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: default avatarCarles Cufi <carles.cufi@nordicsemi.no>
parent bb6cb0f1
Loading
Loading
Loading
Loading
+21 −89
Changes for scripts/west_commands/runners/nrf_common.py: 21 added lines, 89 removed lines.
Original line number Diff line number Diff line
@@ -295,31 +295,37 @@ class NrfBinaryRunner(ZephyrBinaryRunner):

        self.exec_op('recover')

    def _get_core(self):
        if self.family in ('nrf54h', 'nrf92'):
            if (self.build_conf.getboolean('CONFIG_SOC_NRF54H20_CPUAPP') or
                self.build_conf.getboolean('CONFIG_SOC_NRF9280_CPUAPP')):
                return 'Application'
            if (self.build_conf.getboolean('CONFIG_SOC_NRF54H20_CPURAD') or
                self.build_conf.getboolean('CONFIG_SOC_NRF9280_CPURAD')):
                return 'Network'
            raise RuntimeError(f'Core not found for family: {self.family}')

        if self.family in ('nrf53'):
            if self.build_conf.getboolean('CONFIG_SOC_NRF5340_CPUAPP'):
                return 'Application'
            if self.build_conf.getboolean('CONFIG_SOC_NRF5340_CPUNET'):
                return 'Network'
            raise RuntimeError(f'Core not found for family: {self.family}')

        return None

    def program_hex(self):
        # Get the command use to actually program self.hex_.
        self.logger.info(f'Flashing file: {self.hex_}')

        # What type of erase/core arguments should we pass to the tool?
        core = None
        core = self._get_core()

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

            cpuapp = (
                self.build_conf.getboolean('CONFIG_SOC_NRF54H20_CPUAPP') or
                self.build_conf.getboolean('CONFIG_SOC_NRF9280_CPUAPP')
            )
            cpurad = (
                self.build_conf.getboolean('CONFIG_SOC_NRF54H20_CPURAD') or
                self.build_conf.getboolean('CONFIG_SOC_NRF9280_CPURAD')
            )
            generated_uicr = self.build_conf.getboolean('CONFIG_NRF_REGTOOL_GENERATE_UICR')

            if cpuapp:
                core = 'Application'
            elif cpurad:
                core = 'Network'

            if generated_uicr and not self.hex_get_uicrs().get(core):
                raise RuntimeError(
                    f"Expected a UICR to be contained in: {self.hex_}\n"
@@ -367,7 +373,7 @@ class NrfBinaryRunner(ZephyrBinaryRunner):
                # Handle SUIT root manifest if application manifests are not used.
                # If an application firmware is built, the root envelope is merged
                # with other application manifests as well as the output HEX file.
                if not cpuapp and self.sysbuild_conf.get('SB_CONFIG_SUIT_ENVELOPE'):
                if core != 'Application' and self.sysbuild_conf.get('SB_CONFIG_SUIT_ENVELOPE'):
                    app_root_envelope_hex_file = os.fspath(
                        mpi_hex_dir / 'suit_installed_envelopes_application_merged.hex'
                    )
@@ -399,83 +405,9 @@ class NrfBinaryRunner(ZephyrBinaryRunner):
            if self.hex_refers_region(xip_start, xip_end):
                ext_mem_erase_opt = 'ERASE_ALL'

        # What tool commands do we need to flash this target?
        if self.family == 'nrf53':
            # nRF53 requires special treatment due to the extra coprocessor.
            self.program_hex_nrf53(erase_arg, ext_mem_erase_opt)
        else:
        self.op_program(self.hex_, erase_arg, ext_mem_erase_opt, defer=True, core=core)

        self.flush(force=False)

    def program_hex_nrf53(self, erase_arg, ext_mem_erase_opt):
        # program_hex() helper for nRF53.

        # *********************** NOTE *******************************
        # self.hex_ can contain code for both the application core and
        # the network core.
        #
        # We can't assume, for example, that
        # CONFIG_SOC_NRF5340_CPUAPP=y means self.hex_ only contains
        # data for the app core's flash: the user can put arbitrary
        # addresses into one of the files in HEX_FILES_TO_MERGE.
        #
        # Therefore, on this family, we may need to generate two new
        # hex files, one for each core, and flash them individually
        # with the correct '--coprocessor' arguments.
        #
        # Kind of hacky, but it works, and the tools are not capable of
        # flashing to both cores at once. If self.hex_ only affects
        # one core's flash, then we skip the extra work to save time.
        # ************************************************************

        # Address range of the network coprocessor's flash. From nRF5340 OPS.
        # We should get this from DTS instead if multiple values are possible,
        # but this is fine for now.
        net_flash_start = 0x01000000
        net_flash_end   = 0x0103FFFF

        # If there is nothing in the hex file for the network core,
        # only the application core is programmed.
        if not self.hex_refers_region(net_flash_start, net_flash_end):
            self.op_program(self.hex_, erase_arg, ext_mem_erase_opt, defer=True,
                            core='Application')
        # If there is some content that addresses a region beyond the network
        # core flash range, two hex files are generated and the two cores
        # are programmed one by one.
        elif self.hex_contents.minaddr() < net_flash_start or \
             self.hex_contents.maxaddr() > net_flash_end:

            net_hex, app_hex = IntelHex(), IntelHex()
            for start, end in self.hex_contents.segments():
                if net_flash_start <= start <= net_flash_end:
                    net_hex.merge(self.hex_contents[start:end])
                else:
                    app_hex.merge(self.hex_contents[start:end])

            hex_path = Path(self.hex_)
            hex_dir, hex_name = hex_path.parent, hex_path.name

            net_hex_file = os.fspath(
                hex_dir / f'GENERATED_CP_NETWORK_{hex_name}')
            app_hex_file = os.fspath(
                hex_dir / f'GENERATED_CP_APPLICATION_{hex_name}')

            self.logger.info(
                f'{self.hex_} targets both nRF53 coprocessors; '
                f'splitting it into: {net_hex_file} and {app_hex_file}')

            net_hex.write_hex_file(net_hex_file)
            app_hex.write_hex_file(app_hex_file)

            self.op_program(net_hex_file, erase_arg, None, defer=True,
                            core='Network')
            self.op_program(app_hex_file, erase_arg, ext_mem_erase_opt, defer=True,
                            core='Application')
        # Otherwise, only the network core is programmed.
        else:
            self.op_program(self.hex_, erase_arg, None, defer=True,
                            core='Network')

    def reset_target(self):
        if self.family == 'nrf52' and not self.softreset:
+0 −1
Changes for scripts/west_commands/tests/nrf/README.rst: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
This directory contains test data files for test_nrf.py.
+0 −5
Changes for scripts/west_commands/tests/nrf/nrf5340_app_and_net.hex: 0 added lines, 5 removed lines.
Original line number Diff line number Diff line
:020000040000FA
:0100000001FE
:020000040100F9
:0100000001FE
:00000001FF
+0 −2
Changes for scripts/west_commands/tests/nrf/nrf5340_app_only.hex: 0 added lines, 2 removed lines.
Original line number Diff line number Diff line
:0100000001FE
:00000001FF
+0 −3
Changes for scripts/west_commands/tests/nrf/nrf5340_net_only.hex: 0 added lines, 3 removed lines.
Original line number Diff line number Diff line
:020000040100F9
:0100000001FE
:00000001FF
Loading