Code Relocation to ITCM on NXP RT1060 #78948
-
Hey, I am currently using zephyr_code_relocate() and CONFIG_CODE_DATA_RELOCATION to enhance system performance by relocating certain modules to run from ITCM. I typically load the code in two ways:
However, code relocation isn’t feasible in the second case due to ITCM being volatile memory. I assume this means I need to use a dedicated bootloader when loading the code via USB serial, whereas it's not necessary when using the debugger. Is there an example of compiling the code with such a bootloader that loads the required modules into ITCM before the application starts executing? Thank you for your assistance. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Hey @DerekSnell, I recently came across your discussion #75424 and found your comments on code relocation for specified project modules. I’m wondering how to achieve code relocation when loading via USB serial (using NXP-MCUBootUtility) instead of a debugger. You mentioned "configuring the bootloader"—is there any guidance or documentation on how to set this up? Best regards |
Beta Was this translation helpful? Give feedback.
-
Hi @ofirshe , The ROM bootloader does have a RAM Loader feature (and FYI, MCUboot also has a RAM Loader feature). The boot header for the image includes the RAM load address and the size to relocate. The bootloader will then copy that portion of the image from the IVT at the start of the image to the RAM load address. Then it will jump to the reset entry address in the vector table, and the app executes. There is a Kconfig symbol that makes this easy if The Zephyr Code And Data Relocation APIs can also help relocate code to RAM, especially if the whole app does not fit in the RAM, and you want to relocate parts of the app. With
That is not true, From experience I know that Best regards |
Beta Was this translation helpful? Give feedback.
-
Hi @ofirshe , For a reference, you can build the Zperf sample for the
Yes, as I shared before, the cause is because the CPU attempts to access the code or RODATA before the relocation function moves it to RAM. That will not work.
The app fails in the startup code. It never gets to Best regards |
Beta Was this translation helpful? Give feedback.
-
Hi @ofirshe I was referring to the internal SRAM, since you were asking about ITCM. But yes, you can execute the code from external SDRAM. Since SDRAM is quite large, you can use the ROM bootloader to load the entire Attached is a simple example SDRAM_hello_world.zip that moves the entire app to SDRAM, and uses the ROM bootloader to load the RAM at boot, before the app executes. This example was tested on the Some notes about this example: the devicetree overlay splits the SDRAM memory into two regions:
Then the entire app is placed in SDRAM:
The board .conf file configures the ROM bootloader to load the image to RAM at boot:
The LMA is adjusted in the app's Kconfig file. The linker builds the code/rodata for SDRAM at base address 0x8000_0000, but stores in FlexSPI flash at base address 0x1800_0000. So the LMA adjustment is +0x9800_0000.
Best regards |
Beta Was this translation helpful? Give feedback.
Hi @ofirshe ,
To summarize the i.MX RT boot flow when any code is located in RAM, the code must be stored in non-volatile memory, like the FlexSPI flash. The bootloader in ROM will read from the boot memory, configure the SOC and memory, read the boot header stored in that memory to get details about the boot image, and jump to the reset entry function. The relocation to RAM can be done by the bootloader before the app executes, or the app can relocate code to RAM before the app executes that code. Regardless of the method that programs the boot image in the memory, including the USB Serial Download mode you are using, this code will need to be relocated after POR. The debugger gets aroun…