I have been trying to get the Arduino bootloader to compile into my firmware binary in Atmel Studio. I got the bootloader project to link and compile. I use ArduinoCore and the bootloader as a dependencies to my main code. The dependency tree looks like:
- ArduinoCore
- bootloader
- Main firmware
The Bootloader
It took me a bit to get the bootloader to accept the rest of ArduinoCore as a dependency but it compiles into a static library. I use the bootloader linker to specify the memory location of the bootloader binary. It should start at 0x0 and provide a jump to the main firmware, located at 0x2000.
Bootloader linker flags:
-Tbootloader_samd21x18.ld -Wl
And here are the contents of the linker script:
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x2000 /* First 8KB used by bootloader */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000-0x0004 /* 4 bytes used by bootloader to keep data between resets */
This is based off of the .cProj file that comes with the linker. It is compiled as a static library so I can include it into my final binary.
Main Firmware
My code has both the ArduinoCore and the bootloader static libraries as dependencies:
libm
libArduinoCore
libbootloader
And I am using these linker flags:
-Tflash_with_bootloader.ld -Wl,--cref -Os -Wl,--check-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align
The contents of this linker script are moved out by 8KB in order to accommodate the bootloader at the start of the binary:
FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000-0x2000 /* First 8KB used by bootloader */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
And yet, my entry point does not appear to ever hit the bootloader. It jumps straight to "main.cpp" from ArduinoCore. The firmware runs as expected, but the bootloader does not appear to have been included.
Is this some kind of dependency issue? Am I misusing the linkers?
Any help with getting this to compile under a single binary would be very much appreciated. Thank you very much!