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.

asked Feb 24, 2023 at 5:41
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.

answered Feb 24, 2023 at 8:36
4
  • So I can write standard programs with avr studio and not change anything and have them loaded? Commented 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. Commented Feb 24, 2023 at 13:58
  • Ok but the point is you just compile a standard C program. Commented 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 Commented Feb 25, 2023 at 7:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.