Reputation: 225
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:
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 :)
Upvotes: 0
Views: 4674
Reputation: 7691
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.
Check your Linker settings, whether you use the correct linker script. Changing the ORIGIN and size works here (LPC1768 with arm-none-eabi-gcc). Note that the resulting program will not execute on bare metal anymore, as the vector table will be at the wrong position: Your bootloader must be in place to start it.
Note that your bootloader must not jump to 0x10000
but load the reset vector from the table from 0x10004
into the PC. Bonus points when you load the MSP (Main Stack Pointer) from 0x10000
just before.
Upvotes: 0
Reputation: 11896
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.
Upvotes: 1