
Recall first from Wiring interrupts and clocks
- The interrupt parent determines how Linux interprets each interrupts entry.
- The classic GIC binding uses class-relative numbers that Linux translates into GIC hardware interrupt IDs.
- Clock and reset specifiers identify resources in the namespaces of their respective providers.
Choose nodes for the board hardware
3 min readMost board work reuses a handful of standard node types instead of writing new drivers. This lesson answers which common nodes cover regulators, buttons and LEDs, and the naming and unit-address rules dtc checks.
The BeagleBone Black has user LEDs driven by GPIOs. Its Linux device tree describes them with a gpio-leds parent and a child for each LED. The parent identifies the common interface. Each child describes a particular LED connection and can specify its initial state or default trigger. When you read a board schematic, identify who controls the signal before choosing the binding. The GPIO LED binding applies to LEDs wired for GPIO control. LEDs attached to a separate controller use that controller’s binding.
A fixed regulator describes a supply with a fixed output voltage. In DTS, write compatible = "regulator-fixed";. The phrase fixed-regulator names the kind of hardware. The compatible string uses the words in the order regulator-fixed. Give the supply a regulator-name and set regulator-min-microvolt and regulator-max-microvolt to the same output voltage in microvolts. A consumer connects to it through the *-supply property defined by the consumer’s binding. The reference points to the regulator node, so the connection remains explicit even when several rails have the same voltage.
A fixed voltage rail can have a GPIO-controlled enable line. Fixed describes the output voltage, so a rail can still be switched on and off. Describe the enable and its polarity according to the regulator binding and schematic. If the rail has an upstream supply described in the tree, the fixed regulator binding provides vin-supply for that relationship. Add regulator-always-on when the board requires the rail to stay enabled. Check those details separately. An output voltage, an enable polarity, and a requirement to keep the rail on describe three different facts.
Use gpio-keys for a switch or push button connected to a GPIO and used as a Linux input. Give the parent compatible = "gpio-keys"; and add one child per key. Each child describes its GPIO in gpios and its input event code in linux,code. Choose a code defined for the intended function, such as KEY_ENTER for an Enter key. If pressing the button pulls a normally high line low, describe it with GPIO_ACTIVE_LOW. Check how the line is held at its idle level. The polarity flag defines which level counts as asserted. A pull-up or pull-down comes from the circuit or pin configuration.
Use gpio-leds for GPIO-controlled LEDs. Give the parent compatible = "gpio-leds"; and each child its own gpios property. Determine polarity from the circuit, including any transistor between the GPIO and LED. An active-low LED is logically on when its control GPIO is low. You can set default-state = "off"; to request an initially off LED when Linux configures it. The spelling leds-gpio is the Linux platform driver name and the basename of drivers/leds/leds-gpio.c in the kernel source. Use gpio-leds in the compatible property.
Name the node and derive its unit address
3 min readRead user_leds: leds { as a DTS label followed by a node name. user_leds lets other DTS code refer to this node as &user_leds. leds is the name used to form the node’s path. The compatible property inside the node identifies the interface described by the binding. These three identifiers serve different readers. The DTS author uses the label for references, the tree uses the node name in paths, and Linux uses compatible strings for tasks such as matching devices to drivers. Some bindings also define a label property inside a node. That property has the meaning specified by the binding and is distinct from the DTS label before the colon.
Choose a generic node name that describes the device class and follows the binding, such as leds, serial, or regulator-3v3 for a particular supply when its binding permits that form. Linux DTS style uses lowercase letters, digits, and hyphens in the base node name. Labels can use underscores. For example, main_supply can be a label while regulator-main is the node name. The compiler accepts a broader set of node-name characters than kernel style recommends, and a binding can specify a particular name or pattern. Use the binding to choose the name even when several spellings compile.
The suffix after @ in a node name, written according to the rules of the parent bus normally represents the first address in reg. For a memory-mapped device, use the first address expressed in the parent bus’s address space. If a bus translates addresses through ranges, the unit address still uses the child-side address. On an I²C bus, use the device’s bus address. Use lowercase hexadecimal for ordinary hexadecimal unit addresses, omit the 0x prefix, and omit leading zeroes. Some buses define a special address format, so follow the parent binding when it specifies one.
Read reg using the parent’s #address-cells and #size-cells. With multiple address cells, the full first address may occupy several cells. With multiple register ranges, the first address determines the suffix. A GPIO specifier contains a controller reference and controller-defined cells, so a GPIO line number in gpios gives a key or LED child no unit address. Give such children distinct names allowed by their binding. Each sibling must have a unique full node name, and a bus can also require its addressed children to use distinct unit addresses.
A simple-bus node describes a simple memory-mapped bus whose children can be enumerated from the tree. It provides the address and size cell counts for its children and describes address translation through ranges. An empty ranges; declares that child and parent addresses are identical for the mapping. A missing ranges property has different semantics, so keep the empty property when the binding and hardware call for an identity mapping. SoC includes often already describe the relevant buses. Put an addressed child under its actual bus and keep board-level GPIO consumers and fixed rails in the locations their bindings and the existing tree call for.
The root-level chosen and memory nodes from the board skeleton keep their existing roles. /chosen holds boot configuration such as stdout-path and has no unit address. A memory node has device_type = "memory"; and uses reg to describe RAM ranges. Its memory@... name uses the first RAM base address described by that node, formatted according to the root address rules. Use the board’s actual RAM layout or the boot firmware’s established mechanism for supplying it.
Build with W=1 and read the diagnostics
4 min readBuild through the kernel’s Kbuild system so includes, preprocessor macros, and the kernel’s dtc checks are applied to the complete tree. From a configured Linux source tree (for example after make ARCH=arm multi_v7_defconfig) on an x86 Ubuntu host, these commands build the BeagleBone Black DTB. Building a DTB needs only the host C preprocessor and the kernel's own dtc, so no cross-compiler is required for this target. Run the second command after a successful build to confirm that the DTB exists.
make ARCH=arm W=1 ti/omap/am335x-boneblack.dtb
test -s arch/arm/boot/dts/ti/omap/am335x-boneblack.dtb
W=1 is a Kbuild setting that exposes additional checks, including address-related checks that the normal kernel build can suppress. For a self-contained DTS without C preprocessor includes, the standalone command is dtc -I dts -O dtb -o check.dtb check.dts. Use that command for small diagnostic examples. Use the kernel build for board sources that depend on the kernel’s include files and macros.
Here is what a real run showed on a Linux 6.12 tree (the counts on your tree will differ). Without W=1 the BeagleBone Black DTB built with no warnings. With W=1 the same build printed 13 warnings, all from the SoC includes, for example Warning (simple_bus_reg) and Warning (unit_address_vs_reg). After renaming the led2 child in am335x-bone-common.dtsi to led2@0, the W=1 build added one more line: Warning (unit_address_vs_reg): /leds/led2@0: node has a unit name, but no reg or ranges property. That is the pattern to look for: the baseline warnings stay, and your edit adds a new one.
Start with the first relevant diagnostic and read the node path in the message. An included file can define the parent’s cell counts while the board DTS adds a child with an incorrectly sized reg. Fixing the property in the child may clear several later messages, because some checks depend on the results of earlier ones. Use the check name to decide what to inspect.
unit_address_vs_regchecks the presence of a suffix against the node’s addressing properties. For example,led@0with noregor nonemptyrangescan trigger it. Remove an invented suffix from an unaddressed child. For an addressed device, verify that the binding calls forregand derive the suffix from its actual address.simple_bus_regcan flag a disagreement between the unit address and the expected address for a child of asimple-bus. Check the parent’s address format and compare the suffix with the first address in the child’sreg. A suffix and a property can both be present while their values disagree.reg_formatpoints to a malformedregproperty, such as an entry whose cell count fails to match the parent’s address and size cell counts.avoid_default_addr_sizepoints to reliance on default cell counts for addressing. Check the parent definition against the bus binding before adding or changing any cell counts.duplicate_node_namesis an error for duplicate full sibling names in the compiled tree.duplicate_labelis an error when the same label identifies different objects.unique_unit_addresscan warn when siblings with different names use the same unit address. For addressed siblings, check whether both descriptions refer to the same hardware and whether their addresses match the parent bus.
A compiler error normally stops DTB generation. A warning can leave a DTB on disk, so inspect the diagnostics even when the command succeeds. If a warning also appears in the unmodified tree under the same build options, record that baseline and check whether your edit introduces any new warnings. Compiler checks cover tree structure and selected addressing rules. Binding schemas additionally check details such as required properties and accepted compatible strings. You still need the schematic to establish wiring facts such as GPIO polarity.
Before moving on, pick a node you would add for a board signal. Explain which schematic detail determines its binding, which determines its polarity or address, and which name the binding expects. The next lesson, From schematic to a validated device tree, puts those decisions together and checks the resulting board description.
Key takeaways
- gpio-leds is the device tree compatible string. leds-gpio is the Linux driver name.
- A fixed regulator uses the regulator-fixed compatible string and equal minimum and maximum voltage constraints.
- A unit address follows the parent bus rules and normally matches the first address in reg.
- Kernel Kbuild accepts W=1. A successful DTB build can still report dtc warnings.
Reflect
- Explain to a colleague, in two sentences: select standard bindings for fixed supplies, GPIO buttons, GPIO LEDs, and memory-mapped buses.
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- Kernel documentationLinux and the Devicetree: platform identification, runtime configuration, and device population
- Kernel documentationDevicetree Sources (DTS) Coding Style
- Kernel documentationWriting Devicetree Bindings in json-schema
- Kernel documentationLED handling under Linux: LED device naming
Official documentation first. Links checked when the lesson was published.