Skip to content

Commit

Permalink
tool: add support for split program image
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Sep 18, 2024
1 parent 7b76df7 commit 2492fa6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
14 changes: 13 additions & 1 deletion tool/microkit/src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

use crate::util::bytes_to_struct;
use std::borrow::Cow;
use std::collections::HashMap;
use std::fs;
use std::path::Path;
Expand Down Expand Up @@ -144,9 +145,20 @@ pub struct ElfFile {

impl ElfFile {
pub fn from_path(path: &Path) -> Result<ElfFile, String> {
Self::from_split_paths(path, None)
}

pub fn from_split_paths(
path: &Path,
path_for_symbols: Option<&Path>,
) -> Result<ElfFile, String> {
let reader = ElfFileReader::from_path(path)?;
let reader_for_symbols = match path_for_symbols {
Some(path_for_symbols) => Cow::Owned(ElfFileReader::from_path(path_for_symbols)?),
None => Cow::Borrowed(&reader),
};
let segments = reader.segments();
let symbols = reader.symbols()?;
let symbols = reader_for_symbols.symbols()?;
Ok(ElfFile {
word_size: reader.word_size,
entry: reader.hdr.entry,
Expand Down
14 changes: 13 additions & 1 deletion tool/microkit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3315,7 +3315,19 @@ fn main() -> Result<(), String> {
for pd in &system.protection_domains {
match get_full_path(&pd.program_image, &search_paths) {
Some(path) => {
let elf = ElfFile::from_path(&path).unwrap();
let path_for_symbols = pd
.program_image_for_symbols
.as_ref()
.map(|path_suffix| {
get_full_path(path_suffix, &search_paths).ok_or_else(|| {
format!(
"unable to find program image for symbols: '{}'",
path_suffix.display()
)
})
})
.transpose()?;
let elf = ElfFile::from_split_paths(&path, path_for_symbols.as_deref()).unwrap();
pd_elf_files.push(elf);
}
None => {
Expand Down
8 changes: 7 additions & 1 deletion tool/microkit/src/sdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub struct ProtectionDomain {
pub passive: bool,
pub stack_size: u64,
pub program_image: PathBuf,
pub program_image_for_symbols: Option<PathBuf>,
pub maps: Vec<SysMap>,
pub irqs: Vec<SysIrq>,
pub setvars: Vec<SysSetVar>,
Expand Down Expand Up @@ -397,6 +398,7 @@ impl ProtectionDomain {
let mut child_pds = Vec::new();

let mut program_image = None;
let mut program_image_for_symbols = None;
let mut virtual_machine = None;

// Default to minimum priority
Expand All @@ -421,7 +423,7 @@ impl ProtectionDomain {

match child.tag_name().name() {
"program_image" => {
check_attributes(xml_sdf, &child, &["path"])?;
check_attributes(xml_sdf, &child, &["path", "path_for_symbols"])?;
if program_image.is_some() {
return Err(value_error(
xml_sdf,
Expand All @@ -432,6 +434,9 @@ impl ProtectionDomain {

let program_image_path = checked_lookup(xml_sdf, &child, "path")?;
program_image = Some(Path::new(program_image_path).to_path_buf());

program_image_for_symbols =
child.attribute("path_for_symbols").map(PathBuf::from);
}
"map" => {
let map = SysMap::from_xml(xml_sdf, &child, true)?;
Expand Down Expand Up @@ -567,6 +572,7 @@ impl ProtectionDomain {
passive,
stack_size,
program_image: program_image.unwrap(),
program_image_for_symbols,
maps,
irqs,
setvars,
Expand Down

0 comments on commit 2492fa6

Please sign in to comment.