Search code examples
gccarmembeddedbootloadercortex-m

gcc start address


I am currently trying to compile a mbed project offline using gcc-arm-embedded but I want to change the start address as this program is intended to be used with a bootloader so will eventually have to run from 0x10000. I have exported my project as a GCC-ARM-EMBEDDED and am able to build the project with gcc. However I have no idea how to specify the start adress to 0x10000. I have tried to change the LPC1768.ld script, changing the ORIGIN of the FLASH to 0x10000, but it seems that it is not doing anything.

MEMORY
{
  FLASH (rx) : ORIGIN = 0x00010000, LENGTH = 0x70000
  RAM (rwx) : ORIGIN = 0x100000C8, LENGTH = 0x7F38

  USB_RAM(rwx) : ORIGIN = 0x2007C000, LENGTH = 16K
  ETH_RAM(rwx) : ORIGIN = 0x20080000, LENGTH = 16K
}

Is there an option in the Makefile or somewhere else that will help changing the start address of the program, so it can run correctly when I jump from my bootloader to adress 0x10000 ?

EDIT:

I think I understand what I need to achieve thanks to the couple of responses but for some reasons I can't get it working. Mbed does not export the startup_LPC17xx.s file so I tried to use the one from CMSIS, but no luck with that. I am wondering if I actually need to change the startup code as the process is as follow:

  • Bootloader runs at 0x0000
  • Bootloader will do some checks and eventually will run the user-app sitting at 0x10000. The bootloader actually moves the vector table before jumping to 0x10000. This user-app is the one I am trying to build with gcc and will not be running at power-up, only be running after the bootloader has started itself. Not sure if that's clear but I would think that only changing the Linker script would work... but it isn't.

Details of the Linker script where I have changed this section address to 0x10000:

SECTIONS {

.text : 
{
    *startup_LPC17xx.o 
    KEEP(*(.isr_vector))
    *(.text*)

    KEEP(*(.init))
    KEEP(*(.fini))

    /* .ctors */
    *crtbegin.o(.ctors)
    *crtbegin?.o(.ctors)
    *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
    *(SORT(.ctors.*))
    *(.ctors)

    /* .dtors */
    *crtbegin.o(.dtors)
    *crtbegin?.o(.dtors)
    *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
    *(SORT(.dtors.*))
    *(.dtors)

    *(.rodata*)

    KEEP(*(.eh_frame*))
} > FLASH

.ARM.extab : etc..

EDIT2: I have added *startup_LPC17xx.o in my script, this seems to be working fine now :)


Solution

  • In the linker file, specify a section that starts at 0x10000. Then in your crt0 or similar startup code, you need to define your reset entry handler as residing in this section so the linker will put it there. This could be via a .section or #pragma or similar mechanism. You can verify by looking at the linker's generated map file to see that it is placing your reset handler at 0x10000.