Skip to content

imx_rt: erase a wolfBoot sector of one flash block with a block erase - #994

Closed
elyorbek010 wants to merge 2 commits into
wolfSSL:masterfrom
elyorbek010:imx-rt-block-erase
Closed

elyorbek010 wants to merge 2 commits into
wolfSSL:masterfrom
elyorbek010:imx-rt-block-erase

Conversation

@elyorbek010

Copy link
Copy Markdown

Fixes #989.

When WOLFBOOT_SECTOR_SIZE equals the block size of the flash (64 KB on the QSPI parts), the HAL now changes the copy of the flash configuration it got from the boot ROM before it passes it to the ROM driver: the erase sector sequence becomes the block erase command (0x20 to 0xD8, or 0x21 to 0xDC with 4-byte addresses) and the sector size becomes the block size. The ROM erase function then sends one block erase per wolfBoot sector and no longer sixteen sector erases.

  • Only for the targets that read the configuration from the ROM (USE_GET_CONFIG: RT1040, RT1060/1061/1062, RT1064). The RT1050 keeps its configuration in flash and is not changed.
  • Builds with another WOLFBOOT_SECTOR_SIZE, the 4 KB of the example configurations included, compile to the same code as before.
  • If the erase sector sequence does not start with one of the two known sector erase commands, the configuration is left as it is.
  • The partitions and the swap area have to be aligned to the block size. A paragraph in docs/Targets.md says so.

Testing

Run on an i.MX RT1040 series board, XIP from QSPI NOR flash, with master (6d94df4), WOLFBOOT_SECTOR_SIZE=0x10000, 4 MB partitions aligned to 64 KB, application image about 2.5 MB. The board needs its own DCD and application entry offset on top, nothing else. Both builds also had the caches enabled (#990), so the difference is the erase alone. Time spent in wolfBoot for one swap update, from the reset until the application starts, taken by sampling the program counter over the debug probe:

wolfBoot build time in wolfBoot of that in the ROM flash functions
master 117.7 s 112.0 s
master with this change 45.2 s 39.8 s

After the update with this change the boot partition was byte-identical to the new image and its state was IMG_STATE_SUCCESS. An update to an image that does not confirm itself left the state at IMG_STATE_TESTING, and after the next reset wolfBoot swapped the previous image back (58.7 s from reset until it answered on the network).

Build only, no warnings: config/examples/imx-rt1040.config with its 4 KB sectors (the new function is not in the binary) and with 64 KB sectors. Not tried on the RT1060 and RT1064, which I do not have.

I have asked support for the contributor agreement and referenced this pull request.

Copilot AI balanced review requested due to automatic review settings November 18, 2026 09:10
The ROM erase function walks the range in steps of the sector size
from the flash configuration and sends the sector erase command for
each step. With WOLFBOOT_SECTOR_SIZE set to the 64 KB block size of a
QSPI flash, every wolfBoot sector was still erased as sixteen 4 KB
sectors.

When the wolfBoot sector size equals the flash block size, change the
erase sector sequence in the configuration read from the ROM to the
block erase command, and the sector size in it to the block size. The
configuration is left alone when the sequence does not start with a
known sector erase command.

This applies to the targets that get the configuration from the ROM
(RT1040, RT1060/1061/1062, RT1064). Builds with 4 KB wolfBoot sectors
are not changed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The erase granularity change can make encrypted-key maintenance fail or erase data outside its 4 KB cache when 64 KB sectors are configured.

1 open issue
What changed in this PR

This PR addresses #989 by using block erases to speed up updates on supported i.MX RT targets when a wolfBoot sector matches the flash block size.

Changes:

  • Rewrites recognized ROM-provided sector erase commands and erase granularity to use flash blocks.
  • Leaves RT1050 and builds with other wolfBoot sector sizes unchanged.
  • Documents the block-size alignment required for partitions and the swap area.
File Description
hal/​imx_rt.c Adds conditional block-erase configuration before ROM driver initialization.
docs/​Targets.md Documents block erases, supported targets, and alignment requirements.

Review effort: Balanced

Comment thread hal/imx_rt.c
Comment on lines +911 to +912
seq[0] = (seq[0] & ~0xFFU) | cmd;
config->sectorSize = CONFIG_FLASH_BLOCK_SIZE;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, with FLASH_ERASE_UNIT smaller than the block the HAL has to keep erasing by sector. The block erase is
now used only when WOLFBOOT_FLASH_ERASE_UNIT is not set or equals the block size, and docs/Targets.md says
so. A build with 64 KB sectors and FLASH_ERASE_UNIT=0x1000 now compiles to the same code as before this PR.

Encrypted-key maintenance erases one WOLFBOOT_FLASH_ERASE_UNIT at a time. With a unit smaller than the flash block the ROM has to keep erasing by sector, so use the block erase only when no smaller unit is configured.
@dgarske

dgarske commented Nov 19, 2026

Copy link
Copy Markdown
Member

Okay to test. Contributor agreement in progress. ZD 22861

@embhorn

embhorn commented Nov 25, 2026

Copy link
Copy Markdown
Member

Not approved as a contributor. Please consider opening a GitHub Issue to report this issue.

@embhorn embhorn closed this Nov 25, 2026
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.

i.MX RT: a 64 KB wolfBoot sector is erased as sixteen 4 KB sector erases

5 participants