Skip to content

Conversation

ludvigsj
Copy link
Contributor

@ludvigsj ludvigsj commented Oct 6, 2025

This cherry picks upstream changes needed to make Mesh DFU work with external flash on devices where both RRAM and Flash based memory are available (such as the nRF54L15 DK with external flash enabled). This is needed because it is currently blocking us from supporting DFU with external flash support in the DFU samples for nRF54L15.

…sh config

This adds a Kconfig dependency on FLASH_PAGE_LAYOUT when using flash
with explicit erase, removing all code dependencies on flash
configuration from the erasure logic. This module already requires
FLASH_PAGE_LAYOUT to be set when using it with flash with explicit
erase, as a silent requirement. The current code does not work without
this option enabled except for the case where a BLOB has a size which is
a multiple of the page size (since, without it, trying to erase flash
space for the final block, which is of variable size, will fail). Also
cleans up the code a bit.

Signed-off-by: Ludvig Jordet <[email protected]>
(cherry picked from commit 294a2cd)
…ocks

Only erase a page when starting the first block on that page.
This fixes a bug where, if the block size is smaller than the page size,
the entire page would be erased upon start of each block when writing,
meaning only the final block on each page would be retained. This works
because blocks are always received in order.

Signed-off-by: Ludvig Jordet <[email protected]>
(cherry picked from commit 99190cb)
…flash

This fully decouples blob_io_flash from specific flash device details,
by not reading the write block size from a hard-coded device tree node,
instead pulling this from the actual flash device used.

The block write routine has been updated to be more generic and fix a
few bugs:

  * The write buffer is now sized based on a KConfig option instead of
    basing it off the device tree - this makes the module usable with
    any flash device, not just the internal memory. The configured value
    is checked during initialization, to ensure that the configured size
    will fit the write block size required by the device passed to the
    init function.
  * The erase value used to fill the buffer when using a device with
    explicit erase is now pulled from the flash parameters instead of
    being hard-coded to `0xff`.
  * An additional write block sized piece of buffer is allocated - the
    previous buffer sizing with rounding up only worked if
    `BLOB_RX_CHUNK_SIZE % WRITE_BLOCK_SIZE` was 0 or 1 (which
    coincidentally worked in all testing because the chunk size defaults
    to 161, and for internal flash w/write block size of 4,
    `161 % 4 == 1`).
  * The choice of whether to just write the chunk as-is or to
    write-block align it is now based on the erase cap pulled from the
    flash parameters, instead of checking the type of memory in the SOC.
    This means the module dos _not_ currently support the case where
    memory has to be written write-block aligned, but the memory does
    _not_ use explicit erase. It uses a trick of filling the write
    buffer with the erase value to avoid overwriting existing chunks,
    which will not work in this case. This trick is required to support
    random ordered chunks while still writing write-block aligned.
  * The code has been cleaned up a bit in general.

Signed-off-by: Ludvig Jordet <[email protected]>
(cherry picked from commit db207b0)
…ions

The only reason to keep these would be to enable conditional compilation
of some parts of the code. However, we can't see enough benefit in doing
this, particularly since the flash driver itself will conditionally
handle certain paths depending on erase caps, so the options are
deprecated to reduce complexity.

Signed-off-by: Ludvig Jordet <[email protected]>
(cherry picked from commit 8720ab7)
@ludvigsj ludvigsj changed the title [nrf fromtree] Cherry pick blob flash decoupling [nrf fromtree] Bluetooth: Mesh: Cherry pick blob flash decoupling Oct 7, 2025
@rlubos rlubos merged commit f785989 into nrfconnect:main Oct 7, 2025
21 checks passed
@ludvigsj ludvigsj deleted the develop/cherry-pick-blob-flash-decoupling branch October 7, 2025 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants