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 Jul 9, 2024
1 parent 751ed08 commit c8ddcde
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
16 changes: 15 additions & 1 deletion tool/microkit/src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// SPDX-License-Identifier: BSD-2-Clause
//

use std::borrow::Cow;
use std::fs;
use std::path::Path;
use std::collections::HashMap;
Expand Down Expand Up @@ -144,9 +145,21 @@ 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.file_header().entry,
Expand Down Expand Up @@ -193,6 +206,7 @@ impl ElfFile {
}
}

#[derive(Clone)]
struct ElfFileReader<'a> {
path: &'a Path,
bytes: Vec<u8>,
Expand Down
7 changes: 6 additions & 1 deletion tool/microkit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,12 @@ fn build_system(kernel_config: &Config,
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 => return Err(format!("unable to find program image: '{}'", pd.program_image.display()))
Expand Down
7 changes: 6 additions & 1 deletion tool/microkit/src/sysxml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub struct ProtectionDomain {
pub pp: bool,
pub passive: bool,
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 @@ -303,6 +304,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 @@ -323,13 +325,15 @@ 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, node, "program_image must only be specified once".to_string()));
}

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 @@ -415,6 +419,7 @@ impl ProtectionDomain {
pp,
passive,
program_image: program_image.unwrap(),
program_image_for_symbols,
maps,
irqs,
setvars,
Expand Down

0 comments on commit c8ddcde

Please sign in to comment.