Skip to content

Commit

Permalink
Merge pull request #1279 from hermit-os/fdt-print
Browse files Browse the repository at this point in the history
feat(x86_64): print FDT
  • Loading branch information
stlankes authored Jun 13, 2024
2 parents bdffeca + fc69e02 commit 50cd0c8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ build-time = "0.1.3"
cfg-if = "1"
crossbeam-utils = { version = "0.8", default-features = false }
dyn-clone = "1.0"
fdt = "0.1"
fdt = { version = "0.1", features = ["pretty-printing"] }
free-list = "0.3"
hashbrown = { version = "0.14", default-features = false }
hermit-entry = { version = "0.10", features = ["kernel"] }
Expand Down
11 changes: 6 additions & 5 deletions src/arch/x86_64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use core::num::NonZeroU64;
use core::ptr;
use core::sync::atomic::{AtomicPtr, AtomicU32, Ordering};

use fdt::Fdt;
use hermit_entry::boot_info::{BootInfo, PlatformInfo, RawBootInfo};
use hermit_sync::InterruptSpinMutex;
use x86::controlregs::{cr0, cr0_write, cr4, Cr0};
Expand Down Expand Up @@ -81,11 +82,11 @@ pub fn get_mbinfo() -> Option<NonZeroU64> {
}
}

pub fn get_fdt() -> Option<usize> {
boot_info()
.hardware_info
.device_tree
.map(|fdt| fdt.get() as usize)
pub fn get_fdt() -> Option<Fdt<'static>> {
boot_info().hardware_info.device_tree.map(|fdt| {
let ptr = ptr::with_exposed_provenance(fdt.get().try_into().unwrap());
unsafe { Fdt::from_ptr(ptr).unwrap() }
})
}

#[cfg(feature = "smp")]
Expand Down
3 changes: 1 addition & 2 deletions src/arch/x86_64/mm/physicalmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const KVM_32BIT_GAP_SIZE: usize = 768 << 20;
const KVM_32BIT_GAP_START: usize = KVM_32BIT_MAX_MEM_SIZE - KVM_32BIT_GAP_SIZE;

fn detect_from_fdt() -> Result<(), ()> {
let fdt_addr = get_fdt().ok_or(())?;
let fdt = unsafe { fdt::Fdt::from_ptr(fdt_addr as *const u8).unwrap() };
let fdt = get_fdt().ok_or(())?;

let mems = fdt.find_all_nodes("/memory");
let all_regions = mems.map(|m| m.reg().unwrap().next().unwrap());
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ fn boot_processor_main() -> ! {
info!("Welcome to Hermit {}", env!("CARGO_PKG_VERSION"));
info!("Kernel starts at {:p}", env::get_base_address());

#[cfg(target_arch = "x86_64")]
if let Some(fdt) = kernel::get_fdt() {
info!("FDT:\n{fdt:#?}");
}

extern "C" {
static mut __bss_start: u8;
}
Expand Down

0 comments on commit 50cd0c8

Please sign in to comment.