Skip to content

Commit c8ddcde

Browse files
committed
tool: add support for split program image
Signed-off-by: Nick Spinale <nick@nickspinale.com>
1 parent 751ed08 commit c8ddcde

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

tool/microkit/src/elf.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// SPDX-License-Identifier: BSD-2-Clause
55
//
66

7+
use std::borrow::Cow;
78
use std::fs;
89
use std::path::Path;
910
use std::collections::HashMap;
@@ -144,9 +145,21 @@ pub struct ElfFile {
144145

145146
impl ElfFile {
146147
pub fn from_path(path: &Path) -> Result<ElfFile, String> {
148+
Self::from_split_paths(path, None)
149+
}
150+
151+
pub fn from_split_paths(path: &Path, path_for_symbols: Option<&Path>) -> Result<ElfFile, String> {
147152
let reader = ElfFileReader::from_path(path)?;
153+
let reader_for_symbols = match path_for_symbols {
154+
Some(path_for_symbols) => {
155+
Cow::Owned(ElfFileReader::from_path(path_for_symbols)?)
156+
}
157+
None => {
158+
Cow::Borrowed(&reader)
159+
}
160+
};
148161
let segments = reader.segments();
149-
let symbols = reader.symbols()?;
162+
let symbols = reader_for_symbols.symbols()?;
150163
Ok(ElfFile {
151164
word_size: reader.word_size(),
152165
entry: reader.file_header().entry,
@@ -193,6 +206,7 @@ impl ElfFile {
193206
}
194207
}
195208

209+
#[derive(Clone)]
196210
struct ElfFileReader<'a> {
197211
path: &'a Path,
198212
bytes: Vec<u8>,

tool/microkit/src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,12 @@ fn build_system(kernel_config: &Config,
700700
for pd in &system.protection_domains {
701701
match get_full_path(&pd.program_image, search_paths) {
702702
Some(path) => {
703-
let elf = ElfFile::from_path(&path).unwrap();
703+
let path_for_symbols = pd.program_image_for_symbols.as_ref().map(|path_suffix| {
704+
get_full_path(path_suffix, search_paths).ok_or_else(|| {
705+
format!("unable to find program image for symbols: '{}'", path_suffix.display())
706+
})
707+
}).transpose()?;
708+
let elf = ElfFile::from_split_paths(&path, path_for_symbols.as_deref()).unwrap();
704709
pd_elf_files.push(elf);
705710
},
706711
None => return Err(format!("unable to find program image: '{}'", pd.program_image.display()))

tool/microkit/src/sysxml.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ pub struct ProtectionDomain {
152152
pub pp: bool,
153153
pub passive: bool,
154154
pub program_image: PathBuf,
155+
pub program_image_for_symbols: Option<PathBuf>,
155156
pub maps: Vec<SysMap>,
156157
pub irqs: Vec<SysIrq>,
157158
pub setvars: Vec<SysSetVar>,
@@ -303,6 +304,7 @@ impl ProtectionDomain {
303304
let mut child_pds = Vec::new();
304305

305306
let mut program_image = None;
307+
let mut program_image_for_symbols = None;
306308
let mut virtual_machine = None;
307309

308310
// Default to minimum priority
@@ -323,13 +325,15 @@ impl ProtectionDomain {
323325

324326
match child.tag_name().name() {
325327
"program_image" => {
326-
check_attributes(xml_sdf, &child, &["path"])?;
328+
check_attributes(xml_sdf, &child, &["path", "path_for_symbols"])?;
327329
if program_image.is_some() {
328330
return Err(value_error(xml_sdf, node, "program_image must only be specified once".to_string()));
329331
}
330332

331333
let program_image_path = checked_lookup(xml_sdf, &child, "path")?;
332334
program_image = Some(Path::new(program_image_path).to_path_buf());
335+
336+
program_image_for_symbols = child.attribute("path_for_symbols").map(PathBuf::from);
333337
},
334338
"map" => {
335339
let map = SysMap::from_xml(xml_sdf, &child, true)?;
@@ -415,6 +419,7 @@ impl ProtectionDomain {
415419
pp,
416420
passive,
417421
program_image: program_image.unwrap(),
422+
program_image_for_symbols,
418423
maps,
419424
irqs,
420425
setvars,

0 commit comments

Comments
 (0)