This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] AM2732: Placing code in the L3 memory region (0x8000_0000) triggers a prefetch abort exception in the application.

Part Number: AM2732
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

I can't place the code in L3 without the application failing before reaching the main() with a prefetch_abort error being thrown How do I fix this?

  • Problem:

    Trying to set the .text region in a memory location using SysConfig or the linker command file that is marked as "never-execute" in the R5 documentation will cause the core to reach a HwiP_prefetch_abort_handler() prior the application reaching the main() function. As an example, trying to place .text in memory region 0x8000_0000 would cause such error:

    The prefetch abort is caused by the core trying to fetch the first instruction from the entry point in the restricted memory region but at this point in time, said region is still not initialized in the application, causing the application to fall in the prefetch handler as it is not able to reach the main function. Even if the 0x8000_0000 space is being marked as executable in SysConfig, this is not enough to enable the region as the MPU configuration happens in the _c_int00 entry point rather than in the drivers called by SysConfig or SBL applications; trying to set the MPU at bootloader time would also fail as the bootloader resets the device at the end of execution, returning the MPU configuration to its defaults.

    Solution:

      

    The application will keep reaching the prefetch abort handler unless the MPU gets successfully configured before the application reaches its main function. To do so, the .text. sections that play part in MPU enablement must be moved to an executable location (any region not defined as "Execute Never" by default), for them to enable the MPU and then allow the device to reach the main. 

    The core fetches instructions from the ARM's initial boot, MPU, HwIP, and Cache routines. If any of the necessary functions is located in the non-executable region it will cause the core to fall in the prefetch abort handler. These functions are defined in .text. subregions (Check screenshots above) that are not by default defined in SysConfig but we can easily define them in order to place the necessary functions in an accessible region. Below are instructions on moving these initialization regions to an executable area in the core while still keeping the main code in the restricted region:

    1. In the R50-0 and/or R50-1 applications, open SysConfig and go to "Memory Configurator" and click on "Sections". You'll see the following: 

    2. Choose a memory location with execute permissions where you would like to place the MPU initialization functions. This location has to be defined as a "Memory Region" under SysConfig's "Memory Configurator" section

    3. Create new Output Sections located in the region defined in the previous step. They are 4 in total:

    These output sections must be named exactly like in the above screenshot; this is not optional as these are the names of the implicit subsections defined in the initialization routines 

    4. By doing the above, the MPU initialization will have successfully been placed in an executable region where instructions can be fetched from the entry point while keeping the rest of the code and text in L3 memory or any other non-executable-by-default region