mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
tools: elf: allow loading files from &[u8]
Instead of assuming everything is a file or a path, allow loading ELF files from u8 slices. This will enable us to create images with `include_bytes!()`. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
c50314d4a8
commit
46cd5e7098
1 changed files with 13 additions and 1 deletions
|
|
@ -56,7 +56,11 @@ impl fmt::Display for MiniElfSection {
|
|||
write!(
|
||||
f,
|
||||
"Section {:13} {:6} bytes loading into {:08x}..{:08x} flags: {:?}",
|
||||
self.name, self.size, self.virt, self.virt + self.size, self.flags
|
||||
self.name,
|
||||
self.size,
|
||||
self.virt,
|
||||
self.virt + self.size,
|
||||
self.flags
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -133,6 +137,10 @@ pub fn read_program<P: AsRef<Path>>(filename: P) -> Result<ProgramDescription, E
|
|||
fi.read_to_end(&mut b)
|
||||
.map_err(ElfReadError::ReadFileError)?;
|
||||
}
|
||||
process_program(&b)
|
||||
}
|
||||
|
||||
pub fn process_program(b: &[u8]) -> Result<ProgramDescription, ElfReadError> {
|
||||
let elf = ElfFile::new(&b).map_err(|x| ElfReadError::ParseElfError(x))?;
|
||||
let entry_point = elf.header.pt2.entry_point() as u32;
|
||||
let mut program_data = Cursor::new(Vec::new());
|
||||
|
|
@ -276,6 +284,10 @@ pub fn read_minielf<P: AsRef<Path>>(filename: P) -> Result<MiniElf, ElfReadError
|
|||
fi.read_to_end(&mut b)
|
||||
.map_err(ElfReadError::ReadFileError)?;
|
||||
}
|
||||
process_minielf(&b)
|
||||
}
|
||||
|
||||
pub fn process_minielf(b: &[u8]) -> Result<MiniElf, ElfReadError> {
|
||||
let elf = ElfFile::new(&b).map_err(|x| ElfReadError::ParseElfError(x))?;
|
||||
let entry_point = elf.header.pt2.entry_point() as u32;
|
||||
let mut program_data = Cursor::new(Vec::new());
|
||||
|
|
|
|||
Loading…
Reference in a new issue