Skip to content

imx_rt: enable the L1 caches while wolfBoot runs - #993

Closed
elyorbek010 wants to merge 1 commit into
wolfSSL:masterfrom
elyorbek010:imx-rt-l1-caches
Closed

elyorbek010 wants to merge 1 commit into
wolfSSL:masterfrom
elyorbek010:imx-rt-l1-caches

Conversation

@elyorbek010

Copy link
Copy Markdown

Fixes #990.

hal_init() now enables the instruction cache and the data cache, and hal_prepare_boot() disables both again, so the application still starts with the caches off, the state the boot ROM leaves.

  • The flash write and erase functions already invalidate the data cache for the range they touch, so they are not changed.
  • The data cache stays off when the DCP is used (PKA=1): dcp_port.c in wolfCrypt refuses to build with DCP_USE_DCACHE=1, so its buffers would not be maintained. The instruction cache is still enabled in that case.
  • IMX_RT_NO_DCACHE keeps the data cache off in any build. It is described in docs/Targets.md.
  • The caches are only touched when the HAL is built into wolfBoot (__WOLFBOOT), not when it is built into an application.

Testing

Run on an i.MX RT1040 series board, XIP from QSPI NOR flash, with master (6d94df4) plus this branch, SIGN=ECC384, HASH=SHA384, no DCP, application image about 2.5 MB. The board needs its own DCD and application entry offset on top, nothing else. Time from reset until the application answers on the network, three runs each, same application:

wolfBoot build reset to application answering
master 32.1 s, 28.7 s, 30.3 s
master with this change 12.6 s, 12.6 s, 8.9 s

With the caches on I also ran, on master together with the change of #989: two swap updates (boot partition byte-identical to the new image afterwards, state IMG_STATE_SUCCESS) and a rollback of an image that does not confirm itself (state IMG_STATE_TESTING after the update, previous image back after the next reset).

Build only, no warnings: config/examples/imx-rt1040.config with PKA=0, with PKA=1 and with -DIMX_RT_NO_DCACHE. Not tried on the RT1050, RT1060 and RT1064, which I do not have, and not run with the DCP in use.

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

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.

🔵 Needs a closer look

Default cache enablement affects flash-update coherency and application handoff across supported i.MX RT variants, but runtime evidence covers only RT1040 without DCP, leaving other variants and DCP-enabled builds needing maintainer confirmation or hardware validation.

No open issues 🎉

What changed in this PR

This PR addresses #990 by enabling Cortex-M7 L1 caches while wolfBoot runs on i.MX RT, reducing image-verification time while preserving a cache-disabled application handoff.

Changes:

  • Enables instruction and data caches during wolfBoot initialization and disables them before application handoff.
  • Keeps the data cache off for DCP builds or when IMX_RT_NO_DCACHE is defined; application-only HAL builds remain unaffected.
  • Documents cache behavior and the data-cache opt-out.
File Description
hal/​imx_rt.c Adds guarded cache initialization and shutdown, with DCP and opt-out handling.
docs/​Targets.md Documents i.MX RT cache behavior and IMX_RT_NO_DCACHE.

Review effort: Balanced

The boot ROM leaves the instruction and data caches of the Cortex-M7
off and hal_init() did not enable them, so the image hash and the
signature verification ran from memory-mapped flash without caches.

Enable both caches in hal_init() and disable them in
hal_prepare_boot(), so the application starts with the caches off as
before. The flash write and erase functions already invalidate the
data cache for the range they touch.

The data cache stays off when the DCP is used, because the DCP port of
wolfCrypt does not support it, and when IMX_RT_NO_DCACHE is defined.
@dgarske dgarske self-assigned this Nov 19, 2026
@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: wolfBoot runs with the L1 caches off, image verification is about 20 s slower than it needs to be

5 participants