Device Tree - FrankBau/meta-marsboard-bsp GitHub Wiki
The Device Tree describes the hardware (chip and board level). This is especially needed for platform devices, i.e. devices which cannot be detected automatically by software (unlike plug-and-play devices like PCI or USB devices).
For a working example extending the device tree with an additional PWM function, see Using PWM.
The device tree source file for the MarS Board is originally located close to the recipe:
ls ../sources/meta-marsboard-bsp/recipes-kernel/linux/linux-marsboard-3.10.53/marsboard/ defconfig imx6q-marsboard.dts
and copied to the build folder during the bitbake -c unpack virtual/kernel
step:
build/tmp/work/marsboard-poky-linux-gnueabi/linux-marsboard/3.10.53-r0/git/arch/arm/boot/dts/imx6q-marsboard.dts
It contains nodes and node properties (key-value pairs). Nodes are hierarchically organized in a tree. At the top level you find the root node /
:
/ { model = "Marsboard i.MX6 Dual Board"; compatible = "embest,imx6q-marsboard", "fsl,imx6q"; ... };
After the root node you may find sections like
&uart1 { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_uart1_1>; status = "okay"; };
These sections add or modify properties of a node defined elsewhere, often in include files.
For example, &uart1
designates the node with label uart1
. It is defined in the include file imx6qdl.dtsi
included by imx6q.dtsi
. Those include files contain iMX6Q specific on-chip resources:
/ { ... soc { ... aips-bus@02000000 { /* AIPS1 */ ... spba-bus@02000000 { ...@ uart1: serial@02020000 { compatible = "fsl,imx6q-uart", "fsl,imx21-uart"; reg = <0x02020000 0x4000>; interrupts = <0 26 0x04>; clocks = <&clks 160>, <&clks 161>; clock-names = "ipg", "per"; dmas = <&sdma 25 4 0>, <&sdma 26 4 0>; dma-names = "rx", "tx"; status = "disabled"; }; ...
In this example one can see that the UART resources are defined in the SoC tree, but disabled because the chip vendor does not know whether and how the UART is routed on the board. So the board support packages contains board specific stuff like:
- UART1 is available on the board:
status = "okay";
(which overridesstatus = "disabled";
) - The iMX6Q UART1 function is routed to a specific group of chip pads:
pinctrl-0 = <&pinctrl_uart1_1>;
Note that &pinctrl_uart1_1
is another label which is also defined in the include file imx6qdl.dtsi
&iomuxc { ... uart1 { pinctrl_uart1_1: uart1grp-1 { fsl,pins = < MX6QDL_PAD_CSI0_DAT10__UART1_TX_DATA 0x1b0b1 MX6QDL_PAD_CSI0_DAT11__UART1_RX_DATA 0x1b0b1 >; }; }; ...
The device tree is automatically compiled with bitbake virtual/kernel
. Or, when you have opened a devshell by typing bitbake -c devshell virtual/kernel
, simply enter: make imx6q-marsboard.dtb
The output (device tree blob) is
build/tmp/work/marsboard-poky-linux-gnueabi/linux-marsboard/3.10.53-r0/build/arch/arm/boot/dts/imx6q-marsboard.dtb
which is finally copied to
build/tmp/deploy/images/marsboard/uImage-imx6q-marsboard.dtb
and put into the sd card image.
For a faster re-compile cycle open a devshell:
bitbake -c devshell virtual/kernel
and, in the devshell, enter
make imx6q-marsboard.dtb
The device tree can be displayed from the target linux shell by typing
ls /proc/device-tree
find /proc/device-tree/
etc..
(The kernel needs to be configured with CONFIG_PROC_DEVICETREE to enable this.)
- Device Trees for Dummies http://events.linuxfoundation.org/sites/events/files/slides/petazzoni-device-tree-dummies.pdf
- Device Tree Usage http://www.devicetree.org/Device_Tree_Usage
- devicetree: kernel internals and practical troubleshooting http://events.linuxfoundation.org/sites/events/files/slides/dt_internals.pdf