Kernelite 0.1.0
Kernelite is a minimalist, educational operating system kernel built from scratch. The project aims to recreate core components of the Linux architecture to explore the fundamentals of operating system design and hardware-software interaction.
Loading...
Searching...
No Matches
Functions
fdt.c File Reference

Implementation of Device Tree Blob (FDT) parsing and validation functions. More...

#include "fdt/fdt.h"
#include "utils/kprintf.h"
#include <libfdt.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for fdt.c:

Functions

bool check_fdt (const void *ptr)
 Check the validity of the Device Tree Blob (FDT).
 
int get_mem (const void *fdt, memory_map_t *mmap)
 Scans the FDT for memory nodes and populates the provided map.
 
int get_intc_node_offset (const void *fdt)
 Retrieves a pointer to the interrupt controller node in the FDT.
 
bool fdt_is_error (int offset)
 Checks if the given FDT offset represents an error.
 
char * get_compatible_string (const void *fdt, int node_offset)
 Retrieves the compatible string for a given node.
 
bool get_reg_property (const void *fdt, int node_offset, memory_map_t *reg_map)
 Retrieves the register property for a given node.
 
int get_intr_property (const void *fdt, int node_offset, interrupt_t *out_intr_array, size_t out_intr_array_len)
 Retrieves the interrupt property for a given node.
 
int get_nodes_by_compatible (const void *fdt, const char *compatible, int *out_node_offsets, size_t out_node_offsets_len)
 Finds all nodes in the FDT matching a given "compatible" string.
 

Detailed Description

Implementation of Device Tree Blob (FDT) parsing and validation functions.

Validates the FDT header, extracts memory map entries, and exposes kernel helpers for consuming device tree data.

Author
Abhin Parekadan Jose
Date
2026-05-16

Function Documentation

◆ check_fdt()

bool check_fdt ( const void *  ptr)

Check the validity of the Device Tree Blob (FDT).

Parameters
ptrPointer to the FDT in memory.
Returns
true if the FDT is valid, false otherwise.

◆ fdt_is_error()

bool fdt_is_error ( int  offset)

Checks if the given FDT offset represents an error.

Parameters
offsetThe FDT offset to check.
Returns
true if the offset is an error code, false otherwise.

◆ get_compatible_string()

char * get_compatible_string ( const void *  fdt,
int  node_offset 
)

Retrieves the compatible string for a given node.

Parameters
fdtPointer to the FDT header in memory.
node_offsetOffset of the node for which to retrieve the compatible string.
Returns
Pointer to the compatible string, or NULL if not found.

◆ get_intc_node_offset()

int get_intc_node_offset ( const void *  fdt)

Retrieves a pointer to the interrupt controller node in the FDT.

Parameters
fdtPointer to the FDT header in memory.
Returns
Offset of the interrupt controller node, or a negative libfdt error code if not found.

◆ get_intr_property()

int get_intr_property ( const void *  fdt,
int  node_offset,
interrupt_t out_intr_array,
size_t  out_intr_array_len 
)

Retrieves the interrupt property for a given node.

Parameters
fdtPointer to the FDT header in memory.
node_offsetOffset of the node for which to retrieve the interrupt property.
out_intr_arrayArray to be populated with the parsed interrupt specifiers.
out_intr_array_lenNumber of elements available in out_intr_array.
Returns
The number of interrupt entries parsed (capped at out_intr_array_len), or a negative libfdt error code on failure.

◆ get_mem()

int get_mem ( const void *  fdt,
memory_map_t mmap 
)

Scans the FDT for memory nodes and populates the provided map.

This function searches the FDT for nodes with device_type = "memory", respects the root node's #address-cells and #size-cells, and handles both 32-bit and 64-bit address formats.

Parameters
fdtPointer to the FDT header in memory.
mmapPointer to a memory_map_t structure to be populated.
Returns
0 on success, or a negative libfdt error code on failure.

◆ get_nodes_by_compatible()

int get_nodes_by_compatible ( const void *  fdt,
const char *  compatible,
int *  out_node_offsets,
size_t  out_node_offsets_len 
)

Finds all nodes in the FDT matching a given "compatible" string.

Parameters
fdtPointer to the FDT header in memory.
compatibleCompatible string to search for.
out_node_offsetsArray to be populated with the offsets of matching nodes.
out_node_offsets_lenNumber of elements available in out_node_offsets.
Returns
The number of matching nodes found (capped at out_node_offsets_len), or a negative libfdt error code on failure.

◆ get_reg_property()

bool get_reg_property ( const void *  fdt,
int  node_offset,
memory_map_t reg_map 
)

Retrieves the register property for a given node.

Parameters
fdtPointer to the FDT header in memory.
node_offsetOffset of the node for which to retrieve the register property.
reg_mapPointer to a memory_map_t structure to be populated with register information.
Returns
true if the register property is found and successfully parsed, false otherwise.