Where is the bootloader in memory exactly?

Hey guys,

When uploading a sketch inside the Arduino IDE, my question is whether it's the .hex file that gets uploaded to the microcontroller, or is it the .c file that gets compiled and then uploaded to the microcontroller? Also, in the microcontroller's memory, where exactly is the bootloader code located?"

The source code is compiled and linked to produce binary machine code, which is translated into human readable hex notation (file with .hex extension).

The loader transmits that file to the bootloader, usually in the highest memory block, which stores the machine instructions in lower program memory.

When you upload, the IDE compiles all files (.ino/.c/.cpp) that are needed for the sketch which eventually will result in a hex or binary file that will be uploaded.

I'm not sure where the bootloader is; it's either at the beginning of flash memory or at the end.

You likely need to consult the processor manual to see where the bootloader is stored, it will vary. On the UNO and similar AVR processors it tends to be in the upper part of flash memory. There are some Arduino boards, such as the Nano Every, where there is no bootloader on the processor itself.

The hex file is binary code stored in human readable form called Intel Hex Format.

It is at the end. Given of course we are talking about an AVR processor like the Uno.

Normally the boot loader only needs to be burned into a raw chip once. The simplest way to do this is to get another Arduino and load the code into for it to act as a programmer. Then select the type of interface you want using the Program menu in the tools window. In this case choose the "Arduino as ISP" option. Then connect your raw chip to your Arduino as a processor and choose the last option in the Tools menu to Burn Boot loader.

Some sorts of Arduino have the code stored in Flash (read only memory) but then in order to run the code it is transferred into RAM in order to run. These are the type that use the Mbed system.

1.

Please, see the following diagram (Fig-1) for the flash space that holds the Boot Loader Program for the ATmega328P MCU of the Arduino UNO Board.


Figure-1:

2.

After the compilation of the high level sketch, binary codes are generated. After that an Intel-Hex formatted file is generated for the purpose of transmitting the program codes over the UART Port.

The Boot Loader Program collects the Intel-Hex formatted frames from the UART Port, retrieves the original binary codes of the sketch and then stores them into the application section of the flash memory (Fig-1) using SPM instruction.

At the end of the storage, the control goes to location 0x0000 from where the MCU jumps at the beginning address (I have shown an arbitray location 0x0040) of the application program and begins code execution.

If I try to load bootloader of Arduino Uno Minima R4 I got this screen ...

Given of course we are talking about an AVR processor like the Uno.

And not one of the newer AVRs like the ATmega4809, which either don't have a bootloader at all (Nano Every), or put the bootloader at the beginning of memory (MegaCoreX)

ARMs all have the bootloader first (at 0), but some (SAM3x8e on Due, rp2040) use tricks to map different regions of flash to "0" at boot time.

Thanks for your answer.

So if we look at it from the point of view of a .ino file, how does the bootloader .c file and the .ino file compile together for a same sketch. Is every bootloader .c file inside a sketch ?

Ok thank you this answer, my understanding is getting clearer.

Would you like to make any comments on Fig-1 of post #6 as to --
1. From which location of Boot Section the Control goes to location 0x0000?
2. To which location of Application Section, the control goes from 0x0000?

The bootloader is loaded into the chip separately, and STAYS there unless explicitly erased. When a .ino file is compiled, it produces its own binary file that is compiled to be located at the appropriate address, and the bootloader copies it from the Serial (or USB) port to that memory area.

Not really. It seems OK for Uno.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.