2

I realized that on the atmega boards the bootloader is programmed into the chip.

I'm curious, when compiling a sketch how does the compiler/assembler differ from compiling a standard C program for a chip without a bootloader?

Is there still a main? Does the linker put the startup code in a different area? Obviously with the bootloader you're no longer compiling a program which places code at the reset address.

1

1 Answer 1

5

On the Uno and similar AVR-based boards, the compiler and assembler are not aware of the bootloader. The compiled program starts at address zero. There you have the interrupt vector table, starting with the reset vector. That vector is a jump to the C runtime startup code, which does some low-level initialization, then calls main() from the Arduino core library, which calls setup() and loop() from your sketch.

The bootloader lives at the end of the flash. The AVR chip has a few bytes of non-volatile configuration memory called “fuses”. These bytes are configured by the Arduino board maker to dedicate the last 512 bytes of flash to the bootloader, and to start executing the code at the start of the bootloader on power up and on reset events. It is then the bootloader's responsibility to jump to address zero in order to start the user's program.

4
  • So I can write standard programs with avr studio and not change anything and have them loaded? Feb 24, 2023 at 13:51
  • @FourierFlux: I have never used AVR Studio, but I do occasionally write regular AVR programs using avr-libc, compile them with avr-gcc, and upload them to an Uno using avrdude. Feb 24, 2023 at 13:58
  • Ok but the point is you just compile a standard C program. Feb 24, 2023 at 14:22
  • warning for future readers. the answer really only applies to AVR architecture. it doesn't carry over to other architectures
    – Juraj
    Feb 25, 2023 at 7:08

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.