AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
fdt.c File Reference

Reading the devicetree that the boot loader passes (a flattened one, an FDT) into the kernel's struct boot: the RAM (/memory's reg property), the initrd (/chosen's linux,initrd-start and linux,initrd-end), and the command line (/chosen's bootargs). More...

#include <core/system.h>
#include <core/string.h>
#include <boot/boot.h>
#include <mm/mm.h>

Go to the source code of this file.

Data Structures

struct  fdt_header
 The FDT's header (big-endian). More...

Macros

#define FDT_MAGIC   0xD00DFEED
#define FDT_BEGIN_NODE   1
#define FDT_END_NODE   2
#define FDT_PROP   3
#define FDT_NOP   4
#define FDT_END   9
#define MMAP_MAX   16

Functions

static uint32_t be32 (const void *p)
 Reads a big-endian 32-bit number.
static uint64_t cells (const void *p, int cells)
 Reads cells big-endian 32-bit cells at p as one number.
struct boot * fdt_boot (uintptr_t dtb)
 Reads the boot loader's devicetree into a struct boot.

Variables

static struct boot boot
static mmap_t mmap [MMAP_MAX]
static module_t modules [1]
static char cmdline [1024]

Detailed Description

Reading the devicetree that the boot loader passes (a flattened one, an FDT) into the kernel's struct boot: the RAM (/memory's reg property), the initrd (/chosen's linux,initrd-start and linux,initrd-end), and the command line (/chosen's bootargs).

References: [1] - Devicetree Specification, release 0.4, chapter 5 (Flattened Devicetree Format)

The blob is big-endian: a header, then the structure (tokens: a node begins, a property, a node ends), then the strings (the properties' names). Only what the kernel needs is read. The root's #address-cells and #size-cells say how many 32-bit cells an address and a size take.

Definition in file fdt.c.

Macro Definition Documentation

◆ FDT_BEGIN_NODE

#define FDT_BEGIN_NODE   1

Definition at line 24 of file fdt.c.

Referenced by fdt_boot().

◆ FDT_END

#define FDT_END   9

Definition at line 28 of file fdt.c.

◆ FDT_END_NODE

#define FDT_END_NODE   2

Definition at line 25 of file fdt.c.

Referenced by fdt_boot().

◆ FDT_MAGIC

#define FDT_MAGIC   0xD00DFEED

Definition at line 23 of file fdt.c.

Referenced by fdt_boot().

◆ FDT_NOP

#define FDT_NOP   4

Definition at line 27 of file fdt.c.

Referenced by fdt_boot().

◆ FDT_PROP

#define FDT_PROP   3

Definition at line 26 of file fdt.c.

Referenced by fdt_boot().

◆ MMAP_MAX

#define MMAP_MAX   16

Definition at line 63 of file fdt.c.

Referenced by fdt_boot().

Function Documentation

◆ be32()

uint32_t be32 ( const void * p)
inlinestatic

Reads a big-endian 32-bit number.

Definition at line 45 of file fdt.c.

References be32().

Referenced by be32(), cells(), and fdt_boot().

◆ cells()

uint64_t cells ( const void * p,
int cells )
static

Reads cells big-endian 32-bit cells at p as one number.

Definition at line 52 of file fdt.c.

References be32(), and cells().

Referenced by cells(), fdt_boot(), and vcs_read().

◆ fdt_boot()

struct boot * fdt_boot ( uintptr_t dtb)

Reads the boot loader's devicetree into a struct boot.

If there is no devicetree there, the struct boot is empty.

Parameters
dtbthe devicetree's physical address
Returns
the struct boot (static)

Definition at line 78 of file fdt.c.

References be32(), cells(), boot::cmdline, cmdline, FDT_BEGIN_NODE, fdt_boot(), FDT_END_NODE, FDT_MAGIC, FDT_NOP, FDT_PROP, fdt_header::magic, memcpy(), MIN, boot::mmap, mmap, boot::mmap_count, MMAP_MAX, MMAP_USABLE, boot::modules, modules, boot::modules_count, fdt_header::off_dt_strings, fdt_header::off_dt_struct, PHYS2VIRT, printk(), and boot::total_mem.

Referenced by aarch64_init(), and fdt_boot().

Variable Documentation

◆ boot

struct boot boot
static

Definition at line 66 of file fdt.c.

◆ cmdline

char cmdline[1024]
static

Definition at line 69 of file fdt.c.

Referenced by fdt_boot().

◆ mmap

mmap_t mmap[MMAP_MAX]
static

Definition at line 67 of file fdt.c.

Referenced by fdt_boot().

◆ modules

module_t modules[1]
static

Definition at line 68 of file fdt.c.

Referenced by fdt_boot().