From: Johannes Schneider <johannes.schneider@leica-geosystems.com>
To: barebox@lists.infradead.org
Cc: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Subject: [PATCH] ARM: i.MX8M: enable MMU in PBL around fw-external BL32 verify
Date: Tue, 16 Jun 2026 14:49:23 +0000 [thread overview]
Message-ID: <20260616144924.1614561-1-johannes.schneider@leica-geosystems.com> (raw)
The BL32 fw-external blob is loaded into DRAM by the PBL and then
SHA-256-verified inside get_builtin_firmware_ext(). The verify runs
in PBL phase 1 with the MMU off and D-cache cold, walking ~720 KiB
through uncached DRAM accesses; on a Cortex-A53 this costs around
2 s of pre-BL31 wall-clock on every boot.
The verify is the only thing anchoring the BL32 content to the
signed PBL: HABv4 on i.MX8M only signs and loads what fits in
on-chip SRAM (= the PBL), and BL31/BL32 reach DRAM via PBL-driven
copies, so skipping the SHA-256 would be a security regression.
Turn on MMU + D-cache once the DRAM is populated and right before
the SHA-256 verify + BL31/BL32 memcpy run, and drop the MMU again
right before the BL31 entry (BL31 expects MMU off). Mirrors the
Rockchip handling in commits f2ae1a4a85 ("ARM: rockchip: atf:
enable MMU in PBL") and a0ef3a1b5c ("ARM: rockchip: atf: pass
correct memsize to mmu_early_enable()").
Measured on i.MX8MM and i.MX8MP (Cortex-A53, ~720 KiB BL32 blob):
the BL32 verify drops from ~2 s to ~300 ms (generic-C SHA-256 in
both cases, the difference is the D-cache state) and the BL31
early-init also benefits from the warm cache (~200 ms saved).
Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
---
--- a/arch/arm/mach-imx/atf.c
+++ b/arch/arm/mach-imx/atf.c
@@ -20,6 +20,7 @@
#include <mach/imx/xload.h>
#include <mach/imx/snvs.h>
#include <pbl.h>
+#include <asm/mmu.h>
static void imx_adjust_optee_memory(void **bl32, void **bl32_image, size_t *bl32_size)
{
@@ -187,6 +188,9 @@
"r" (tfa_dest - 16) :
"cc");
+ /* BL31 expects MMU off. */
+ mmu_disable();
+
/*
* If enabled the bl_params are passed via x0 to the TF-A, except for
* the i.MX8MQ which doesn't support bl_params yet.
@@ -284,6 +288,12 @@
imx8m_setup_snvs();
imx8mm_load_bl33(bl33);
+ /* Cache DRAM for the BL32 verify + BL31/BL32 memcpy that follow. */
+ mmu_early_enable(MX8M_DDR_CSD1_BASE_ADDR,
+ imx8m_barebox_earlymem_size(32),
+ MX8M_DDR_CSD1_BASE_ADDR +
+ imx8m_barebox_earlymem_size(32) - OPTEE_SIZE);
+
if (IS_ENABLED(CONFIG_FIRMWARE_IMX8MM_OPTEE)) {
get_builtin_firmware_ext(imx8mm_bl32_bin, bl33, &bl32, &bl32_size);
get_builtin_firmware(imx8mm_bl31_bin_optee, &bl31, &bl31_size);
@@ -349,6 +359,12 @@
imx8m_setup_snvs();
imx8mp_load_bl33(bl33);
+ /* Cache DRAM for the BL32 verify + BL31/BL32 memcpy that follow. */
+ mmu_early_enable(MX8M_DDR_CSD1_BASE_ADDR,
+ imx8m_barebox_earlymem_size(32),
+ MX8M_DDR_CSD1_BASE_ADDR +
+ imx8m_barebox_earlymem_size(32) - OPTEE_SIZE);
+
if (IS_ENABLED(CONFIG_FIRMWARE_IMX8MP_OPTEE)) {
get_builtin_firmware_ext(imx8mp_bl32_bin, bl33, &bl32, &bl32_size);
get_builtin_firmware(imx8mp_bl31_bin_optee, &bl31, &bl31_size);
@@ -414,6 +430,12 @@
imx8m_setup_snvs();
imx8mn_load_bl33(bl33);
+ /* Cache DRAM for the BL32 verify + BL31/BL32 memcpy that follow. */
+ mmu_early_enable(MX8M_DDR_CSD1_BASE_ADDR,
+ imx8m_barebox_earlymem_size(16),
+ MX8M_DDR_CSD1_BASE_ADDR +
+ imx8m_barebox_earlymem_size(16) - OPTEE_SIZE);
+
if (IS_ENABLED(CONFIG_FIRMWARE_IMX8MN_OPTEE)) {
get_builtin_firmware_ext(imx8mn_bl32_bin, bl33, &bl32, &bl32_size);
get_builtin_firmware(imx8mn_bl31_bin_optee, &bl31, &bl31_size);
@@ -473,6 +495,12 @@
imx8m_setup_snvs();
imx8mq_load_bl33(bl33);
+ /* Cache DRAM for the BL32 verify + BL31/BL32 memcpy that follow. */
+ mmu_early_enable(MX8M_DDR_CSD1_BASE_ADDR,
+ imx8m_barebox_earlymem_size(32),
+ MX8M_DDR_CSD1_BASE_ADDR +
+ imx8m_barebox_earlymem_size(32) - OPTEE_SIZE);
+
if (IS_ENABLED(CONFIG_FIRMWARE_IMX8MQ_OPTEE)) {
get_builtin_firmware_ext(imx8mq_bl32_bin, bl33, &bl32, &bl32_size);
get_builtin_firmware(imx8mq_bl31_bin_optee, &bl31, &bl31_size);
next reply other threads:[~2026-06-16 14:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 14:49 Johannes Schneider [this message]
2026-06-16 14:49 ` [PATCH] crypto: sha256: PBL multi-block transform via ARMv8 Crypto Extensions Crypto Extensions Johannes Schneider
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260616144924.1614561-1-johannes.schneider@leica-geosystems.com \
--to=johannes.schneider@leica-geosystems.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox