7.2. Relocation of sections at runtime

7.2.1. Need / Problem Statament

Run time relocation of code and/or data could be employed for optimal utilization of fast memories.

Consider ExecuteInPlace (XIP) where in a secodary memory device would hold code and data and allows execute in place. Most of the external device would be slower compared to internal memory it would be benificial to place highly used code/data in the internal memory.

Situations where memories are not setup by boot loader
  • e.g. As in case of AM65xx device, the TCM’s contents are lost with reset of MCU R5.

    This renders TCM’s un-useable by applications.

7.2.2. Solution

To support run-time relocation of code/data would require 3 distinct steps

  1. Identification memory section that would be used for loading and section to run from
  2. Listing of code/data that would require to loaded and run/used from different locations
  3. Moving of sections from loaded area to run/used areas

Would rely on TI’s compilers copy table to implement #1 & #2 and copy in functions to implement #3. Refer for details Advanced Linker Techniques. on COPY TABLE and COPY IN

Consider the below for convience

  • MSMC3 - Memory location where .text and .data would be loaded by SBL
  • MCU0_ATCM_TXT_RUN_TIME_LOAD - Memory location where text section of the program would be executed from
  • MCU0_ATCM_DAT_RUN_TIME_LOAD - Memory location where data section of the program would be used from
  • TI RTOS/sysbios is deployed on Cotex R5F

7.2.3. #1 & #2 - Define Copy Table

Below list the section of linker command

Text Section:

.text_run_time_load : {
                *ti.csl*aer5f(.text)
             } palign(8) load = MSMC3,
                run = MCU0_ATCM_TXT_RUN_TIME_LOAD,
                table(_text_run_time_load_section)
  • _text_run_time_load_section - Defines copy table for text section
    • ti.csl aer5f(.text) - text segement of the object
    • MSMC3 - Location where code is loaded by SBL
    • MCU0_ATCM_TXT_RUN_TIME_LOAD - Location from it would be executed

Data Section:

.data_run_time_load : {
                *ti.drv*aer5f(.data)
             } palign(8) load = MSMC3,
                run = MCU0_ATCM_DAT_RUN_TIME_LOAD,
                table(_data_run_time_load_section)
  • _data_run_time_load_section - Defines copy table for data section
    • ti.drv aer5f(.data) - data segement of the object
    • MSMC3 - Location where data is loaded by SBL
    • MCU0_ATCM_DAT_RUN_TIME_LOAD - Location from it would accessed at runtime

Copy TABLE Section:

/* This is the region which will have all the copy tables */
.ovly       : {} palign(128) load = MSMC3
  • ovly is the section that would be host all the copy tables

7.2.4. #3 - Copy at run time

Before the text/data defined by these two tables are used, these requires to be moved from MSMC3 to MCU0_ATCM_TXT_RUN_TIME_LOAD or MCU0_ATCM_DAT_RUN_TIME_LOAD and this can be achived with compiler runtime-support function copy_in()

copy in example:

copy_in(&_text_run_time_load_section);
copy_in(&_data_run_time_load_section);

7.2.5. Example

The method described above is implemented for UDMA example

  • Linker Command File - Defined COPY TABLE - PDK_INSTALL_DIR/packages/ti/drv/udma/examples/udma_adc_test/build/am65xx/linker_r5_sysbios.lds
  • Example - Reference copy in useage - PDK_INSTALL_DIR/packages/ti/drv/udma/examples/udma_adc_test/main_tirtos.c