pub struct MemoryConfig {
pub regions: Vec<MemoryRegion>,
}Expand description
Parsed memory configuration from a linker script (memory.x).
Fields§
§regions: Vec<MemoryRegion>Implementations§
Source§impl MemoryConfig
impl MemoryConfig
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, String>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self, String>
Parse a memory.x file at the given path.
The file format follows GNU LD linker script syntax:
MEMORY
{
FLASH : ORIGIN = 0x08000000, LENGTH = 64K
RAM : ORIGIN = 0x20000000, LENGTH = 20K
}Examples found in repository?
examples/demo.rs (line 8)
3fn main() {
4 let memory_x = "./memory.x";
5 let elf_path = "./stm32dome";
6
7 println!("[INFO] Parsing memory.x: {}", memory_x);
8 let config = MemoryConfig::from_file(memory_x).expect("Failed to parse memory.x");
9
10 if let Some(flash) = config.flash() {
11 println!("[INFO] FLASH: origin=0x{:08X}, length={}", flash.origin, flash.length);
12 }
13 if let Some(ram) = config.ram() {
14 println!("[INFO] RAM: origin=0x{:08X}, length={}", ram.origin, ram.length);
15 }
16
17 println!();
18 println!("[INFO] Analyzing ELF: {}", elf_path);
19 let usage = analyze_elf(elf_path, &config).expect("Failed to analyze ELF");
20
21 println!("[INFO] FLASH used: {} bytes", usage.flash_used);
22 println!("[INFO] RAM used: {} bytes", usage.ram_used);
23 println!();
24
25 println!("{}", format_report(&usage, 30));
26 println!();
27 println!("[INFO] Firmware: {}", elf_path);
28}Sourcepub fn find(&self, name: &str) -> Option<&MemoryRegion>
pub fn find(&self, name: &str) -> Option<&MemoryRegion>
Find a region by name (case-insensitive).
Sourcepub fn flash(&self) -> Option<&MemoryRegion>
pub fn flash(&self) -> Option<&MemoryRegion>
Get the FLASH region, if present.
Examples found in repository?
examples/demo.rs (line 10)
3fn main() {
4 let memory_x = "./memory.x";
5 let elf_path = "./stm32dome";
6
7 println!("[INFO] Parsing memory.x: {}", memory_x);
8 let config = MemoryConfig::from_file(memory_x).expect("Failed to parse memory.x");
9
10 if let Some(flash) = config.flash() {
11 println!("[INFO] FLASH: origin=0x{:08X}, length={}", flash.origin, flash.length);
12 }
13 if let Some(ram) = config.ram() {
14 println!("[INFO] RAM: origin=0x{:08X}, length={}", ram.origin, ram.length);
15 }
16
17 println!();
18 println!("[INFO] Analyzing ELF: {}", elf_path);
19 let usage = analyze_elf(elf_path, &config).expect("Failed to analyze ELF");
20
21 println!("[INFO] FLASH used: {} bytes", usage.flash_used);
22 println!("[INFO] RAM used: {} bytes", usage.ram_used);
23 println!();
24
25 println!("{}", format_report(&usage, 30));
26 println!();
27 println!("[INFO] Firmware: {}", elf_path);
28}Sourcepub fn ram(&self) -> Option<&MemoryRegion>
pub fn ram(&self) -> Option<&MemoryRegion>
Get the RAM region, if present.
Examples found in repository?
examples/demo.rs (line 13)
3fn main() {
4 let memory_x = "./memory.x";
5 let elf_path = "./stm32dome";
6
7 println!("[INFO] Parsing memory.x: {}", memory_x);
8 let config = MemoryConfig::from_file(memory_x).expect("Failed to parse memory.x");
9
10 if let Some(flash) = config.flash() {
11 println!("[INFO] FLASH: origin=0x{:08X}, length={}", flash.origin, flash.length);
12 }
13 if let Some(ram) = config.ram() {
14 println!("[INFO] RAM: origin=0x{:08X}, length={}", ram.origin, ram.length);
15 }
16
17 println!();
18 println!("[INFO] Analyzing ELF: {}", elf_path);
19 let usage = analyze_elf(elf_path, &config).expect("Failed to analyze ELF");
20
21 println!("[INFO] FLASH used: {} bytes", usage.flash_used);
22 println!("[INFO] RAM used: {} bytes", usage.ram_used);
23 println!();
24
25 println!("{}", format_report(&usage, 30));
26 println!();
27 println!("[INFO] Firmware: {}", elf_path);
28}Trait Implementations§
Source§impl Clone for MemoryConfig
impl Clone for MemoryConfig
Source§fn clone(&self) -> MemoryConfig
fn clone(&self) -> MemoryConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MemoryConfig
impl RefUnwindSafe for MemoryConfig
impl Send for MemoryConfig
impl Sync for MemoryConfig
impl Unpin for MemoryConfig
impl UnsafeUnpin for MemoryConfig
impl UnwindSafe for MemoryConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more