Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion xspiloader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ cortex-m = { workspace = true }
cortex-m-rt = { workspace = true }
panic-probe = { workspace = true }

neotron-loader = "0.1.0"
# Required for ELF payloads build with Rust 1.89
# https://github.com/Neotron-Compute/neotron-loader/pull/2
neotron-loader = { git = "https://github.com/Neotron-Compute/neotron-loader", rev = "ab92cecd8a458044aef30b39c87112244deb69c6" }
16 changes: 7 additions & 9 deletions xspiloader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,27 +247,25 @@ async fn load_elf(
};

// Attempt to load PT_LOAD segments
if ph.p_type() == neotron_loader::ProgramHeader::PT_LOAD {
if ph.p_type() == neotron_loader::ProgramHeader::PT_LOAD
&& ph.p_filesz() > 0
{
info!(
"loading 0x{:x} len 0x{:x} from 0x{:x}",
ph.p_paddr(),
ph.p_memsz(),
ph.p_filesz(),
ph.p_offset()
);
// Flush in case it faults
log::logger().flush();

if !valid_dest(ph.p_paddr(), ph.p_memsz()) {
if !valid_dest(ph.p_paddr(), ph.p_filesz()) {
error!("Invalid dest");
return Err(());
}

if ph.p_memsz() == 0 {
continue;
}

let (foff, addr, sz) = if ph.p_paddr() != 0 {
(ph.p_offset(), ph.p_paddr(), ph.p_memsz())
(ph.p_offset(), ph.p_paddr(), ph.p_filesz())
} else {
// Rust disallows NULL pointers, which is unfortunate given
// 0x0 is the start of ITCM where reset vectors can go.
Expand All @@ -288,7 +286,7 @@ async fn load_elf(
);
}

(ph.p_offset() + 1, ph.p_paddr() + 1, ph.p_memsz() - 1)
(ph.p_offset() + 1, ph.p_paddr() + 1, ph.p_filesz() - 1)
};

let dest = (addr as usize) as *mut u8;
Expand Down