I want to run code in RAM and use initialize copy by
directives.
My .icf
file is as follows:
define symbol __ICFEDIT_intvec_start__ = 0x08000000;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x080007ff;
define symbol __ICFEDIT_region_ROM1_start__ = 0x08070000;
define symbol __ICFEDIT_region_ROM1_end__ = 0x0807FFFF;
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x2000FFFF;
define symbol __ICFEDIT_size_cstack__ = 0x600;
define symbol __ICFEDIT_size_heap__ = 0x00;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x600;
define symbol __ICFEDIT_size_heap__ = 0x00;
/**** End of ICF editor section. ###ICF###*/
define memory mem with size = 4G;
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
define region ROM1_region = mem:[from __ICFEDIT_region_ROM1_start__ to __ICFEDIT_region_ROM1_end__];
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
do not initialize { section .noinit };
initialize by copy {readwrite};
initialize by copy {
object gd32f403_it.o,
object gd32f403_exti.o,
object gd32f403_fmc.o,
object gd32f403_gpio.o,
object gd32f403_misc.o,
object gd32f403_pmu.o,
object gd32f403_rcu.o,
object gd32f403_timer.o,
object gd32f403_usart.o,
object usb_delay.o,
object iap_core.o,
object usb_core.o,
object usbd_core.o,
object usbd_int.o,
object usbd_std.o,
object app.o ,
};
place in ROM_region {
readonly object system_gd32f403.o,
};
place in ROM1_region {
readonly object app.o ,
readonly object usb_delay.o,
readonly object iap_core.o,
readonly object gd32f403_it.o,
readonly object gd32f403_exti.o,
readonly object gd32f403_fmc.o,
readonly object gd32f403_gpio.o,
readonly object gd32f403_misc.o,
readonly object gd32f403_pmu.o,
readonly object gd32f403_rcu.o,
readonly object gd32f403_timer.o,
readonly object gd32f403_usart.o,
readonly object usb_core.o,
readonly object usbd_core.o,
readonly object usbd_int.o,
readonly object usbd_std.o,
readonly,
};
place in RAM_region {
readwrite,
block CSTACK, block HEAP,
};
export symbol __ICFEDIT_region_RAM_start__;
export symbol __ICFEDIT_region_RAM_end__;
But only gd32f403_gpio.o
and gd32f403_misc.o
execute in RAM and other objects still run in FLASH as shown in output .map
files:
"P3", part 1 of 3: 0x54c
P3-1 0x20000000 0x54c <Init block>
...
.rodata inited 0x20000000 0x40 app.o [1]
.rodata inited 0x20000040 0x44 app.o [1]
.rodata inited 0x20000130 0x8 gd32f403_rcu.o [1]
.rodata inited 0x20000138 0x14 iap_core.o [1]
.rodata inited 0x2000014c 0x4 iap_core.o [1]
.text inited 0x20000150 0xc6 gd32f403_gpio.o [1]
.text inited 0x20000218 0xd0 gd32f403_misc.o [1]
.data inited 0x200002e8 0x120 app.o [1]
.data inited 0x20000408 0x30 iap_core.o [1]
.data inited 0x20000504 0x48 xfiles.o [3]
...
- 0x2000054c 0x54c
Why other objects such as app.o
, gd32f403_usart.o
have not been copied into RAM to execute?
Please!
What should I do if I want achieve the goal that copy code to RAM described in .icf
file?
Sections that are needed for initialization are not affected by the initialize by copy directive. This includes the __low_level_initfunction and anything it references.
Anything reachable from the programentry label is considered needed for initialization unless reached via a section fragment with a label starting with __iar_init$$done.