.ncache.init section splits .bss from .heap and .stack

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

.ncache.init section splits .bss from .heap and .stack

492 次查看
MulattoKid
Contributor III

Hi,

When following the eDMA example in the SDK for i.MX RT1040 it uses the macro AT_NONCACHEABLE_SECTION_INIT to put an array into a specific section, .ncache.init.

However, when this is done, the .bss section is split from the .heap and .stack sections. Before it looked like this

Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x010000 0x60010000 0x60010000 0x00100 0x00100 RW 0x10000
LOAD 0x010100 0x60010100 0x60010100 0x00400 0x00400 R 0x10000
LOAD 0x010500 0x60010500 0x60010500 0x0ad70 0x0ad70 RWE 0x10000
LOAD 0x020000 0x20000000 0x6001b270 0x000a0 0x03a58 RW 0x10000

Section to Segment mapping:
Segment Sections...
00 .image_header
01 .interrupts
02 .text .ARM .init_array .fini_array
03 .data .ram_function .bss .heap .stack

and now after it looks like this

Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x010000 0x60010000 0x60010000 0x00100 0x00100 RW 0x10000
LOAD 0x010100 0x60010100 0x60010100 0x00400 0x00400 R 0x10000
LOAD 0x010500 0x60010500 0x60010500 0x0ad70 0x0ad70 RWE 0x10000
LOAD 0x020000 0x20000000 0x6001b270 0x000a0 0x02a58 RW 0x10000
LOAD 0x030000 0x20200000 0x6001b370 0x00800 0x00800 RW 0x10000
LOAD 0x002a58 0x20002a58 0x6001dcc8 0x00000 0x00800 RW 0x10000

Section to Segment mapping:
Segment Sections...
00 .image_header
01 .interrupts
02 .text .ARM .init_array .fini_array
03 .data .ram_function .bss
04 .ncache.init
05 .heap .stack

This causes an issue with our bootloader's FW image integrity check, as .bss now becomes a part of the output binary, but isn't flashed when using the Cortex-Debug extension in VSCode, resulting in the binary the hash is computed on containing all 0x00 for the .bss section, while in flash the same memory region is 0xFF (erased).

Is there a way to force .bss to be in the last program header along with .heap and .stack? For reference, the linker script file is a slightly modified version of the one used for all examples with the RT1040, but the parts regarding .bss etc. are unmodified (see attached file).

0 项奖励
回复
2 回复数

400 次查看
MulattoKid
Contributor III

Hi @Omar_Anguiano,

Well, all the relevant sections (.data, .ram_function, .bss, .ncache.init, .heap and .stack) are placed in RAM. The issue is that .bss, .heap and .stack are uninitialized, so when .bss suddenly ends up in the same program header as e.g. .data, the zero-bytes the .bss section contains are included in the binary, but isn't flashed when flashing using the Cortex-Debug extension in VSCode. This causes a mismatch in the hashes between the flashed and non-flashed images.

I've tried moving stuff around in the linker file, but I've not been able to find a way to make .bss end up in the last program header, as it was when .ncache.init wasn't used. I attached it above, but this is what that part of the linker file looks like (should be identical to the linker files in the examples for the i.MX RT1040 EVK):

 

.data : AT(__DATA_ROM)
{
  . = ALIGN(4);
  __DATA_RAM = .;
  __data_start__ = .;      /* create a global symbol at data start */
  *(m_usb_dma_init_data)

  /* Explicitly place flash operation functions in RAM. */
  */mflash_drv.c.obj(.text .text* .rodata .rodata*)
  */fsl_flexspi.c.obj(.text .text* .rodata .rodata*)
  */fsl_cache.c.obj(.text .text* .rodata .rodata*)

  *(.data)                 /* .data sections */
  *(.data*)                /* .data* sections */
  *(DataQuickAccess)       /* quick access data section */
  KEEP(*(.jcr*))
  . = ALIGN(4);
  __data_end__ = .;        /* define a global symbol at data end */
} > m_data

__ram_function_flash_start = __DATA_ROM + (__data_end__ - __data_start__); /* Symbol is used by startup for TCM data initialization */

.ram_function : AT(__ram_function_flash_start)
{
  . = ALIGN(32);
  __ram_function_start__ = .;
  *(CodeQuickAccess)
  . = ALIGN(128);
  __ram_function_end__ = .;
} > m_data

__NDATA_ROM = __ram_function_flash_start + (__ram_function_end__ - __ram_function_start__);
.ncache.init : AT(__NDATA_ROM)
{
  __noncachedata_start__ = .;   /* create a global symbol at ncache data start */
  *(NonCacheable.init)
  . = ALIGN(4);
  __noncachedata_init_end__ = .;   /* create a global symbol at initialized ncache data end */
} > m_ncache
. = __noncachedata_init_end__;
.ncache :
{
  *(NonCacheable)
  . = ALIGN(4);
  __noncachedata_end__ = .;     /* define a global symbol at ncache data end */
} > m_ncache

__DATA_END = __NDATA_ROM + (__noncachedata_init_end__ - __noncachedata_start__);
text_end = ORIGIN(m_text) + LENGTH(m_text);
ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data")

/* Uninitialized data section */
.bss :
{
  /* This is used by the startup in order to initialize the .bss section */
  . = ALIGN(4);
  __START_BSS = .;
  __bss_start__ = .;
  *(m_usb_dma_noninit_data)
  *(.bss)
  *(.bss*)
  *(COMMON)
  . = ALIGN(4);
  __bss_end__ = .;
  __END_BSS = .;
} > m_data

.heap :
{
  . = ALIGN(8);
  __end__ = .;
  PROVIDE(end = .);
  __HeapBase = .;
  . += HEAP_SIZE;
  __HeapLimit = .;
  __heap_limit = .; /* Add for _sbrk */
} > m_data

.stack :
{
  . = ALIGN(8);
  . += STACK_SIZE;
} > m_data

 

0 项奖励
回复

409 次查看
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello
I hope you are well.

To place the bss directly as it was before you will have to manually edit the linker file and make sure it is placed at the RAM.

Best regards,
Omar

0 项奖励
回复