Roadmaps / Embedded Linux / Phase 2
Phase 2 of 4 · Study weeks 5-8
Kernel, device tree and a driver
This phase lets you describe hardware to the kernel and write a driver that binds to it, so you can read a vendor's patches without fear. Read the kernel documentation on device tree usage and the Bootlin kernel training slides as you go.
Topics every week
- Week 58 h
- The kernel in Yocto:
linux-yocto, config fragments,menuconfiganddiffconfig, what to turn off and what that breaks
Hand inA config fragment and a table of removed options with image size and boot-time change
- The kernel in Yocto:
- Week 68 h
- Device tree: nodes,
compatible, properties,dtc - dump the QEMU tree (
-machine virt,dumpdtb=virt.dtb), add your node to the decompiled source and boot with-dtb
Hand inThe decompiled
virttree annotated, and yourknaxus,gw-demonode added and loaded - Device tree: nodes,
- Week 78 h
- A platform driver (first 2 hours: build the Bootlin hello module):
of_match_table, probe and remove, reading a property, an out-of-tree module recipe
Hand inThe driver bound to your node, logging its property, built by a recipe
- A platform driver (first 2 hours: build the Bootlin hello module):
- Week 88 h
- Boot with U-Boot: environment, boot script, kernel command line, boot time breakdown
- debugging a kernel that does not boot
Hand inCheckpoint 2, built in four steps: the fragment; the node; the driver; the seeded wrong
compatiblecheck (then the captures)
Note: -dtb is for a first look. In the product the device tree must ship inside the slot (for example in the boot partition or a FIT image written with the root), so it updates and rolls back with the slot; record where yours lives in ADR-3. Week 7 is the steepest week: if the driver overruns, spill into Week 8's first sitting and keep the checkpoint captures for the second.
Practice projects
- Strip the kernel until something breaks, then restore it. Done when you can name the option that broke it and the symptom.
- Add a second node with a property your driver reads as an integer array. Done when
dmesgshows the values and an out-of-range value makes the probe fail cleanly. - (Optional for a fresher) Break the boot with a bad command line and read the failure from the serial console. Done when you can say which stage failed and how you knew.
GitHub repos to study
| Repo | What to read | Week |
|---|---|---|
| bootlin/training-materials | The embedded Linux and kernel labs and slides for configuration, device tree and drivers | 5 to 7 |
| rauc/meta-rauc-community | meta-rauc-qemuarm: the machine, U-Boot script and image settings you will reuse | 8 |
Milestone checkpoint
Apply the fragment, add the node and the driver, and run the seeded wrong match. Done when the Checkpoint 2 row passes. Evidence: the fragment, the option table with size and boot-time numbers, the dmesg capture of the probe, the check script and its failure on the seeded fault, ADR-2 (a config fragment against a full defconfig: what you gain in upgrade effort and what you lose in visibility).
Check yourself
Answer each question in your head first, then open it to check.
What does the kernel use to match a driver to a device tree node?
Thecompatibleproperty, compared with the driver's match table.Why use a config fragment and not a full saved config?
A fragment records only your changes, so a new kernel release rebases cleanly and a reviewer sees what you changed on top of the default.What happens if a driver's
probereturns an error?The device stays unbound, the error is logged, and the rest of the system continues (-EPROBE_DEFERis the exception: the kernel retries later, when a dependency appears).How would you find which option adds a driver you do not want?
Search the Kconfig tree for the driver name and read whatselects or depends on it (menuconfigsearch shows the dependencies).What does U-Boot pass to the kernel, and how can you change it?
The kernel image, the device tree and a command line (passed in the tree's/chosennode); change them in the U-Boot environment or boot script.