How can I get VMA and LMA for a section?
The easiest way to get the runtime address (VMA) and load time address (LMA) for a section, is to use the AT keyword at the end of the output section description and get the base and the end address of a section explicitly with the builtin function LOADADDR().
-
Specify two memory regions:
-
SECTION_MEM— Allocated for the.somesecsection. -
SECTION_FLASH_CODE_CACHED— Allocated for the copy of.somesecsection.MEMORY { SECTION_MEM : org = 0, len = 0x10000 SECTION_FLASH_CODE_CACHED : org = 0xd0000000, len = 0x10000 }
-
-
Define the
.somesecsection and locate it in the memory regionSECTION_MEMfor runtime. TheATkeyword sets the load address of the section toSECTION_FLASH_CODE_CACHED.SECTIONS { .somesec : { CODE_RAM_BASE_ADDRESS_PTR = .; /* output section commands */ CODE_RAM_END_ADDRESS_PTR = .; } >SECTION_MEM AT> SECTION_FLASH_CODE_CACHED _base_loc_code_rom = LOADADDR(.somesec); _end_loc_code_rom = LOADADDR(.somesec) + SIZEOF(.somesec); }During runtime, you can copy the
.somesecsection by using the symbolsCODE_RAM_BASE_ADDRESS_PTRfor the destination and_base_loc_code_romfor the source. The size of the copy can be calculated by_base_loc_code_rom - _end_loc_code_rom.CODE_RAM_BASE_ADDRESS_PTRgives the runtime address (VMA) and_base_loc_code_rom givesthe load time address (LMA).