From a0dd354bdc299d7d089bd4ed143f6a213852a905 Mon Sep 17 00:00:00 2001 From: Ian McIntyre Date: Thu, 3 Apr 2025 16:44:15 -0400 Subject: Add section for boot ROM reservations The boot ROM is allowed to use allocations of OCRAM as scratch space. If you interact with the boot ROM -- using it to interact with FlexSPI, for instance -- then you cannot also use these OCRAM regions. See the system boot chapter in the reference manual for more info. The boot ROM typically reserves the start of OCRAM. The size varies by chip. This commit describes a new section, .bootrom_reservation, at the start of OCRAM. Users are encouraged to place a MaybeUninit buffer that's sized for your ROM's requirements. If users don't place anything in this section, then the new directive is a no-op. On the other hand, the section is defined before other RAM regions, so that it takes precedence over other sections users might want to place in OCRAM. Tested using the runtime's test suite. I'm testing with the Teensy 4 binary, since the test suite can support features in this build. The updated test suite shows that the linker will place the boot ROM reservation before placing the stack, suggesting that we're respecting section priority. --- src/host/imxrt-link.x | 5 +++++ src/lib.rs | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'src') diff --git a/src/host/imxrt-link.x b/src/host/imxrt-link.x index 7fcd76c..f07601b 100644 --- a/src/host/imxrt-link.x +++ b/src/host/imxrt-link.x @@ -37,6 +37,11 @@ EXTERN(__INTERRUPTS); /* `static` variable similar to `__EXCEPTIONS` */ /* # Sections */ SECTIONS { + .bootrom ORIGIN(OCRAM) (NOLOAD) : + { + KEEP(*(.bootrom_reservation)); + } > OCRAM + .stack (NOLOAD) : ALIGN(8) { __estack = .; diff --git a/src/lib.rs b/src/lib.rs index ab55627..40d2789 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -176,6 +176,28 @@ //! //! With this in place, your package should be able to use the `#[exception]` macro //! exported by `imxrt-rt`. See the `imxrt-rt` package examples for a demonstration. +//! +//! # Extras +//! +//! The runtime package has extra features to support i.MX RT programs. +//! +//! ## Reserving OCRAM for NXP's boot ROM +//! +//! If you're using NXP's boot ROM, you may need to reserve a region at the start of +//! OCRAM for API calls. You can achieve that by placing a buffer into `.bootrom_reservation`. +//! You're responsible for sizing this buffer depending chip's ROM. +//! +//! Here's an example of how to reserve the first 48KiB of OCRAM for the boot ROM. +//! The example assumes the boot ROM requires at most 48KiB. +//! +//! ``` +//! # use core::mem::MaybeUninit; +//! #[unsafe(link_section = ".bootrom_reservation")] +//! static ROM_RESERVATION: MaybeUninit<[u8; 48 * 1024]> = MaybeUninit::uninit(); +//! ``` +//! +//! Without this reservation, this program is allowed to use the lower addresses of +//! OCRAM without concern for the boot ROM. #![cfg_attr(all(target_arch = "arm", target_os = "none"), no_std)] -- cgit v1.2.3