Skip to main content

MemoryConfig

Struct MemoryConfig 

Source
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

Source

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}
Source

pub fn parse(content: &str) -> Result<Self, String>

Parse memory configuration from a string.

Source

pub fn find(&self, name: &str) -> Option<&MemoryRegion>

Find a region by name (case-insensitive).

Source

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}
Source

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

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.