AnsweredAssumed Answered

Non-XIP Boot to SDRAM with GCC (elftosb and GCC linker script)

Question asked by Nikolaos Chatzinikolaou on Apr 17, 2018
Latest reply on Apr 18, 2018 by Nikolaos Chatzinikolaou

Hello,

 

I have adapted the instructions in AN12107 & AN12108 to boot my RT1050-EVK from hyperflash to SDRAM (non-XIP) using GCC/CMake rather than IAR. Everything works fine except one thing: elftosb seems to ignore my .data section, so my globals don't get initialised.

 

Here's what I've done:

 

Using hello_world as a base, I've added a global variable foo, which I initialise to a value upon declaration, and then printf it in main.

 

I've modified MIMXRT1052xxxxx_flexspi_nor.ld as follows:


  m_interrupts          (RX)  : ORIGIN = 0x80002000, LENGTH = 0x00000400
  m_text                (RX)  : ORIGIN = 0x80002400, LENGTH = 0x00020000
  m_data                (RW)  : ORIGIN = 0x81000000, LENGTH = 0x00020000

 

Building and running readelf -S shows the .data section, as expected:

 

  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .interrupts       PROGBITS        80002000 002000 000400 00   A  0   0  4
  [ 2] .text             PROGBITS        80002400 002400 002e30 00  AX  0   0  4
  [ 3] .ARM              ARM_EXIDX       80005230 005230 000008 00  AL  2   0  4
  [ 4] .init_array       INIT_ARRAY      80005238 005238 000004 04  WA  0   0  4
  [ 5] .fini_array       FINI_ARRAY      8000523c 00523c 000004 04  WA  0   0  4
  [ 6] .data             PROGBITS        81000000 010000 000074 00  WA  0   0  4
  [ 7] .ncache.init      PROGBITS        81000074 010074 000000 00   W  0   0  1
  [ 8] .ncache           PROGBITS        81000074 010074 000000 00   W  0   0  1
  [ 9] .bss              NOBITS          81000074 010074 000054 00  WA  0   0  4
  [10] .heap             NOBITS          810000c8 010074 000400 00  WA  0   0  1
  [11] .stack            NOBITS          810004c8 010074 000400 00  WA  0   0  1

 

Indeed, checking the .elf at offset 010000, I can see the initial value of foo.

 

The command I use to generate the sb is:

 

elftosb.exe -d -f imx -V -c ../../bd_file/imx10xx/imx-sdram-unsigned-dcd.bd -o imx.bin F:\hello_world.elf

 

And its output:

 

positional args:
0: F:\hello_world.elf
source elfFile => extern(0=F:\hello_world.elf)
        Section: 0x0
filtering sections of file: F:\hello_world.elf
creating segment for section .interrupts
creating segment for section .text
creating segment for section .init_array
creating segment for section .fini_array
Entry point is Reset_Handler@0x800024e1 (ARM)
iMX bootable image generated successfully

 

As can be seen, the .data section doesn't get picked up. At this point (before even generating boot_image.sb), I can confirm that imx.bin lacks the initial values in .data. The const values in .text are retained.

 

When running the code, I can confirm that main is executing from 0x80002400+, my foo variable is at 0x81000000, and any const variable values (which work fine) are after the code. The startup code's copy-loop fills up foo with whatever is after .fini_array (at __etext), which is, of course, rubbish.

 

Any clues why this happens?

 

Thanks in advance,

 

Nikos

Outcomes