Skip to content

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

Open

Description

@elyorbek010

Summary

On the i.MX RT targets that use a serial NOR flash with 4 KB sectors and 64 KB blocks, hal_flash_erase() hands the range to the boot ROM erase function. The ROM walks the range in steps of the sector size from the flash configuration and sends the sector erase command for each step. Building wolfBoot with WOLFBOOT_SECTOR_SIZE=0x10000 therefore does not make an update faster: every 64 KB wolfBoot sector still costs sixteen 4 KB erases.

On our flash a 4 KB sector erase takes about 36 ms and a 64 KB block erase about 150 ms, so erasing 64 KB as one block is roughly four times faster than erasing it as sixteen sectors (about 150 ms against 580 ms). Erase time is most of what a swap update costs.

What we measured

Board with an i.MX RT1040 family part, XIP from a QSPI NOR flash, wolfBoot v2.8.0 built with TARGET=imx_rt, ECC384, SHA384, no NVM_FLASH_WRITEONCE, partitions of 4 MB, application image about 2.5 MB. Time spent in wolfBoot for one swap update, from reset until the application starts:

wolfBoot build time in wolfBoot
4 KB wolfBoot sectors about 120 s
64 KB wolfBoot sectors, HAL unchanged about 116 s
64 KB wolfBoot sectors, erase sent as a 64 KB block erase about 45 s

After the last run the boot partition was byte-identical to the new image, and a later update with an image that never confirms itself was rolled back correctly.

I read hal/imx_rt.c on master (254cfa5): hal_flash_erase() and the flash configuration are the same there as in v2.8.0 for this path, so I expect the same behaviour, but I have only run v2.8.0.

What we changed locally

In the copy of the flash configuration that the HAL passes to the ROM driver, we changed the erase sequence that the ROM uses for a sector from the 4 KB sector erase command to the 64 KB block erase command (the 3-byte or the 4-byte address variant, matching the one that was there), and set the sector size in that configuration to the block size. We did this only when the wolfBoot sector size equals the flash block size, so builds with 4 KB wolfBoot sectors are not affected. All partitions and the swap area have to be aligned to 64 KB for this.

Request

Could the i.MX RT HAL use the block erase command when the wolfBoot sector size is the flash block size, or offer a build option for it? If there is already a supported way to get block erases through the ROM API on these parts, a pointer to it would be enough.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions