I need to be able to choose between two Arduino apps running on an atmega 1280 (megaavr) at boot time. Therefore I need to move one of those apps to a different location in program memory, and I need to move the interrupts to that location as well.

I already have a method of executing the correct interrupts (with the help of the bootloader) in any location in memory.

However, I don't understand the build process enough to see where the linker decides where to place things and how to move both the program and interrupt sections to new memory locations.

  • Where is the location of the interrupt vector defined?
  • Where is the location of the program defined?

The current builds are performed using Arduino 22. While I'd prefer to modify build scripts or files in that environment, if needed I would consider moving it all over to a makefile build process and out of the Arduino environment.


2 Answers 2


I'll preface this answer by saying I've never actually tried to do this. That being said, Arduino is just a layer on top of avr-libc / avr-gcc. The user manual FAQ explains how to locate code to a fixed address, and I think you should be able to just do it the same way in your Arduino source code. The Arduino IDE is written in Java, and the source is available - you could modify the Compiler.java file to add the necessary flags to the linker (i.e. -Wl,--section-start) to locate your code. I would not recommend trying to go down this road though.

What would be better is to try using Eclipse as your Arduino IDE (lots of info on the web on how to do this), you could just set the linker settings there as you normally would. Much more straight forward.


AVRGCC loads the interrupts and program into the same section, with the interrupts first. The section is simply labeled .text, so only one flag needs to be fed to the compiler to move both the interrupts and the program:

-Wl,--section-start=.text=0x10000 # Exactly 1/2 of a 128k device

I ultimately went with a custom Makefile (there are a multitude of arduino makefile examples on the internet) rather than trying to do this inside Arduino. This will allow me to customize the build process further for other parts of the project as well.

I did not research the linker script further, but I suspect the interrupt section could be separated from the .text section with another simple section directive.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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