mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-13 15:26:48 +00:00
[RISCV] Fix panic when initramfs not exists
This commit is contained in:
parent
7d5a2b7a79
commit
8b69aba0b8
@ -35,20 +35,12 @@ fn init_kernel_commandline(kernel_cmdline: &'static Once<KCmdlineArg>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init_initramfs(initramfs: &'static Once<&'static [u8]>) {
|
fn init_initramfs(initramfs: &'static Once<&'static [u8]>) {
|
||||||
let chosen = DEVICE_TREE.get().unwrap().find_node("/chosen").unwrap();
|
let Some((start, end)) = parse_initramfs_range() else {
|
||||||
let initrd_start = chosen
|
return;
|
||||||
.property("linux,initrd-start")
|
};
|
||||||
.unwrap()
|
|
||||||
.as_usize()
|
|
||||||
.unwrap();
|
|
||||||
let initrd_end = chosen
|
|
||||||
.property("linux,initrd-end")
|
|
||||||
.unwrap()
|
|
||||||
.as_usize()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let base_va = paddr_to_vaddr(initrd_start);
|
let base_va = paddr_to_vaddr(start);
|
||||||
let length = initrd_end - initrd_start;
|
let length = end - start;
|
||||||
initramfs.call_once(|| unsafe { core::slice::from_raw_parts(base_va as *const u8, length) });
|
initramfs.call_once(|| unsafe { core::slice::from_raw_parts(base_va as *const u8, length) });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,27 +81,24 @@ fn init_memory_regions(memory_regions: &'static Once<Vec<MemoryRegion>>) {
|
|||||||
regions.push(MemoryRegion::kernel());
|
regions.push(MemoryRegion::kernel());
|
||||||
|
|
||||||
// Add the initramfs region.
|
// Add the initramfs region.
|
||||||
let chosen = DEVICE_TREE.get().unwrap().find_node("/chosen").unwrap();
|
if let Some((start, end)) = parse_initramfs_range() {
|
||||||
let initrd_start = chosen
|
regions.push(MemoryRegion::new(
|
||||||
.property("linux,initrd-start")
|
start,
|
||||||
.unwrap()
|
end - start,
|
||||||
.as_usize()
|
MemoryRegionType::Module,
|
||||||
.unwrap();
|
));
|
||||||
let initrd_end = chosen
|
}
|
||||||
.property("linux,initrd-end")
|
|
||||||
.unwrap()
|
|
||||||
.as_usize()
|
|
||||||
.unwrap();
|
|
||||||
let length = initrd_end - initrd_start;
|
|
||||||
regions.push(MemoryRegion::new(
|
|
||||||
initrd_start,
|
|
||||||
length,
|
|
||||||
MemoryRegionType::Module,
|
|
||||||
));
|
|
||||||
|
|
||||||
memory_regions.call_once(|| non_overlapping_regions_from(regions.as_ref()));
|
memory_regions.call_once(|| non_overlapping_regions_from(regions.as_ref()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_initramfs_range() -> Option<(usize, usize)> {
|
||||||
|
let chosen = DEVICE_TREE.get().unwrap().find_node("/chosen").unwrap();
|
||||||
|
let initrd_start = chosen.property("linux,initrd-start")?.as_usize()?;
|
||||||
|
let initrd_end = chosen.property("linux,initrd-end")?.as_usize()?;
|
||||||
|
Some((initrd_start, initrd_end))
|
||||||
|
}
|
||||||
|
|
||||||
/// The entry point of the Rust code portion of Asterinas.
|
/// The entry point of the Rust code portion of Asterinas.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn riscv_boot(_hart_id: usize, device_tree_paddr: usize) -> ! {
|
pub extern "C" fn riscv_boot(_hart_id: usize, device_tree_paddr: usize) -> ! {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user