What a Bootloader Does and How It Hands Control to the Application
A plain explanation of what a microcontroller bootloader does at reset, how the vector table makes a hand-over possible, and what the application inherits.

If you have only ever pressed the upload button in an IDE, the word bootloader may sound like magic: some code that is already on the chip, waiting to receive more code. It is not magic, and the idea fits in your head once you know what a microcontroller does in the first microsecond after reset. This post explains that sequence for an Arm Cortex-M part, defines every term it uses, shows how a bootloader and an application can share one chip, and demonstrates the hand-over with a small example. The details come from the Arm Cortex-M3 and M4 documentation and the STM32F407 reference manual (RM0090), and the same picture holds for other Cortex-M families.
A processor with no operating system
A desktop computer has layers: firmware starts a bootloader, which loads an operating system, which starts programs. A microcontroller usually has none of that. It has a processor core, some flash memory that keeps its contents without power, some RAM that does not, and peripherals. When you press reset or apply power, the core must know where to find the first instruction. The hardware answers by reading a fixed location.
On a Cortex-M3, M4 or M7 the core reads two 32-bit numbers from the start of a table in memory called the vector table:
| Word | Content | What the core does with it |
|---|---|---|
| 0 | Initial stack pointer value | Loads it into the main stack pointer, MSP |
| 1 | Reset handler address | Jumps there to start running code |
| 2 and on | Addresses of the exception and interrupt handlers | Used later, when an event occurs |
That is the whole start-up sequence. There is no loader, no file system and no program header. The reset handler is a function in your firmware, written in C or assembly by the startup file. It copies initialized variables from flash into RAM, clears the uninitialized ones to zero, sets up the clock, and calls main().
On an STM32 the table sits at the start of flash, which is mapped to 0x08000000 in the address space. A dump of the first words of a typical image shows the idea:
0x08000000: 0x20020000 initial stack pointer (top of 128 KB of RAM)
0x08000004: 0x08000189 reset handler (odd: Thumb bit set)
0x08000008: 0x080001F1 NMI handler
0x0800000C: 0x080001F5 HardFault handlerThe reset address is odd because Cortex-M cores run only Thumb instructions and the lowest bit of a branch target must be 1 to say so. The actual code starts at 0x08000188.
So what is a bootloader?
A bootloader is a small program of your own that sits at the start of flash, so it runs first. Instead of being the whole product, it is a gatekeeper. It starts, looks at the state of the system, and then does one of two things:
If a good application is installed and no update is wanted, it starts the application.
Otherwise it waits for a new application to arrive, writes it into the part of flash reserved for it, and then starts it.
The bootloader and the application are two separate firmware images that live in different regions of the same flash chip. The bootloader owns the first sectors. The application owns the rest.
0x08000000 +----------------------+
| bootloader | runs first, always present
0x08010000 +----------------------+
| application | replaced by updates
| |
0x08100000 +----------------------+Because only the bootloader writes the application region, the application never has to overwrite itself, which would be unsafe. And because the bootloader is small and rarely changes, the part of the system that decides whether the device starts is the part least likely to contain a new bug.
Some words you will meet around this idea:
Image is a complete block of firmware, a bootloader or an application, ready to be written to flash.
Slot is a region of flash that holds one image.
Flash sector is the smallest block that can be erased. Regions must start and end on sector boundaries.
Hand-over (or jump) is the moment the bootloader stops and the application starts.
How the hand-over works
The trick follows from the start-up sequence. The core begins an application by reading its stack pointer and reset handler from a vector table. The bootloader can imitate this on purpose. If the application's vector table sits at 0x08010000, the bootloader reads word 0 and word 1 from there, tells the core where the application's table is, loads the stack pointer and jumps to the reset handler. From the application's point of view, it has just been reset.
In code, the sequence is short:
#include <stdint.h>
#include "stm32f4xx.h"
#define APP_VECTORS 0x08010000u
typedef void (*entry_fn)(void);
void start_application(void)
{
uint32_t sp = *(volatile uint32_t *)(APP_VECTORS + 0u);
uint32_t reset = *(volatile uint32_t *)(APP_VECTORS + 4u);
__disable_irq(); /* no interrupt may fire mid-switch */
SCB->VTOR = APP_VECTORS; /* the core now looks here for handlers */
__set_MSP(sp); /* take the application's stack */
((entry_fn)reset)(); /* jump; this call never returns */
}Four lines do the work. SCB->VTOR is the vector table offset register in the System Control Block. It holds the address of the table the core consults whenever an interrupt or fault occurs, and it starts at zero. Without writing it, the first interrupt in the application would fetch its handler address from the bootloader's table and run the wrong code. Casting the reset address to a function pointer and calling it makes the processor branch there, and since the stack pointer was just replaced, the call has nowhere to return to, so the application takes over for good.
To show the effect, have the application print its vector table address after starting:
#include <stdio.h>
#include "stm32f4xx.h"
int main(void)
{
/* clock and UART setup omitted */
printf("VTOR = 0x%08lX\r\n", (unsigned long)SCB->VTOR);
for (;;) { }
}With the application built for 0x08010000 and started by the bootloader, the console prints:
VTOR = 0x08010000If the same application were flashed at address zero and reset directly, it would print 0x08000000. The difference is what the bootloader's one line of SCB->VTOR = ... produces.
What the application inherits
A real reset puts the chip back in a known state: peripherals off, interrupts disabled, clocks at their default. The bootloader's jump is not a real reset, so the application starts with whatever state the bootloader left. Two kinds of leftovers cause trouble.
Hardware left running. If the bootloader started a timer, a UART with interrupts, or the system tick timer, they keep running into the application. A tick interrupt that fires before the application sets up its handler either calls a wrong function or locks the system. The remedy is to stop everything: disable SysTick, clear the interrupt enable and pending registers in the interrupt controller, and return peripherals to their reset state with the vendor's de-initialization functions.
Clock configuration. The application's start-up code normally assumes the chip is in its reset state, running on the internal oscillator. If the bootloader already switched to a PLL at 168 MHz, the application may try to reconfigure a PLL that is locked and in use. Either return the clock tree to the default before the jump, or write the application's clock setup to tolerate it.
Memory is a third leftover, though a gentler one. The bootloader's variables remain in RAM, and the application's start-up will overwrite or clear them. Do not rely on them surviving, unless you reserved a region both agree on, as the boot info post in this cluster describes.
Why not skip the bootloader?
You can. A product that is programmed once at the factory and never updated needs no bootloader, and the first sector can hold the application directly. The vendor's ROM bootloader, entered with a boot pin, may be enough for initial programming. A custom bootloader earns its flash space when:
The device must be updated without a programmer, in the field.
Updates arrive over some link: serial, USB, Bluetooth, Wi-Fi.
You need to check that firmware is valid or authentic before running it.
You want a way to recover from a bad update.
It costs flash, a few kilobytes at minimum, a more complex build, and a second program to test. The larger bootloader and over-the-air guide in this cluster covers building one end to end.
Where bootloaders come from
There are two sources. Many microcontrollers ship with a ROM bootloader burned in by the vendor. On an STM32, holding the BOOT0 pin high at reset starts a program in system memory that accepts firmware over UART, USB, I2C, SPI or CAN. On the RP2040 it is the BOOTSEL button, which makes the board appear as a USB drive. On AVR boards, the Arduino bootloader (Optiboot) is placed in the top of flash by the board's maker.
The second source is your own. You write it, put it in the first flash sectors, and link it for 0x08000000. The application is linked for its own address higher up. The two images are built separately, and the programmer writes both during manufacturing.
Common beginner mistakes
Linking the application for address zero. The code will run only if flashed at the beginning, and the absolute addresses inside it are wrong anywhere else. Set the origin of the
FLASHregion in the application's linker script to its slot address.**Forgetting
VTOR.** The program runs until the first interrupt, then misbehaves. This is the most common first-bootloader bug.Jumping without checking. If the slot is empty, flash reads as
0xFFFFFFFF, and jumping there is a crash. Check that the stack pointer looks like a RAM address and that the reset handler points inside the application region.Leaving interrupts enabled. An interrupt pending from the bootloader's last action fires the moment the application enables interrupts.
Putting the bootloader and the data in the same sector. Updating a setting would force an erase of the bootloader.


