Skip to content

Commit

Permalink
feat(firecracker): create an FDT
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Nov 17, 2024
1 parent e159762 commit c8fad18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
21 changes: 19 additions & 2 deletions src/arch/x86_64/firecracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use core::ptr::write_bytes;
use core::{ptr, slice};

use align_address::Align;
use hermit_entry::boot_info::{BootInfo, HardwareInfo, PlatformInfo, SerialPortBase};
use hermit_entry::boot_info::{
BootInfo, DeviceTreeAddress, HardwareInfo, PlatformInfo, SerialPortBase,
};
use hermit_entry::elf::LoadedKernel;
use hermit_entry::fc::{
BOOT_FLAG_OFFSET, CMD_LINE_PTR_OFFSET, CMD_LINE_SIZE_OFFSET, E820_ENTRIES_OFFSET,
Expand All @@ -15,6 +17,7 @@ use x86_64::structures::paging::{PageSize, PageTableFlags, Size2MiB, Size4KiB};

use super::physicalmem::PhysAlloc;
use super::{paging, KERNEL_STACK_SIZE, SERIAL_IO_PORT};
use crate::fdt::Fdt;
use crate::BootInfoExt;

extern "C" {
Expand Down Expand Up @@ -220,11 +223,25 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
start_address, end_address
);

let mut fdt = Fdt::new("firecracker")
.unwrap()
.memory(start_address as u64..end_address as u64)
.unwrap();

if let Some(command_line) = command_line {
fdt = fdt.bootargs(command_line).unwrap();
}

let fdt = fdt.finish().unwrap();

let device_tree =
DeviceTreeAddress::new(u64::try_from(fdt.leak().as_ptr().expose_addr()).unwrap());

let boot_info = BootInfo {
hardware_info: HardwareInfo {
phys_addr_range: start_address as u64..end_address as u64,
serial_port_base: SerialPortBase::new(SERIAL_IO_PORT),
device_tree: None,
device_tree,
},
load_info,
platform_info: PlatformInfo::LinuxBootParams {
Expand Down
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ mod macros;

mod arch;
mod bump_allocator;
#[cfg(any(target_os = "uefi", all(target_arch = "x86_64", not(feature = "fc"))))]
#[cfg(any(target_os = "uefi", target_arch = "x86_64"))]
mod fdt;
mod log;
mod os;

#[cfg(any(
target_os = "uefi",
all(target_arch = "x86_64", target_os = "none", not(feature = "fc"))
))]
#[cfg(any(target_os = "uefi", all(target_arch = "x86_64", target_os = "none")))]
extern crate alloc;

trait BootInfoExt {
Expand Down

0 comments on commit c8fad18

Please sign in to comment.