knaxuslearn · build · ship

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

  1. Week 58 h
    • The kernel in Yocto: linux-yocto, config fragments, menuconfig and diffconfig, 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

  2. 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 virt tree annotated, and your knaxus,gw-demo node added and loaded

  3. 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

  4. 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 compatible check (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

  1. Strip the kernel until something breaks, then restore it. Done when you can name the option that broke it and the symptom.
  2. Add a second node with a property your driver reads as an integer array. Done when dmesg shows the values and an out-of-range value makes the probe fail cleanly.
  3. (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

RepoWhat to readWeek
bootlin/training-materialsThe embedded Linux and kernel labs and slides for configuration, device tree and drivers5 to 7
rauc/meta-rauc-communitymeta-rauc-qemuarm: the machine, U-Boot script and image settings you will reuse8

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.

  1. What does the kernel use to match a driver to a device tree node?
    The compatible property, compared with the driver's match table.
  2. 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.
  3. What happens if a driver's probe returns an error?
    The device stays unbound, the error is logged, and the rest of the system continues (-EPROBE_DEFER is the exception: the kernel retries later, when a dependency appears).
  4. How would you find which option adds a driver you do not want?
    Search the Kconfig tree for the driver name and read what selects or depends on it (menuconfig search shows the dependencies).
  5. 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 /chosen node); change them in the U-Boot environment or boot script.