pub fn create_bootinfo_from_fdt(
cpu_id: usize,
relocated_fdt_addr: usize,
) -> BootInfoExpand description
Create BootInfo from FDT data
This function creates a comprehensive BootInfo structure by extracting essential system information from the Flattened Device Tree (FDT). It serves as the bridge between FDT-based boot protocols and the kernel’s unified boot interface.
§Architecture Compatibility
This function is architecture-agnostic and can be used by any architecture that uses FDT for hardware description:
- RISC-V: Primary boot protocol
- ARM/AArch32: Standard boot method
- AArch64: Alternative to UEFI
- PowerPC: Traditional FDT usage
- Other architectures: Any FDT-capable platform
§Boot Information Extraction
The function extracts the following information from FDT:
- Memory Layout: DRAM size and location from
/memorynode - Usable Memory: Calculates available memory excluding kernel image
- Initramfs: Relocates and provides access to initial filesystem
- Command Line: Extracts bootargs from
/chosennode - Device Source: Creates FDT-based device source reference
§Memory Management
The function performs automatic memory management:
- DRAM Discovery: Parses memory nodes to find total system memory
- Kernel Exclusion: Calculates usable memory starting after kernel image
- Initramfs Relocation: Moves initramfs to safe memory location
- Memory Area Updates: Adjusts usable memory to account for relocations
§Initramfs Handling
If initramfs is present in the FDT /chosen node:
- Automatically relocates to prevent overlap with kernel heap
- Updates usable memory area to exclude relocated initramfs
- Provides relocated address in BootInfo for VFS initialization
§Arguments
cpu_id- ID of the current CPU/Hart performing bootrelocated_fdt_addr- Physical address of the relocated FDT in memory
§Returns
A complete BootInfo structure containing all essential boot parameters
extracted from the FDT, ready for use by start_kernel().
§Panics
This function will panic if:
- FDT manager is not properly initialized
- Required memory nodes are missing from FDT
- Memory layout is invalid or corrupted
§Example
// Called from architecture-specific boot code
let bootinfo = create_bootinfo_from_fdt(hartid, relocated_fdt_area.start);
start_kernel(&bootinfo);