From a9bb416c822d20c1b94fb7b2bfab282d25e11125 Mon Sep 17 00:00:00 2001 From: Ian McIntyre Date: Wed, 11 Feb 2026 16:29:27 -0500 Subject: Preload RAM for ECC ciphers Testing shows that we must blow fuses in order to activate either ECC engine. Once the fuse is blown, NXP's boot ROM will enable the ECC engine. So by the time the reset handler is running, ECC may already be enabled. The 32-bit copy loops won't work for initializing ITCM and OCRAM. Since these bus widths are 64-bit and the ECC is computed over 64 bits, these 32 bit accesses result in a read-modify-write (RMW) on the underlying interface. If these RAM regions aren't already initialized, we'll fail an ECC check; the read in RMW compares bogus RAM contents against a bogus ECC. This seems to dramatically slow down initialization, or stall it (I've seen the CPU spinning in the boot ROM). If we listen to NXP and use 64-bit writes to preload ECC-protected RAM regions, the 32-bit copy loops will work as expected. Note that we can still issue 64-bit accesses towards DTCM; they're scattered across the two 32-bit interfaces. There's an NXP whitepaper [1] describing that. Once TCM ECC is enabled, we need to tell the TCM interfaces to RMW smaller accesses. Otherwise, we won't generate correct ciphers. We also might need to retry operations if there was a correction by the RAM controller. We can perform these with predicated instructions. Tested on an 1010EVK, where I used the debugger to show the control registers weren't touched; and tested on the 1170EVK, with the same approach showing the expected set bits. [1]: https://www.nxp.com/docs/en/white-paper/CORTEXM7WP.pdf [2]: https://www.nxp.com/docs/en/application-note/AN13204.pdf --- tests/inspect_elf.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') diff --git a/tests/inspect_elf.rs b/tests/inspect_elf.rs index 654c632..d3c5ae1 100644 --- a/tests/inspect_elf.rs +++ b/tests/inspect_elf.rs @@ -266,6 +266,12 @@ fn imxrt1010evk() { binary.fcb().unwrap() ); assert_eq!(binary.flexram_config().unwrap(), 0b11_10_0101); + assert_eq!(binary.symbol_value("__sitcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__eitcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__sdtcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__edtcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__socram").unwrap(), 0); + assert_eq!(binary.symbol_value("__eocram").unwrap(), 0); let ivt = binary.ivt().unwrap(); assert_eq!(ivt.magic_header, 0x402000D1); @@ -380,6 +386,13 @@ fn imxrt1010evk_ram() { let binary = ImxrtBinary::new(&elf, &contents); + assert_eq!(binary.symbol_value("__sitcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__eitcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__sdtcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__edtcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__socram").unwrap(), 0); + assert_eq!(binary.symbol_value("__eocram").unwrap(), 0); + let stack = binary.section(".stack").unwrap(); assert_eq!( Section { @@ -495,6 +508,12 @@ fn baseline_teensy4( binary.flexram_config().unwrap(), 0b11111111_101010101010101010101010 ); + assert_eq!(binary.symbol_value("__sitcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__eitcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__sdtcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__edtcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__socram").unwrap(), 0); + assert_eq!(binary.symbol_value("__eocram").unwrap(), 0); let ivt = binary.ivt().unwrap(); assert_eq!(ivt.magic_header, 0x402000D1); @@ -735,6 +754,12 @@ fn imxrt1170evk_cm7() { binary.fcb().unwrap() ); assert_eq!(binary.flexram_config().unwrap(), 0xFFAAFFAA); + assert_eq!(binary.symbol_value("__sitcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__eitcm").unwrap(), 0x4_0000); + assert_eq!(binary.symbol_value("__sdtcm").unwrap(), 0x2000_0000); + assert_eq!(binary.symbol_value("__edtcm").unwrap(), 0x2004_0000); + assert_eq!(binary.symbol_value("__socram").unwrap(), 0x2024_0000); + assert_eq!(binary.symbol_value("__eocram").unwrap(), 0x2034_0000); let ivt = binary.ivt().unwrap(); assert_eq!(ivt.magic_header, 0x402000D1); @@ -856,6 +881,13 @@ fn imxrt1170evk_cm7_nonboot() { assert!(binary.fcb().is_err()); assert_eq!(binary.flexram_config().unwrap(), 0xFFAAFFAA); + assert_eq!(binary.symbol_value("__sitcm").unwrap(), 0); + assert_eq!(binary.symbol_value("__eitcm").unwrap(), 0x4_0000); + assert_eq!(binary.symbol_value("__sdtcm").unwrap(), 0x2000_0000); + assert_eq!(binary.symbol_value("__edtcm").unwrap(), 0x2004_0000); + assert_eq!(binary.symbol_value("__socram").unwrap(), 0x2024_0000); + assert_eq!(binary.symbol_value("__eocram").unwrap(), 0x2034_0000); + assert!( binary.ivt().is_err(), "Non boot image still contains boot IVT" -- cgit v1.2.3