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:

  1. ArduinoCore
  2. bootloader
  3. 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:


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!

  • it is not really an Arduino question
    – Juraj
    Commented Feb 24, 2021 at 15:04
  • " .cProj file that comes with the linker." I'm guessing you meant "with the bootloader." Is the goal just to wind up with a single binary that has both the sketch code and bootloader in it, because the IDE and arduino-cli do that. Or do you really really want to use ATMEL Studio for some reason?
    – timemage
    Commented Feb 25, 2021 at 17:14
  • My whole project is in Atmel Studio. Doing it in Arduino IDE is not possible at this point, especially after modifying some of the core files. I think I have solved it for now using srec_cat.
    – Andrew
    Commented Feb 25, 2021 at 21:50

1 Answer 1


This isn't exactly 100% the answer I was looking for, because I still want to know how I can use a static library build, as I mention in my post, and compile everything as a single binary. This method is essentially gluing two binaries together.

I found this great and informative post over here: https://www.avrfreaks.net/forum/can-you-combine-appbootloader-using-as7

It uses srec_cat to concatenate two binaries after building them: https://www.keil.com/support/docs/2666.htm

I use the offset specified from the '.ld' file using

srec_cat <firmware1.bin> -Binary <firmware2.bin> -Binary -offset 0x2000 -o <firmwareOut.bin>

As the post suggests, I set this up as a post-build event and set my build dependencies accordingly so that a full clean and make will produce a consolidated binary including the bootloader.

If anyone tries this, make sure you only use the non-bootloader binary generated by your main project build. The bootloader places new firmware at location 0x2000 and your firmware will break if it finds a bootloader at the location where the firmware is supposed to be. When uploading firmware to the bootloader, it does not overwrite the bootloader.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.