From eb47674359ea27cc5e7824a234067491ff01ab13 Mon Sep 17 00:00:00 2001 From: Ian McIntyre Date: Wed, 26 Nov 2025 09:22:06 -0500 Subject: Let users change name of included device.x file Alternate PAC designs might describe the device file with a custom / chip specific name. This change lets users specify which linker script they're using. --- CHANGELOG.md | 5 +++++ src/host.rs | 28 +++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dd5d73..0ae56f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ Establish a 32 byte reservation at the start of ITCM where instructions are never placed. This reduces the total capacity of ITCM by 32 bytes on nearly all MCUs, except the 1180. +Provide a `RuntimeBuilder::device_script_name` method to change the name of +the device linker script that's included in the runtime. By default, the name +remains `device.x`. The name only matters if the "device" crate feature is +enabled. + ### FlexRAM bank layouts The runtime builder lets users specify the _layout_, or assignment, of FlexRAM diff --git a/src/host.rs b/src/host.rs index 17ab626..a4f572e 100644 --- a/src/host.rs +++ b/src/host.rs @@ -229,7 +229,7 @@ impl EnvOverride { /// # Default values /// /// The example below demonstrates the default `RuntimeBuilder` memory placements, -/// stack sizes, and heap sizes. +/// stack sizes, heap sizes, and additional configurations. /// /// ``` /// use imxrt_rt::{Family, RuntimeBuilder, Memory}; @@ -250,6 +250,8 @@ impl EnvOverride { /// b.stack_size(8 * 1024); // 8 KiB stack. /// b.heap(Memory::Dtcm); // Heap in DTCM... /// b.heap_size(0); // ...but no space given to the heap. +/// b.linker_script_name("imxrt-link.x"); +/// b.device_script_name("device.x"); /// /// assert_eq!(b, RuntimeBuilder::from_flexspi(family, FLASH_SIZE)); /// ``` @@ -346,9 +348,11 @@ pub struct RuntimeBuilder { heap_size: EnvOverride, flash_opts: Option, linker_script_name: String, + device_script_name: String, } const DEFAULT_LINKER_SCRIPT_NAME: &str = "imxrt-link.x"; +const DEFAULT_DEVICE_SCRIPT_NAME: &str = "device.x"; impl RuntimeBuilder { /// Creates a runtime that can execute and load contents from @@ -375,6 +379,7 @@ impl RuntimeBuilder { flexspi: FlexSpi::family_default(family), }), linker_script_name: DEFAULT_LINKER_SCRIPT_NAME.into(), + device_script_name: DEFAULT_DEVICE_SCRIPT_NAME.into(), } } @@ -411,6 +416,7 @@ impl RuntimeBuilder { flexspi: FlexSpi::family_default(family), }), linker_script_name: DEFAULT_LINKER_SCRIPT_NAME.into(), + device_script_name: DEFAULT_DEVICE_SCRIPT_NAME.into(), } } @@ -431,6 +437,7 @@ impl RuntimeBuilder { heap_size: EnvOverride::new(0), flash_opts: None, linker_script_name: DEFAULT_LINKER_SCRIPT_NAME.into(), + device_script_name: DEFAULT_DEVICE_SCRIPT_NAME.into(), } } @@ -544,6 +551,20 @@ impl RuntimeBuilder { self } + /// Set the name of the device's linker file that's included by the + /// runtime's linker script. + /// + /// By default, the device PAC is expected to place a file named + /// `device.x` on the linker search path. The runtime's linker script + /// includes that `device.x` file when the "device" crate feature is + /// enabled. + /// + /// This method lets you change the name of that included file. + pub fn device_script_name(&mut self, name: &str) -> &mut Self { + self.device_script_name = name.into(); + self + } + /// Commit the runtime configuration. /// /// `build()` ensures that the generated linker script is available to the @@ -624,8 +645,9 @@ impl RuntimeBuilder { write_ram_memory_map(writer, self.family, &self.flexram_layout)?; } - #[cfg(feature = "device")] - writeln!(writer, "INCLUDE device.x")?; + if cfg!(feature = "device") { + writeln!(writer, "INCLUDE {}", self.device_script_name)?; + } // Keep these alias names in sync with the primary linker script. // The main linker script uses these region aliases for placing -- cgit v1.2.3