Home / Learn Embedded C / Flash Layout: Bootloader and Application

Flash Layout: Bootloader and Application

How flash memory is divided into separate regions for the bootloader and the application.

The short versionHow flash memory is divided into separate regions for the bootloader and the application.

Theory in plain words

A typical flash layout with a bootloader0x08000000Bootloader region (small, rarely updated)0x08004000Application region (updated by the bootloader)0x08020000Optional: second application slot (for A/B updates)
A typical flash layout with a bootloader

Definition

A bootloader-capable chip's flash is divided into at least two regions: a small bootloader region (at the fixed address the chip starts executing from after reset) and a larger application region (where the actual firmware lives, loaded/updated by the bootloader).

Why you need this

This separation is what makes field updates possible at all — the application region can be safely erased and reprogrammed by the bootloader without ever touching (and risking corrupting) the bootloader's own flash region.

How it works

The exact addresses and sizes of each region are defined in the chip's linker script (covered in depth in the Build Systems group) — both the bootloader's and the application's build must agree on where the application region begins.

Where you'll see this

  • Linker script design
  • Firmware update architecture
  • Flash memory planning

Try it

Checking that a write address falls inside the application region onlyC: edit and run

A real bootloader performs exactly this kind of bounds check before accepting any incoming firmware bytes, to guarantee it can never overwrite itself.

Try it: computing each region's size from its start/end addresses

Deriving region sizes to confirm the application region is far larger than the bootloaderC: edit and run

Computing sizes this way is a useful sanity check when reading a linker script, since the bootloader region is normally a small fraction of the much larger application region.

Test what you just read

1. Why must flash be divided into separate bootloader and application regions?