在MCU闪存中保留16K扇区,并在特定地址添加链接描述文件

问题描述 投票:1回答:1

我正在使用gnu工具链(9.2.1)为STM32F429创建一个引导程序,并尝试为引导程序和应用程序共享的用户数据保留一些闪存。我想为其保留前四个16K闪存扇区中的第二个,因为它们很小巧:所有其他扇区均为128K。内存布局应如下所示:

ISR vector table : 0x08000000 (428 bytes)
padding          : 0x080001ac (15956 bytes)
-----------------------------
user data        : 0x08004000 (16K)
-----------------------------
bootloader code  : 0x08008000 (max 224K, for total of max. 256K)

我修改了ST的linker script看起来像这样:

/* Specify the memory areas */
MEMORY
{
    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 256K /* max. bootloader binary size */
    CCMRAM (rw)     : ORIGIN = 0x10000000, LENGTH = 64K
    RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 191K /* deduct 1K for NOINIT data */
    NOINIT (rwx)    : ORIGIN = 0x2002FC00, LENGTH = 1K /* NOINIT data will survive reset */
}

/* Define output sections */
SECTIONS
{
    /* The startup code goes first into FLASH */
    .isr_vector :
    {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
    } >FLASH

    /* Then comes user flash sector, make sure to get one of the first 4 that are 16K in size
    .user_flash :
    {
      . = ALIGN(0x4000)
      KEEP(*(.user_flash))
      . = ALIGN(0x4000)
    } >FLASH

    /* ... more sections below not shown here */
}

在我的bootloader.cpp中,我声明用户闪存如下:

__attribute__((__section__(".user_flash"))) const uint32_t user_flash[0x4000 / sizeof(uint32_t)] = {0};

但是,在调试器中,user_flash的地址不是预期的0x08004000,而是0x0801b4e8

从声明中删除__attribute__((__section__(".user_flash")))会产生不同的地址,证明该属性至少具有some效果。

。elf文件上的arm-non-eabi-objdump -h运行确认user_flash节的(不正确)地址。我也尝试用. = 0x08004000声明该部分,但无效。

[我尝试的另一种方法是将.isr_vector放在其自己的16K部分中,然后是用于用户闪存的16K部分,最后是(256-16-16)= 224K FLASH部分。这产生了伪造的二进制文件,该二进制文件将进行硬故障。

我在这里做错了什么?

编辑:

我已经tried.padding之后插入.isr_vector部分以尝试以这种方式对齐.user_flash,但是无论我做什么,.text.rodata部分似乎总是在[ C0],即使它们在.padding部分之后声明。

arm embedded bootloader stm32f4 linker-scripts
1个回答
1
投票
.user_flash
© www.soinside.com 2019 - 2024. All rights reserved.