Request a firmware review
Menu
Teams choosing a microcontroller or flash layout for updatable firmware

Check that two image slots fit in your flash

Enter your flash size, partitions and current image. The calculator sizes two equal image slots and tells you whether the image still fits after the growth you expect.

Key characteristics

Inputs
Flash, bootloader, scratch, storage, sector size, image, growth
Outputs
Slot size, largest image, fill, growth check
Default example
Fictional LW-1 probe with 1 MB of internal flash
Runs
In your browser with nothing sent

Calculator: Check that two image slots fit in your flash

Fictional example values are filled in. Replace them with your own; results update as you type. Nothing you enter leaves your browser.

Space the bootloader reserves inside each slot for its header, signature and swap status. Swap using move or offset needs one more erase sector; add it here.

Results

Space for the two image slots
896 KB
Each slot, aligned to the sector size
448 KB
Largest image that fits a slot
444 KB
Current image fills its slot
92.8%
Room left for growth
32 KB
Image after the growth you want
515 KB
Fits with that growth
No, 71 KB short
Flash left unassigned
0 KB

Two equal slots let the bootloader keep the running image while the new one downloads and swap back if the new one fails. Slots are rounded down to whole erase sectors. If the image will not fit, the usual answers are a smaller image, an external flash chip for the second slot, or a different update method with its own trade-offs.

A device that can update itself safely needs room for two copies of its firmware: the one running now and the one arriving. With MCUboot, and most bootloaders built the same way, that means two image slots, plus space for the bootloader itself, settings and logs. The question to answer before you choose a microcontroller is whether your image fits twice, with room for the features and fixes still to come.

How to use it

  1. Enter the internal flash size and each fixed partition: bootloader, scratch (if your swap method needs one), settings, and logs and other storage.
  2. Enter the flash erase sector size.
  3. Enter the header and trailer allowance, your current image size and the growth you want room for.

What each input means

Input What it means Where to get a real number
Internal flash Total program flash on the part The microcontroller datasheet
Bootloader partition Space for MCUboot or your bootloader The bootloader build output, rounded up to whole sectors with some spare
Scratch partition A temporary area that swap using scratch needs to move sectors 0 for swap using move, swap using offset and overwrite-only
Settings, logs and other storage Partitions your application keeps across updates Your settings and log formats, sized for a full log, not an empty one
Flash erase sector size The smallest block the flash can erase The reference manual; external flash chips often differ from internal flash
Header and trailer allowance Space the bootloader keeps in each slot for the image header, signature and swap status Your bootloader configuration; see the swap method note below
Current application image Your signed image today Build output
Growth you want room for How much the image will grow before support ends How much it grew over the last few months, extended

Reading the default example

Example (fictional). Loamwick’s LW-1 probe has 1,024 KB of internal flash: a 48 KB MCUboot partition, no scratch, 32 KB of settings and 48 KB of logs, with 4 KB erase sectors and a 4 KB header and trailer allowance. That leaves 896 KB for two slots of 448 KB each. The largest image that fits a slot is 444 KB, and the 412 KB application image fills 92.8% of it, with 32 KB left for growth. With 25% growth the image would be 515 KB, which does not fit: it is 71 KB short. No flash is left unassigned. Loamwick’s answer is to move the second slot to an external flash chip on the Rev E board.

At 92.8% the image fits today, and small fixes will fit for a while. But a new feature or a larger security library could push it over, and from then on no update could reach the probes until the layout changed. Changing the partition layout of shipped devices is itself a risky update, so the decision belongs in the next board revision, not a later firmware release.

How it calculates

The calculator subtracts the bootloader, scratch, settings and logs from the total flash. It splits what remains in two and rounds each half down to whole erase sectors, because a slot has to start and end on a sector boundary. The largest image is the slot size minus the header and trailer allowance. Fill is the current image divided by that largest image. The growth check multiplies the current image by one plus the growth share and compares it with the largest image.

Limits

  • Equal slots only. The calculator gives both slots the same size and puts both in internal flash. With the second slot on an external chip, the first slot can take the space the second one used, and the external chip needs a slot at least as large.
  • The swap method changes the numbers. MCUboot’s documentation describes several ways to swap images. Swap using move needs one extra sector in the primary slot, and gives the largest image as the number of sectors minus one, times the sector size, minus the trailer rounded up to whole sectors. Swap using offset needs one extra sector in the secondary slot instead. With two equal slots, budget that sector out of the image: raise the header and trailer allowance by one sector (to 8 KB in the example, which brings the largest image to 440 KB). Swap using scratch needs the scratch partition instead, and the documentation notes it may be removed in future. Overwrite-only needs neither, but cannot go back to the old image on its own.
  • Trailer size varies. The swap status area grows with the number of sectors in a slot and the flash write alignment. Use the size your bootloader build reports.

What to do next

If the image does not fit, the usual answers are a smaller image (size-optimized builds, less logging, fewer unused stack features), an external flash chip for the second slot, or a different update method with its own trade-offs. We work through these choices in over-the-air updates and firmware development. The same image size drives the over-the-air data cost calculator, and the version scheme builder covers the version written into the image header. The updates and releases section of Field Update has more on update architecture.

Send us your board and your plan.

A firmware review reads your schematics, code, flash layout and update plan, and ends with a written plan: what to build first, what could go wrong in the field and how updates will reach your devices.

Request a firmware review

Or email sales@fumbar.com, or call (720) 675-4202.