boot: bootutil: Allow ports to size the image hash buffer - #2823
Merged
Conversation
BOOT_TMPBUF_SZ is the buffer the image is read into, in chunks, while its hash is computed, so the number of flash_area_read() calls over an image is ceil(image_size / BOOT_TMPBUF_SZ). On flash that is not memory mapped every one of those reads is a bus transaction with a fixed cost, which can make this size dominate image validation time; ports that are short on RAM may equally want to lower it from the 256 byte default. The buffer is declared by the callers of bootutil_img_validate() rather than passed in by the port, so a port using the in-tree loaders cannot currently influence it at all. Add MCUBOOT_BOOT_TMPBUF_SZ so a port can override it from mcuboot_config.h, following the same pattern already used for MCUBOOT_BOOT_MAX_ALIGN in bootutil_public.h. The default is unchanged, so there is no behavioural change for any existing configuration. Signed-off-by: Daniel Riege <daniel.riege99@gmail.com>
nordicjm
approved these changes
Aug 6, 2026
de-nordic
approved these changes
Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
MCUBOOT_BOOT_TMPBUF_SZ, letting a port override the size of the bufferused to read an image in chunks while computing its hash. The default stays at
256 bytes.
Why
BOOT_TMPBUF_SZdetermines the chunk size inbootutil_img_hash(), so thenumber of
flash_area_read()calls over an image isceil(image_size / BOOT_TMPBUF_SZ).On flash that is memory mapped the per-call cost is small. On flash that is not
— QSPI, SPI NOR, eMMC — each read is a bus transaction with a fixed
command/address overhead, so the read count rather than the byte count can
dominate validation time. At the 256 byte default a 1 MiB image is 4096
sequential reads.
The converse also applies: the buffer is statically allocated, so a
RAM-constrained port may want it smaller than 256.
Why not just pass a different
tmp_buf_sz?bootutil_img_hash()already takes the buffer and its size as parameters, butevery caller lives in
boot/bootutilor in a port:boot/bootutil/src/bootutil_loader.cboot/bootutil/src/loader.cboot/boot_serial/src/boot_serial_encryption.cboot/zephyr/single_loader.c,boot/zephyr/firmware_loader.cboot/mynewt/src/single_loader.cA port that uses the in-tree loaders therefore has no way to reach it short of
forking those files.
bootutil_priv.halready includesmcuboot_config/mcuboot_config.habove the definition, so a guard is all thatis needed.
Design
Mirrors the existing
MCUBOOT_BOOT_MAX_ALIGN->BOOT_MAX_ALIGNpattern inboot/bootutil/include/bootutil/bootutil_public.h— same#ifdef/_Static_assert/#elsedefault shape, and the option name is the existinginternal name with the usual
MCUBOOT_prefix, so no new vocabulary isintroduced.
Happy to rename it, or to add a corresponding Zephyr Kconfig option, if
maintainers prefer — note that this guard is a prerequisite for such a Kconfig
option working at all.
Impact
and the new macro is defined nowhere in tree.
samples/mcuboot_config/mcuboot_config.template.h.