gccarmldcortex-a8

How do i ensure the entry function at a fixed address of bare-metal arm?


I'm using S5PV210, a sumsung arm-cortexA8 chip. In its document, the program will start to execute at 0xd0200010. Now i succeeded run my program on it. But i still have some questions.

At first, I used link command "-Ttext 0xd02000010 -e main" , and thought that it will put the main function to address 0xd0200010. But i found that it just put .text section onto 0xd0200010. If i changed the order of function in my .c file, even though .text section will still be put on the 0xd0200010,but main function won't be on that address, and "-e main" doesn't work at all.

So , how could i make main function to be at 0xd0200010? Can i do it just by compiler and linker command?


Solution

  • I worked it out..

    elf file is used for OS platform, then entry point is defined is the header of elf file.

    But for bare-metal system, it can't read the information of elf file, so it must be transformed into binary file, which doesn't contain any information about entry point.In other words, bare-metal system doesn't have concept of "entry point". So -e main option won't work for binary file.

    There are many ways to place a C function on a fixed address.I just post my solution about it

    1. declare main function at a user-defined section

      int main() attribute((section(".main")))

    2. Use linker script, put the section .main on required address.

      SECTIONS { .=0x0000 .text : { led.o (.main) *(.text) } ........ }