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

Growable partitions

One product often ships with flash chips of several sizes. A fixed layout wastes the extra flash of the larger chips, and one layout per flash size multiplies the files to keep in step. A layout can therefore take the flash size from the chip (size = "detect") and let some partitions grow with it. This page explains how nanoflash places these partitions. The keys are in Layout file.

Resolution

Resolution keeps the file order. Partitions with a fixed offset stay where they are. The others go at the first offset after the previous partition that satisfies their alignment. Partitions place first at their minimum size. The free space is then shared by these rules:

  • R1 Segments. Every partition with a fixed offset starts a segment of the file order. A segment ends where the next one starts, and the last one ends at the end of the flash. Growth only fills the free space at the end of its own segment, so only the last segment depends on the flash size. In a detect layout, fixed offsets ascend in file order, so that no partition lies above the last segment as it grows. A layout with a fixed flash size keeps any order.
  • R2 Steps. The share of a { grow } partition is a multiple of the largest of its alignment and the alignments of the partitions after it in its segment. These partitions then move by whole multiples of their alignment and need no new padding.
  • R3 remaining grows in steps of the largest alignment of the partitions after it, or of one byte when it is the last of its segment. Alone at the end of a segment, it fills to the byte.
  • R4 Sharing. The free space is shared by weight, and each share is rounded down to its step. A maximum holds a share, and what it leaves goes to the others. The rounding remainder stays unallocated. Several remaining partitions share like { grow = 1 }. The partitions after a growing one are pushed towards the end of its segment. Every layout that was valid before growing sizes existed resolves exactly as before.
  • R5 Roles. firmware and update partitions never take the table form, because their images are built for a size. They may be remaining where that size does not depend on the device: a fixed flash size, or a segment that ends at a fixed offset. In a detect layout, a bootloader, partition-table, firmware or update partition whose offset would move with the flash is refused.
  • R6 Dependence. In a detect layout, a partition grows with the flash when it is remaining or { grow } in the last segment, unless its maximum keeps it below one step above its minimum. It moves with the flash when it is in the last segment, has no fixed offset and comes after a partition that grows with the flash.

Resolution fails, and names the partitions and the addresses involved, on:

  • duplicate names and zero sizes;
  • misaligned fixed offsets, overlaps, and partitions that exceed the flash size;
  • a remaining partition left without space;
  • fixed offsets that descend in a detect layout;
  • a maximum below its minimum;
  • a growing firmware or update partition;
  • a partition whose role needs a fixed offset placed after one that grows with the flash;
  • a flash below the minimum of the layout;
  • roles that a writer cannot express.

Offline outputs use the minimum

layout check, layout write, the build feature and image build without --flash-size do not know the chip. They resolve the layout for its minimum flash size. The constants and linker regions state what holds on every device, so both writers need the layout resolved for its minimum and refuse another (NotAtMinimum). Only the values written decide between u32 and u64.

  • R7 Constants. FLASH_SIZE becomes FLASH_MINIMUM_SIZE. A partition that grows with the flash gets MINIMUM_SIZE instead of SIZE: its size on the minimum flash, the least that it has on any device, because shares never shrink when the flash grows. That size is at least the minimum that the layout declares. The minimum_size of the report is the declared minimum, and MINIMUM_SIZE is the size on the minimum flash. A partition that moves with the flash gets no OFFSET and no ADDRESS, so a firmware that uses them fails to compile instead of writing at the wrong place. A partition that does both has MINIMUM_SIZE and no OFFSET: moving wins for placement, growing for size. The other partitions keep SIZE, so the constants of a fixed layout do not change.
  • R8 Linker regions. A partition that grows with the flash keeps a region of its size on the minimum flash, after a comment. Every byte of that region belongs to the partition on every device, and the linker never places anything past it. A partition that moves with the flash gets no region, and a comment says so: no fixed ORIGIN is right on every device, and a missing region fails the link.

Flashing resolves again

flash checks every input at the minimum before it connects, then resolves the layout again for the flash that the chip reports, before any erase. Images and erase entries that name a partition follow it. Inputs tied to an offset may not touch a partition that moves. Checks before the first erase describes these steps and the warnings partitions-grew, partitions-moved and flash-size-not-detected.

The report

For each partition, the report gives its offset, end and size. When images are known, it gives the image size and the headroom left, in bytes and in percent, plus the unallocated flash. For a layout whose flash size is detected, the report also gives minimum_flash_size, and each partition gives its minimum_size (the minimum that the layout declares, 0 for remaining), its growth (the bytes above it), and whether it grows_with_flash or moves_with_flash. An image larger than its partition is an error. The human output is a table, and --json gives the same data.