Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(firecracker): create an FDT #408

Merged
merged 4 commits into from
Nov 19, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ jobs:
ARCH="$(uname -m)"
release_url="https://github.com/firecracker-microvm/firecracker/releases"
latest=$(basename $(curl -fsSLI -o /dev/null -w %{url_effective} ${release_url}/latest))
# FIXME: remove once 1.7.0 and above work
latest=v1.6.0
curl -L ${release_url}/download/${latest}/firecracker-${latest}-${ARCH}.tgz \
| tar -xz

Expand Down
4 changes: 2 additions & 2 deletions data/x86_64/hello_world-microvm
Git LFS file not shown
20 changes: 18 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 @@ -175,6 +178,8 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
);
}

let mut fdt = Fdt::new("firecracker").unwrap();

// Load the boot_param memory-map information
let linux_e820_entries =
unsafe { *(sptr::from_exposed_addr::<u8>(boot_params + E820_ENTRIES_OFFSET)) };
Expand Down Expand Up @@ -203,6 +208,8 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {

let entry_end = entry_start + entry_size;

fdt = fdt.memory(entry_start..entry_end).unwrap();

if start_address == 0 {
start_address = entry_start as usize;
}
Expand All @@ -220,11 +227,20 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
start_address, end_address
);

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
Loading