mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
align sections of the MiniElf
Sections of the MiniElf are now aligned as required by the source ELF requirements. This is required for direct-mapping with XIP. the overhead is just a few bytes every couple of programs, so it's a small price to pay for XIP.
This commit is contained in:
parent
a6b46c6275
commit
43c73c0d6c
2 changed files with 26 additions and 3 deletions
|
|
@ -18,7 +18,7 @@ env_logger = "0.7.1"
|
|||
log = "0.4.14"
|
||||
pem = "0.8.3"
|
||||
svd2utra = "0.1.11"
|
||||
xmas-elf = "0.7.0"
|
||||
xmas-elf = "0.9.0"
|
||||
xous-semver = "0.1.2"
|
||||
|
||||
[[bin]]
|
||||
|
|
|
|||
|
|
@ -310,7 +310,8 @@ pub fn process_minielf(b: &[u8]) -> Result<MiniElf, ElfReadError> {
|
|||
|
||||
// This keeps a running offset of where data is getting copied.
|
||||
let mut program_offset = 0;
|
||||
for s in elf.section_iter() {
|
||||
let mut section_iter = elf.section_iter().peekable();
|
||||
while let Some(s) = section_iter.next() {
|
||||
let mut flags = MiniElfFlags::NONE;
|
||||
let name = s.get_name(&elf).unwrap_or("<<error>>");
|
||||
|
||||
|
|
@ -332,7 +333,7 @@ pub fn process_minielf(b: &[u8]) -> Result<MiniElf, ElfReadError> {
|
|||
debug!(" offset: {:08x}", s.offset());
|
||||
debug!(" size: {:?}", s.size());
|
||||
debug!(" link: {:?}", s.link());
|
||||
let size = s.size();
|
||||
let mut size = s.size();
|
||||
|
||||
let no_copy = s.get_type() == Ok(ShType::NoBits);
|
||||
|
||||
|
|
@ -363,6 +364,16 @@ pub fn process_minielf(b: &[u8]) -> Result<MiniElf, ElfReadError> {
|
|||
// If this section gets copied, add it to the program stream.
|
||||
if s.get_type() != Ok(ShType::NoBits) {
|
||||
let section_data = s.raw_data(&elf);
|
||||
let pad_amount = if let Some(next_section) = section_iter.peek() {
|
||||
if section_data.len() % next_section.align() as usize != 0 {
|
||||
next_section.align() as usize - (section_data.len() % next_section.align() as usize)
|
||||
} else {
|
||||
0
|
||||
}
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
debug!(
|
||||
"Section start: {:02x} {:02x} {:02x} {:02x} going into offset 0x{:08x}",
|
||||
section_data[0], section_data[1], section_data[2], section_data[3], program_offset
|
||||
|
|
@ -374,6 +385,18 @@ pub fn process_minielf(b: &[u8]) -> Result<MiniElf, ElfReadError> {
|
|||
.write(section_data)
|
||||
.map_err(ElfReadError::WriteSectionError)?;
|
||||
program_offset += section_data.len() as u64;
|
||||
|
||||
if pad_amount != 0 {
|
||||
let pad = vec![0u8; pad_amount];
|
||||
program_data.write(&pad)
|
||||
.map_err(ElfReadError::WriteSectionError)?;
|
||||
program_offset += pad_amount as u64;
|
||||
size += pad_amount as u64;
|
||||
}
|
||||
} else {
|
||||
// we leave the nocopy sections mis-aligned.
|
||||
// They don't exist in the file, they are just zero'd on spec.
|
||||
// This works so long as the nocopy sections are at the end of the MiniElf.
|
||||
}
|
||||
sections.push(MiniElfSection {
|
||||
virt: s.address() as u32,
|
||||
|
|
|
|||
Loading…
Reference in a new issue