Skip to content

Commit 5dce468

Browse files
committed
feat: implement decompression of Hermit images
1 parent 030515e commit 5dce468

File tree

14 files changed

+378
-29
lines changed

14 files changed

+378
-29
lines changed

Cargo.lock

Lines changed: 153 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ align-address = "0.3"
1111
allocator-api2 = { version = "0.3", default-features = false }
1212
anstyle = { version = "1", default-features = false }
1313
cfg-if = "1"
14-
hermit-entry = { version = "0.10", features = ["loader"] }
14+
hermit-entry = { version = "0.10", git = "https://github.com/fogti/hermit-entry.git", branch = "image-reader", features = ["allocator-api2", "loader"] }
15+
lazy_static = { version = "1.5.0", features = ["spin_no_std"] }
1516
log = "0.4"
1617
one-shot-mutex = "0.2"
1718
sptr = "0.3"

src/arch/aarch64/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use sptr::Strict;
2020

2121
use crate::BootInfoExt;
2222
use crate::arch::paging::*;
23-
use crate::os::CONSOLE;
23+
use crate::os::{CONSOLE, ExtraBootInfo};
2424

2525
unsafe extern "C" {
2626
static mut loader_end: u8;
@@ -110,12 +110,14 @@ pub fn find_kernel() -> &'static [u8] {
110110
}
111111
}
112112

113-
pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
113+
pub unsafe fn boot_kernel(kernel_info: LoadedKernel, extra_info: ExtraBootInfo) -> ! {
114114
let LoadedKernel {
115115
load_info,
116116
entry_point,
117117
} = kernel_info;
118118

119+
assert!(extra_info.image.is_none());
120+
119121
let dtb = unsafe {
120122
Fdt::from_ptr(sptr::from_exposed_addr(get_dtb_addr() as usize))
121123
.expect(".dtb file has invalid header")

src/arch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cfg_if::cfg_if! {
55
} else if #[cfg(target_arch = "riscv64")] {
66
mod riscv64;
77
pub use self::riscv64::*;
8-
} else if #[cfg(all(target_arch = "x86_64"))] {
8+
} else if #[cfg(target_arch = "x86_64")] {
99
mod x86_64;
1010
pub use self::x86_64::*;
1111
}

src/arch/riscv64/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use log::info;
1717
use sptr::Strict;
1818

1919
use crate::BootInfoExt;
20+
use crate::os::ExtraBootInfo;
2021

2122
fn find_kernel_linux(chosen: &FdtNode<'_, '_>) -> Option<&'static [u8]> {
2223
let initrd_start = chosen.property("linux,initrd-start")?.as_usize()?;
@@ -90,7 +91,7 @@ pub unsafe fn get_memory(memory_size: u64) -> u64 {
9091
u64::try_from(start_address).unwrap()
9192
}
9293

93-
pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
94+
pub unsafe fn boot_kernel(kernel_info: LoadedKernel, extra_info: ExtraBootInfo) -> ! {
9495
let LoadedKernel {
9596
load_info,
9697
entry_point,
@@ -118,6 +119,8 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
118119
DeviceTreeAddress::new(fdt_addr.try_into().unwrap())
119120
};
120121

122+
assert!(extra_info.image.is_none());
123+
121124
let boot_info = BootInfo {
122125
hardware_info: HardwareInfo {
123126
phys_addr_range,

src/arch/x86_64/firecracker.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use super::physicalmem::PhysAlloc;
2020
use super::{KERNEL_STACK_SIZE, SERIAL_IO_PORT, paging};
2121
use crate::BootInfoExt;
2222
use crate::fdt::Fdt;
23+
use crate::os::ExtraBootInfo;
2324

2425
unsafe extern "C" {
2526
static mut loader_end: u8;
@@ -118,7 +119,7 @@ pub fn find_kernel() -> &'static [u8] {
118119
unsafe { slice::from_raw_parts(sptr::from_exposed_addr(elf_start), elf_len) }
119120
}
120121

121-
pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
122+
pub unsafe fn boot_kernel(kernel_info: LoadedKernel, extra_info: ExtraBootInfo) -> ! {
122123
let LoadedKernel {
123124
load_info,
124125
entry_point,
@@ -172,7 +173,12 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
172173
write_bytes(stack, 0, KERNEL_STACK_SIZE.try_into().unwrap());
173174
}
174175

175-
let mut fdt = Fdt::new("firecracker").unwrap();
176+
let maybe_image = match extra_info.image {
177+
None => &[],
178+
Some(tar_image) => tar_image,
179+
};
180+
181+
let mut fdt = Fdt::new("firecracker", maybe_image).unwrap();
176182

177183
// Load the boot_param memory-map information
178184
let linux_e820_entries =

0 commit comments

Comments
 (0)