Repository navigation
imx_rt: erase a wolfBoot sector of one flash block with a block erase - #994
elyorbek010 wants to merge 2 commits into
Conversation
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.
There was a problem hiding this comment.
🟡 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.
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
| seq[0] = (seq[0] & ~0xFFU) | cmd; | ||
| config->sectorSize = CONFIG_FLASH_BLOCK_SIZE; |
There was a problem hiding this comment.
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.
ca8f547 to
ee5ffd5
Compare
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.
|
Okay to test. Contributor agreement in progress. ZD 22861 |
|
Not approved as a contributor. Please consider opening a GitHub Issue to report this issue. |

Fixes #989.
When
WOLFBOOT_SECTOR_SIZEequals 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 (0x20to0xD8, or0x21to0xDCwith 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.USE_GET_CONFIG: RT1040, RT1060/1061/1062, RT1064). The RT1050 keeps its configuration in flash and is not changed.WOLFBOOT_SECTOR_SIZE, the 4 KB of the example configurations included, compile to the same code as before.docs/Targets.mdsays 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: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 atIMG_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.configwith 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.