Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Write a layout file

A layout file describes the flash of a board once. The command, the build.rs of the firmware and the browser read the same file. Every key is in Layout file.

Describe the flash

Create a TOML file with a [flash] table:

# layouts/esp32-s3-8mb.toml
[flash]
size = "8 MiB"
alignment = "4 KiB"
base-address = 0x0
  • alignment is the default alignment of every partition. Omit it for 4 KiB.
  • base-address is where the flash is mapped. Set it when the linker regions or the addresses of Intel HEX and ELF images need it. Omit it for 0x0.

Add the partitions

Add one [[partition]] per partition, in the order of the flash:

[[partition]]
name = "bootloader"
role = "bootloader"
offset = 0x0
size = "32 KiB"

[[partition]]
name = "partition-table"
role = "partition-table"
offset = 0x8000
size = "4 KiB"

[[partition]]
name = "nvs"
role = "custom"
size = "24 KiB"
espressif = { type = "data", subtype = "nvs" }

[[partition]]
name = "application"
role = "firmware"
size = "3 MiB"
alignment = "64 KiB"

[[partition]]
name = "storage"
role = "storage"
filesystem = "littlefs"
size = "remaining"
  1. Give each partition a unique name and a role.
  2. Give a fixed offset only where the bootloader or the chip needs one. nanoflash places the others after the previous partition, at their alignment.
  3. Give each partition a size. Use "remaining" for the last partition to take what is left.
  4. Add per-family attributes (espressif, mbr, linker) where the role is not enough. A custom partition needs them on Espressif.

Let partitions grow with the flash

When one product ships with several flash sizes, let the chip tell the size:

[flash]
size = "detect"
minimum = "4 MiB"

[[partition]]
name = "storage"
role = "storage"
size = { minimum = "1 MiB", grow = 3, maximum = "8 MiB" }
  • Keep fixed offsets in ascending order.
  • Do not let a firmware or update partition grow.
  • Put the partitions that must stay in place before the first partition that grows.

Growable partitions explains how the free space is shared.

A board with a bootloader at a fixed address

A board without a partition table on the flash, such as the Arduino Nano 33 BLE, needs only the bootloader and the application:

# Arduino Nano 33 BLE (nRF52840): Arduino's bootloader in the first 64 KiB, the application after it.
[flash]
size = "1 MiB"
base-address = 0x0

[[partition]]
name = "bootloader"
role = "bootloader"
offset = 0x0
size = "64 KiB"

[[partition]]
name = "application"
role = "firmware"
size = "remaining"

Next steps