Kernel Device Tree Processing

Learning Rust with Songs · 3:19

Listen on 93

Lyrics

[Verse 1]
When the bootloader hands control away
The kernel starts its parsing day
Device tree blob sits in memory
A flattened structure, binary

The magic number starts the show
Version checks before we go
Each property and node defined
In linear format, all aligned

[Chorus]
Unflatten, validate, create the tree
Parse the blob to memory
Nodes and properties take their place
Device tree processing, boot's embrace
Unflatten, validate, create the tree
Linux kernel sets hardware free

[Verse 2]
Walking through the structure now
Scanning tokens, byte by byte somehow
Begin node tokens mark the start
Each device gets its counterpart

Properties follow with their names
Interrupt lines and memory claims
Compatible strings tell us how
This hardware fits the kernel's vow

[Chorus]
Unflatten, validate, create the tree
Parse the blob to memory
Nodes and properties take their place
Device tree processing, boot's embrace
Unflatten, validate, create the tree
Linux kernel sets hardware free

[Bridge]
From flat blob to living tree
Device node structs in memory
Parent child relationships restored
Sibling links and properties stored

Early init can't allocate
Bootmem serves our parser's fate
Building up the device tree
For drivers waiting patiently

[Verse 3]
Phandles link the nodes together
References that bind forever
Address cells and size cells too
Tell us how to parse values through

When the parsing phase is done
Device matching has begun
Platform bus will probe and find
Drivers for each device kind

[Chorus]
Unflatten, validate, create the tree
Parse the blob to memory
Nodes and properties take their place
Device tree processing, boot's embrace
Unflatten, validate, create the tree
Linux kernel sets hardware free

[Outro]
From binary blob to kernel's brain
Device tree makes hardware plain
Boot complete, the system's live
Thanks to parsing primitives

← Bootloader and Device Tree Loading | Driver Matching and Platform Devices →