Skip to content

Commit

Permalink
feat(loader): add BlobInfo::compare helper function
Browse files Browse the repository at this point in the history
Add BlobInfo::compare helper function to verify if the blob is loaded
correctly.

Signed-off-by: tfx2001 <[email protected]>
  • Loading branch information
tfx2001 committed Jul 27, 2024
1 parent 51743b7 commit 06bc753
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,27 @@ impl BlobInfo {
let dst: &mut [u8] = core::slice::from_raw_parts_mut(load_address, self.length);
dst.copy_from_slice(src);
}

#[allow(unused)]
unsafe fn compare(&self, load_address: *const u8) {
let src: &[u8] = core::slice::from_raw_parts(self.start as *const _, self.length);
let dst: &[u8] = core::slice::from_raw_parts(load_address, self.length);

assert!(src.iter().enumerate().all(|(i, &x)| x == dst[i]))
}
}

pub unsafe fn load_test_kernel() {
let info: &BlobInfo = &BLOB_TABLE[0];
assert!(info.type_ == BlobType::Kernel);
assert!(info.start + info.length <= BLOB_TABLE[1].start);

info.load(SUPERVISOR_ENTRY as *mut u8);
info.load(SUPERVISOR_ENTRY as *mut _);
}

pub unsafe fn load_dtb() {
let info: &BlobInfo = &BLOB_TABLE[1];
assert!(info.type_ == BlobType::Dts);

info.load(DTB_LOAD_ADDRESS as *mut u8);
info.load(DTB_LOAD_ADDRESS as *mut _);
}

0 comments on commit 06bc753

Please sign in to comment.