IAR 链接器在初始化期间将代码从 FLASH 复制到 RAM

IAR linker copy code from FLASH to RAM during initialization

我想 运行 在 RAM 中编写代码并使用 initialize copy by 指令。

我的.icf文件如下:

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__;

但只有 gd32f403_gpio.ogd32f403_misc.o 在 RAM 中执行,其他对象仍在 运行 闪存中,如输出 .map 文件所示:

"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

为什么其他对象如app.ogd32f403_usart.o没有被复制到RAM中执行?

拜托!

如果我想达到.icf文件中的copy code to RAM的目的,我该怎么办?

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.