|
| 1 | +.. _idle_relocated_tcm_sample: |
| 2 | + |
| 3 | +Multicore idle test with firmware relocated to radio core TCM |
| 4 | +############################################################# |
| 5 | + |
| 6 | +.. contents:: |
| 7 | + :local: |
| 8 | + :depth: 2 |
| 9 | + |
| 10 | +The test benchmarks the idle behavior of an application that runs on multiple cores. |
| 11 | +It demonstrates a radio loader pattern where the radio core firmware is loaded from MRAM into TCM (Tightly Coupled Memory) at runtime. |
| 12 | + |
| 13 | +Requirements |
| 14 | +************ |
| 15 | + |
| 16 | +The test supports the following development kit: |
| 17 | + |
| 18 | +.. table-from-rows:: /includes/sample_board_rows.txt |
| 19 | + :header: heading |
| 20 | + :rows: nrf54h20dk_nrf54h20_cpuapp |
| 21 | + |
| 22 | +Overview |
| 23 | +******** |
| 24 | + |
| 25 | +This test demonstrates how to build a multicore idle application with :ref:`configuration_system_overview_sysbuild` using a two-stage boot process for the radio core: |
| 26 | + |
| 27 | +* Radio Loader - A small bootloader that runs on the radio core, copies firmware from MRAM to TCM, and jumps to it. |
| 28 | +* Remote Firmware - The actual application that runs from TCM after being loaded. |
| 29 | + |
| 30 | +The test automatically relocates the remote firmware binary to the correct MRAM address during build time, ensuring it can be loaded by the radio loader. |
| 31 | + |
| 32 | +Architecture |
| 33 | +============ |
| 34 | + |
| 35 | +The system uses the following memory layout: |
| 36 | + |
| 37 | +* **MRAM (Non-volatile):** |
| 38 | + |
| 39 | + * ``cpurad_loader_partition`` @ 0x92000 - Contains the radio loader (8 KB) |
| 40 | + * ``cpurad_loaded_fw`` @ 0x94000 - Contains the remote firmware binary (128 KB) |
| 41 | + |
| 42 | +* **TCM (Volatile, fast execution):** |
| 43 | + |
| 44 | + * ``cpurad_ram0`` @ 0x23000000 - Code execution region (128 KB) |
| 45 | + * ``cpurad_data_ram`` @ 0x23020000 - Data region (64 KB) |
| 46 | + |
| 47 | +Additional files |
| 48 | +================ |
| 49 | + |
| 50 | +The test comes with the following additional files: |
| 51 | + |
| 52 | +* :file:`sysbuild.conf` - Enables the radio loader by setting ``CONFIG_NRF_RADIO_LOADER=y``. |
| 53 | +* :file:`boards/memory_map.overlay` - Shared memory map configuration for both loader and remote firmware. |
| 54 | +* :file:`sysbuild/radio_loader/` - Radio loader configuration overrides (:file:`prj.conf`, overlay). |
| 55 | +* :file:`sysbuild/remote_rad/` - Radio core firmware configuration overrides (:file:`prj.conf`, overlay). |
| 56 | + |
| 57 | +Enabling the Radio Loader |
| 58 | +************************* |
| 59 | + |
| 60 | +The radio loader is automatically added to the build when you enable it in sysbuild configuration. |
| 61 | + |
| 62 | +In :file:`sysbuild.conf`: |
| 63 | + |
| 64 | +.. code-block:: kconfig |
| 65 | +
|
| 66 | + SB_CONFIG_NRF_RADIO_LOADER=y |
| 67 | +
|
| 68 | +This single configuration option: |
| 69 | + |
| 70 | +#. Automatically adds the ``radio_loader`` application located in the :file:`nrf/samples/nrf54h20/radio_loader` folder. |
| 71 | +#. Builds it for the CPURAD core. |
| 72 | +#. No manual ``ExternalZephyrProject_Add()`` needed in sysbuild. |
| 73 | + |
| 74 | +Memory map configuration |
| 75 | +======================== |
| 76 | + |
| 77 | +The memory map is defined in :file:`boards/memory_map.overlay` and is shared between the radio loader and remote firmware to ensure consistency. |
| 78 | + |
| 79 | +The overlay defines: |
| 80 | + |
| 81 | +#. TCM regions: |
| 82 | + |
| 83 | + .. code-block:: devicetree |
| 84 | +
|
| 85 | + cpurad_ram0: sram@23000000 { |
| 86 | + compatible = "mmio-sram"; |
| 87 | + reg = <0x23000000 0x20000>; /* 128 KB for code */ |
| 88 | + }; |
| 89 | + cpurad_data_ram: sram@23020000 { |
| 90 | + compatible = "mmio-sram"; |
| 91 | + reg = <0x23020000 0x10000>; /* 64 KB for data */ |
| 92 | + }; |
| 93 | +
|
| 94 | +#. MRAM partitions: |
| 95 | + |
| 96 | + .. code-block:: devicetree |
| 97 | +
|
| 98 | + &mram1x { |
| 99 | + /delete-node/ partitions; |
| 100 | +
|
| 101 | + partitions { |
| 102 | + compatible = "fixed-partitions"; |
| 103 | + #address-cells = <1>; |
| 104 | + #size-cells = <1>; |
| 105 | +
|
| 106 | + cpurad_loader_partition: partition@92000 { |
| 107 | + label = "cpurad_loader_partition"; |
| 108 | + reg = <0x92000 DT_SIZE_K(8)>; /* 8 KB allocated (~4 KB actual) */ |
| 109 | + }; |
| 110 | +
|
| 111 | + cpurad_loaded_fw: partition@94000 { |
| 112 | + label = "cpurad_loaded_fw"; |
| 113 | + reg = <0x94000 DT_SIZE_K(128)>; /* 128 KB fixed */ |
| 114 | + }; |
| 115 | + }; |
| 116 | + }; |
| 117 | +
|
| 118 | +Automatic firmware relocation |
| 119 | +***************************** |
| 120 | + |
| 121 | +The remote firmware must be relocated to match the MRAM partition address where it will be stored. |
| 122 | +This is automatically done by Zephyr's ``CONFIG_BUILD_OUTPUT_ADJUST_LMA`` feature when the devicetree chosen nodes are configured correctly. |
| 123 | + |
| 124 | +How it works |
| 125 | +============ |
| 126 | + |
| 127 | +Firmware relocation is handled automatically by Zephyr's build system using the ``CONFIG_BUILD_OUTPUT_ADJUST_LMA`` configuration option, which is configured in ``zephyr/soc/nordic/nrf54h/Kconfig.defconfig.nrf54h20_cpurad`` for all nRF54H20 CPURAD projects. |
| 128 | + |
| 129 | +The configuration automatically detects the ``fw-to-relocate`` chosen node in your devicetree. |
| 130 | +When present, it calculates the LMA adjustment to relocate firmware from MRAM to TCM. |
| 131 | +Without this chosen node, firmware runs directly from the ``zephyr,code-partition`` location (standard XIP behavior). |
| 132 | + |
| 133 | +Simply configure the devicetree chosen nodes correctly in your firmware's overlay: |
| 134 | + |
| 135 | +.. code-block:: devicetree |
| 136 | +
|
| 137 | + /{ |
| 138 | + chosen { |
| 139 | + /* VMA: where code runs (TCM) */ |
| 140 | + zephyr,code-partition = &cpurad_ram0; |
| 141 | + zephyr,sram = &cpurad_data_ram; |
| 142 | +
|
| 143 | + /* LMA: where to load from (MRAM partition) - enables relocation */ |
| 144 | + fw-to-relocate = &cpurad_loaded_fw; |
| 145 | + }; |
| 146 | + }; |
| 147 | +
|
| 148 | +Zephyr automatically calculates the Load Memory Address (LMA) adjustment based on your chosen nodes: |
| 149 | + |
| 150 | +**With fw-to-relocate chosen node** (for radio loader pattern): |
| 151 | + |
| 152 | +.. code-block:: text |
| 153 | +
|
| 154 | + LMA_adjustment = fw-to-relocate address - zephyr,code-partition address |
| 155 | + = cpurad_loaded_fw - cpurad_ram0 |
| 156 | + = 0x94000 - 0x23000000 |
| 157 | +
|
| 158 | +**Without fw-to-relocate** (standard behavior): |
| 159 | + |
| 160 | +.. code-block:: text |
| 161 | +
|
| 162 | + LMA_adjustment = zephyr,code-partition address - zephyr,sram address |
| 163 | +
|
| 164 | +The build system then adjusts the hex file so that the firmware is loaded from MRAM (``0x94000``), but runs from TCM (``0x23000000``). |
| 165 | + |
| 166 | +Building and running |
| 167 | +******************** |
| 168 | + |
| 169 | +.. |test path| replace:: :file:`samples/nrf54h20/idle_relocated_tcm` |
| 170 | + |
| 171 | +.. include:: /includes/build_and_run_test.txt |
| 172 | + |
| 173 | +Testing |
| 174 | +======= |
| 175 | + |
| 176 | +After programming the test to your development kit, complete the following steps to test it: |
| 177 | + |
| 178 | +1. |connect_terminal| |
| 179 | +#. Reset the kit. |
| 180 | +#. Observe the console output for both cores: |
| 181 | + |
| 182 | + * For the application core, the output should be as follows: |
| 183 | + |
| 184 | + .. code-block:: console |
| 185 | +
|
| 186 | + *** Booting nRF Connect SDK zephyr-v3.5.0-3517-g9458a1aaf744 *** |
| 187 | + build time: Nov 22 2025 17:00:59 |
| 188 | + Multicore idle test on [email protected]/nrf54h20/cpuapp |
| 189 | + Multicore idle test iteration 0 |
| 190 | + Multicore idle test iteration 1 |
| 191 | + ... |
| 192 | +
|
| 193 | + * For the radio core, the output should be as follows: |
| 194 | + |
| 195 | + .. code-block:: console |
| 196 | +
|
| 197 | + *** Booting nRF Connect SDK zephyr-v3.5.0-3517-g9458a1aaf744 *** |
| 198 | + build time: Nov 22 2025 17:00:29 |
| 199 | + Multicore idle test on [email protected]/nrf54h20/cpurad |
| 200 | + Current PC (program counter) address: 0x23000ae0 |
| 201 | + Multicore idle test iteration 0 |
| 202 | + Multicore idle test iteration 1 |
| 203 | + ... |
| 204 | +
|
| 205 | + The radio loader first loads the firmware from MRAM (``0x0e094000``) to TCM (``0x23000000``) and then jumps to the loaded firmware. |
| 206 | + This process is transparent and happens during the early boot stage. |
| 207 | + |
| 208 | +#. Verify the DFU process: |
| 209 | + |
| 210 | + #. Build the firmware for the secondary app slot, increase the version number in the :file:`prj.conf` file (uncomment the line): |
| 211 | + |
| 212 | + .. code-block:: kconfig |
| 213 | +
|
| 214 | + CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION="0.0.1+0" |
| 215 | +
|
| 216 | + #. Build the firmware: |
| 217 | + |
| 218 | + .. code-block:: console |
| 219 | +
|
| 220 | + west build -p -b nrf54h20dk/nrf54h20/cpuapp |
| 221 | +
|
| 222 | + #. Program the firmware to the secondary application slot: |
| 223 | + |
| 224 | + .. code-block:: console |
| 225 | +
|
| 226 | + nrfutil device program --firmware build/zephyr_secondary_app.merged.hex --options chip_erase_mode=ERASE_NONE |
| 227 | +
|
| 228 | + Reset the development kit. |
| 229 | + The firmware must boot from the secondary application slot. |
| 230 | + Observe the change in build time in the console output. |
0 commit comments