create_bootinfo_from_fdt

Function create_bootinfo_from_fdt 

Source
pub fn create_bootinfo_from_fdt(
    cpu_id: usize,
    relocated_fdt_addr: usize,
) -> BootInfo
Expand 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 /memory node
  • Usable Memory: Calculates available memory excluding kernel image
  • Initramfs: Relocates and provides access to initial filesystem
  • Command Line: Extracts bootargs from /chosen node
  • Device Source: Creates FDT-based device source reference

§Memory Management

The function performs automatic memory management:

  1. DRAM Discovery: Parses memory nodes to find total system memory
  2. Kernel Exclusion: Calculates usable memory starting after kernel image
  3. Initramfs Relocation: Moves initramfs to safe memory location
  4. 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 boot
  • relocated_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);