SlideShare a Scribd company logo
1 of 47
Download to read offline
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 1/47
Thomas Petazzoni 
I CTO and Embedded Linux engineer at Free Electrons 
I Embedded Linux development: kernel and driver 
development, system integration, boot time and power 
consumption optimization, consulting, etc. 
I Embedded Linux training, Linux driver development training 
and Android system development training, with materials 
freely available under a Creative Commons license. 
I http://free-electrons.com 
I Contributions 
I Kernel support for the Marvell Armada ARM SoCs from 
Marvell 
I Major contributor to Buildroot, an open-source, simple and 
fast embedded Linux build system 
I Living in Toulouse, south west of France 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 2/47
Agenda 
I User perspective: booting with the Device Tree 
I Basic Device Tree syntax and compilation 
I Simple example of Device Tree fragment 
I Overall organization of a Device Tree 
I Examples of Device Tree usage 
I General considerations about the Device Tree in Linux 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 3/47
User perspective: before the Device Tree 
I The kernel contains the entire description of the hardware. 
I The bootloader loads a single binary, the kernel image, and 
executes it. 
I uImage or zImage 
I The bootloader prepares some additional information, called 
ATAGS, which address is passed to the kernel through register 
r2 
I Contains information such as memory size and location, kernel 
command line, etc. 
I The bootloader tells the kernel on which board it is being 
booted through a machine type integer, passed in register r1. 
I U-Boot command: bootm <kernel img addr> 
I Barebox variable: bootm.image 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 4/47
User perspective: before the Device Tree 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 5/47
User perspective: booting with a Device Tree 
I The kernel no longer contains the description of the hardware, 
it is located in a separate binary: the device tree blob 
I The bootloader loads two binaries: the kernel image and the 
DTB 
I Kernel image remains uImage or zImage 
I DTB located in arch/arm/boot/dts, one per board 
I The bootloader passes the DTB address through r2. It is 
supposed to adjust the DTB with memory information, kernel 
command line, and potentially other info. 
I No more machine type. 
I U-Boot command: 
boot[mz] <kernel img addr> - <dtb addr> 
I Barebox variables: bootm.image, bootm.oftree 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 6/47
User perspective: booting with a Device Tree 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 7/47
User perspective: compatibility mode for DT booting 
I Some bootloaders have no speci
c support for the Device 
Tree, or the version used on a particular device is too old to 
have this support. 
I To ease the transition, a compatibility mechanism was added: 
CONFIG_ARM_APPENDED_DTB. 
I It tells the kernel to look for a DTB right after the kernel 
image. 
I There is no built-in Make
le rule to produce such kernel, so 
one must manually do: 
cat arch/arm/boot/zImage arch/arm/boot/dts/myboard.dtb > my-zImage 
mkimage ... -d my-zImage my-uImage 
I In addition, the additional option 
CONFIG_ARM_ATAG_DTB_COMPAT tells the kernel to read the 
ATAGS information from the bootloader, and update the DT 
using them. 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 8/47
What is the Device Tree ? 
I Quoted from the Power.org Standard for Embedded Power 
Architecture Platform Requirements (ePAPR) 
I The ePAPR speci
es a concept called a device tree to describe 
system hardware. A boot program loads a device tree into a 
client program's memory and passes a pointer to the device 
tree to the client. 
I A device tree is a tree data structure with nodes that describe 
the physical devices in a system. 
I An ePAPR-compliant device tree describes device information 
in a system that cannot be dynamically detected by a client 
program. 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 9/47
Basic Device Tree syntax 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 10/47
From source to binary 
I On ARM, all Device Tree Source
les (DTS) are for now 
located in arch/arm/boot/dts 
I .dts
les for board-level de
nitions 
I .dtsi
les for included
les, generally containing SoC-level 
de
nitions 
I A tool, the Device Tree Compiler compiles the source into a 
binary form. 
I Source code located in scripts/dtc 
I The Device Tree Blob is produced by the compiler, and is 
the binary that gets loaded by the bootloader and parsed by 
the kernel at boot time. 
I arch/arm/boot/dts/Makefile lists which DTBs should be 
generated at build time. 
dtb-$(CONFIG_ARCH_MVEBU) += armada-370-db.dtb  
armada-370-mirabox.dtb  
... 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 11/47
Exploring the DT on the target 
I In /sys/firmware/devicetree/base, there is a 
directory/
le representation of the Device Tree contents 
# ls -l /sys/firmware/devicetree/base/ 
total 0 
-r--r--r-- 1 root root 4 Jan 1 00:00 #address-cells 
-r--r--r-- 1 root root 4 Jan 1 00:00 #size-cells 
drwxr-xr-x 2 root root 0 Jan 1 00:00 chosen 
drwxr-xr-x 3 root root 0 Jan 1 00:00 clocks 
-r--r--r-- 1 root root 34 Jan 1 00:00 compatible 
[...] 
-r--r--r-- 1 root root 1 Jan 1 00:00 name 
drwxr-xr-x 10 root root 0 Jan 1 00:00 soc 
I If dtc is available on the target, possible to "unpack" the 
Device Tree using: 
dtc -I fs /sys/firmware/devicetree/base 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 12/47
A simple example, DT side 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 13/47
A simple example, driver side (1) 
The compatible string used to bind a device with the driver 
static struct of_device_id mxs_auart_dt_ids[] = { 
{ 
.compatible = "fsl,imx28-auart", 
.data = &mxs_auart_devtype[IMX28_AUART] 
}, { 
.compatible = "fsl,imx23-auart", 
.data = &mxs_auart_devtype[IMX23_AUART] 
}, { /* sentinel */ } 
}; 
MODULE_DEVICE_TABLE(of, mxs_auart_dt_ids); 
[...] 
static struct platform_driver mxs_auart_driver = { 
.probe = mxs_auart_probe, 
.remove = mxs_auart_remove, 
.driver = { 
.name = "mxs-auart", 
.of_match_table = mxs_auart_dt_ids, 
}, 
}; 
Code from drivers/tty/serial/mxs-auart.c 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 14/47
A simple example, driver side (2) 
I of_match_device allows to get the matching entry in the 
mxs_auart_dt_ids table. 
I Useful to get the driver-speci
c data
eld, typically used to 
alter the behavior of the driver depending on the variant of 
the detected device. 
static int mxs_auart_probe(struct platform_device *pdev) 
{ 
const struct of_device_id *of_id = 
of_match_device(mxs_auart_dt_ids, &pdev->dev); 
if (of_id) { 
/* Use of_id->data here */ 
[...] 
} 
[...] 
} 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 15/47
A simple example, driver side (3) 
I Getting a reference to the clock 
I described by the clocks property 
I s->clk = clk_get(&pdev->dev, NULL); 
I Getting the I/O registers resource 
I described by the reg property 
I r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 
I Getting the interrupt 
I described by the interrupts property 
I s->irq = platform_get_irq(pdev, 0); 
I Get a DMA channel 
I described by the dmas property 
I s->rx_dma_chan = dma_request_slave_channel(s->dev, "rx"); 
I s->tx_dma_chan = dma_request_slave_channel(s->dev, "tx"); 
I Check some custom property 
I struct device_node *np = pdev->dev.of_node; 
I if (of_get_property(np, "fsl,uart-has-rtscts", NULL)) 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 16/47
Device Tree inclusion 
I Device Tree
les are not monolithic, they can be split in 
several
les, including each other. 
I .dtsi
les are included
les, while .dts
les are
nal Device 
Trees 
I Typically, .dtsi will contain de
nition of SoC-level 
information (or sometimes de
nitions common to several 
almost identical boards). 
I The .dts
le contains the board-level information. 
I The inclusion works by overlaying the tree of the including
le over the tree of the included
le. 
I Inclusion using the DT operator /include/, or since a few 
kernel releases, the DTS go through the C preprocessor, so 
#include is recommended. 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 17/47
Device Tree inclusion example 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 18/47
Device Tree inclusion example (2) 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 19/47
Concept of Device Tree binding 
I Quoting the ePAPR: 
I This chapter contains requirements, known as bindings, for 
how speci
c types and classes of devices are represented 
in the device tree. 
I The compatible property of a device node describes the 
speci
c binding (or bindings) to which the node complies. 
I When creating a new device tree representation for a device, a 
binding should be created that fully describes the 
required properties and value of the device. This set of 
properties shall be suciently descriptive to provide device 
drivers with needed attributes of the device. 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 20/47
Documentation of Device Tree bindings 
I All Device Tree bindings recognized by the kernel are 
documented in Documentation/devicetree/bindings. 
I Each binding documentation described which properties are 
accepted, with which values, which properties are mandatory 
vs. optional, etc. 
I All new Device Tree bindings must be reviewed by the Device 
Tree maintainers, by being posted to 
devicetree@vger.kernel.org. This ensures correctness 
and consistency across bindings. 
OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS 
M: Rob Herring rob.herring@calxeda.com 
M: Pawel Moll pawel.moll@arm.com 
M: Mark Rutland mark.rutland@arm.com 
M: Stephen Warren swarren@wwwdotorg.org 
M: Ian Campbell ijc+devicetree@hellion.org.uk 
L: devicetree@vger.kernel.org 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 21/47
Device Tree binding documentation example 
* Freescale MXS Application UART (AUART) 
Required properties: 
- compatible : Should be fsl,soc-auart. The supported SoCs include 
imx23 and imx28. 
- reg : Address and length of the register set for the device 
- interrupts : Should contain the auart interrupt numbers 
- dmas: DMA specifier, consisting of a phandle to DMA controller node 
and AUART DMA channel ID. 
Refer to dma.txt and fsl-mxs-dma.txt for details. 
- dma-names: rx for RX channel, tx for TX channel. 
Example: 
auart0: serial@8006a000 { 
compatible = fsl,imx28-auart, fsl,imx23-auart; 
reg = 0x8006a000 0x2000; 
interrupts = 112; 
dmas = dma_apbx 8, dma_apbx 9; 
dma-names = rx, tx; 
}; 
Note: Each auart port should have an alias correctly numbered in aliases 
node. 
Example: 
[...] 
Documentation/devicetree/bindings/tty/serial/fsl-mxs-auart.txt 
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 22/47

More Related Content

What's hot

U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013Wave Digitech
 
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardKernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardAnne Nicolas
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device driversHoucheng Lin
 
Yocto Project Open Source Build System and Collaboration Initiative
Yocto Project Open Source Build System and Collaboration InitiativeYocto Project Open Source Build System and Collaboration Initiative
Yocto Project Open Source Build System and Collaboration InitiativeMarcelo Sanz
 
Linux booting procedure
Linux booting procedureLinux booting procedure
Linux booting procedureDhaval Kaneria
 
Browsing Linux Kernel Source
Browsing Linux Kernel SourceBrowsing Linux Kernel Source
Browsing Linux Kernel SourceMotaz Saad
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchlinuxlab_conf
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBshimosawa
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)shimosawa
 
Embedded_Linux_Booting
Embedded_Linux_BootingEmbedded_Linux_Booting
Embedded_Linux_BootingRashila Rr
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal BootloaderSatpal Parmar
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageKernel TLV
 

What's hot (20)

U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardKernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
 
BeagleBone Black Booting Process
BeagleBone Black Booting ProcessBeagleBone Black Booting Process
BeagleBone Black Booting Process
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
Yocto Project Open Source Build System and Collaboration Initiative
Yocto Project Open Source Build System and Collaboration InitiativeYocto Project Open Source Build System and Collaboration Initiative
Yocto Project Open Source Build System and Collaboration Initiative
 
Linux booting procedure
Linux booting procedureLinux booting procedure
Linux booting procedure
 
Browsing Linux Kernel Source
Browsing Linux Kernel SourceBrowsing Linux Kernel Source
Browsing Linux Kernel Source
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
Linux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKBLinux Kernel Booting Process (1) - For NLKB
Linux Kernel Booting Process (1) - For NLKB
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
 
Embedded_Linux_Booting
Embedded_Linux_BootingEmbedded_Linux_Booting
Embedded_Linux_Booting
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
Linux Device Tree
Linux Device TreeLinux Device Tree
Linux Device Tree
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
Linux Internals - Interview essentials - 1.0
Linux Internals - Interview essentials - 1.0Linux Internals - Interview essentials - 1.0
Linux Internals - Interview essentials - 1.0
 

Similar to Device Tree for Dummies (ELC 2014)

Petazzoni device-tree-dummies
Petazzoni device-tree-dummiesPetazzoni device-tree-dummies
Petazzoni device-tree-dummiesAlex Cherny
 
Kernel Recipes 2013 - ARM support in the Linux kernel
Kernel Recipes 2013 - ARM support in the Linux kernelKernel Recipes 2013 - ARM support in the Linux kernel
Kernel Recipes 2013 - ARM support in the Linux kernelAnne Nicolas
 
Writing Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxWriting Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxRajKumar Rampelli
 
Kernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using BuildrootKernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using BuildrootAnne Nicolas
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel DevelopmentPriyank Kapadia
 
A character device typically transfers data to and from a user appli.pdf
A character device typically transfers data to and from a user appli.pdfA character device typically transfers data to and from a user appli.pdf
A character device typically transfers data to and from a user appli.pdfaptind
 
A character device typically transfers data to and from a user appli.pdf
A character device typically transfers data to and from a user appli.pdfA character device typically transfers data to and from a user appli.pdf
A character device typically transfers data to and from a user appli.pdfaptind
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modulesdibyajyotig
 
The sysfs Filesystem
The sysfs FilesystemThe sysfs Filesystem
The sysfs FilesystemJeff Yana
 
Kernel init
Kernel initKernel init
Kernel initgowell
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]mcganesh
 
EMBEDDED SYSTEMS -UNIT-III-TSK-PROF.ECE-ACET.ppt
EMBEDDED SYSTEMS -UNIT-III-TSK-PROF.ECE-ACET.pptEMBEDDED SYSTEMS -UNIT-III-TSK-PROF.ECE-ACET.ppt
EMBEDDED SYSTEMS -UNIT-III-TSK-PROF.ECE-ACET.pptswarna pasupuleti
 

Similar to Device Tree for Dummies (ELC 2014) (20)

Petazzoni device-tree-dummies
Petazzoni device-tree-dummiesPetazzoni device-tree-dummies
Petazzoni device-tree-dummies
 
Kernel Recipes 2013 - ARM support in the Linux kernel
Kernel Recipes 2013 - ARM support in the Linux kernelKernel Recipes 2013 - ARM support in the Linux kernel
Kernel Recipes 2013 - ARM support in the Linux kernel
 
Notes for LX0-101 Linux
Notes for LX0-101 Linux Notes for LX0-101 Linux
Notes for LX0-101 Linux
 
Writing Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxWriting Character driver (loadable module) in linux
Writing Character driver (loadable module) in linux
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Kernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using BuildrootKernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using Buildroot
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
 
A character device typically transfers data to and from a user appli.pdf
A character device typically transfers data to and from a user appli.pdfA character device typically transfers data to and from a user appli.pdf
A character device typically transfers data to and from a user appli.pdf
 
A character device typically transfers data to and from a user appli.pdf
A character device typically transfers data to and from a user appli.pdfA character device typically transfers data to and from a user appli.pdf
A character device typically transfers data to and from a user appli.pdf
 
Device drivers tsp
Device drivers tspDevice drivers tsp
Device drivers tsp
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
 
Device Drivers
Device DriversDevice Drivers
Device Drivers
 
The sysfs Filesystem
The sysfs FilesystemThe sysfs Filesystem
The sysfs Filesystem
 
Kernel init
Kernel initKernel init
Kernel init
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]
 
Studienarb linux kernel-dev
Studienarb linux kernel-devStudienarb linux kernel-dev
Studienarb linux kernel-dev
 
Linux filesystemhierarchy
Linux filesystemhierarchyLinux filesystemhierarchy
Linux filesystemhierarchy
 
EMBEDDED SYSTEMS -UNIT-III-TSK-PROF.ECE-ACET.ppt
EMBEDDED SYSTEMS -UNIT-III-TSK-PROF.ECE-ACET.pptEMBEDDED SYSTEMS -UNIT-III-TSK-PROF.ECE-ACET.ppt
EMBEDDED SYSTEMS -UNIT-III-TSK-PROF.ECE-ACET.ppt
 

Recently uploaded

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Recently uploaded (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Device Tree for Dummies (ELC 2014)

  • 1. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 1/47
  • 2. Thomas Petazzoni I CTO and Embedded Linux engineer at Free Electrons I Embedded Linux development: kernel and driver development, system integration, boot time and power consumption optimization, consulting, etc. I Embedded Linux training, Linux driver development training and Android system development training, with materials freely available under a Creative Commons license. I http://free-electrons.com I Contributions I Kernel support for the Marvell Armada ARM SoCs from Marvell I Major contributor to Buildroot, an open-source, simple and fast embedded Linux build system I Living in Toulouse, south west of France Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 2/47
  • 3. Agenda I User perspective: booting with the Device Tree I Basic Device Tree syntax and compilation I Simple example of Device Tree fragment I Overall organization of a Device Tree I Examples of Device Tree usage I General considerations about the Device Tree in Linux Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 3/47
  • 4. User perspective: before the Device Tree I The kernel contains the entire description of the hardware. I The bootloader loads a single binary, the kernel image, and executes it. I uImage or zImage I The bootloader prepares some additional information, called ATAGS, which address is passed to the kernel through register r2 I Contains information such as memory size and location, kernel command line, etc. I The bootloader tells the kernel on which board it is being booted through a machine type integer, passed in register r1. I U-Boot command: bootm <kernel img addr> I Barebox variable: bootm.image Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 4/47
  • 5. User perspective: before the Device Tree Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 5/47
  • 6. User perspective: booting with a Device Tree I The kernel no longer contains the description of the hardware, it is located in a separate binary: the device tree blob I The bootloader loads two binaries: the kernel image and the DTB I Kernel image remains uImage or zImage I DTB located in arch/arm/boot/dts, one per board I The bootloader passes the DTB address through r2. It is supposed to adjust the DTB with memory information, kernel command line, and potentially other info. I No more machine type. I U-Boot command: boot[mz] <kernel img addr> - <dtb addr> I Barebox variables: bootm.image, bootm.oftree Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 6/47
  • 7. User perspective: booting with a Device Tree Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 7/47
  • 8. User perspective: compatibility mode for DT booting I Some bootloaders have no speci
  • 9. c support for the Device Tree, or the version used on a particular device is too old to have this support. I To ease the transition, a compatibility mechanism was added: CONFIG_ARM_APPENDED_DTB. I It tells the kernel to look for a DTB right after the kernel image. I There is no built-in Make
  • 10. le rule to produce such kernel, so one must manually do: cat arch/arm/boot/zImage arch/arm/boot/dts/myboard.dtb > my-zImage mkimage ... -d my-zImage my-uImage I In addition, the additional option CONFIG_ARM_ATAG_DTB_COMPAT tells the kernel to read the ATAGS information from the bootloader, and update the DT using them. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 8/47
  • 11. What is the Device Tree ? I Quoted from the Power.org Standard for Embedded Power Architecture Platform Requirements (ePAPR) I The ePAPR speci
  • 12. es a concept called a device tree to describe system hardware. A boot program loads a device tree into a client program's memory and passes a pointer to the device tree to the client. I A device tree is a tree data structure with nodes that describe the physical devices in a system. I An ePAPR-compliant device tree describes device information in a system that cannot be dynamically detected by a client program. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 9/47
  • 13. Basic Device Tree syntax Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 10/47
  • 14. From source to binary I On ARM, all Device Tree Source
  • 15. les (DTS) are for now located in arch/arm/boot/dts I .dts
  • 20. nitions I A tool, the Device Tree Compiler compiles the source into a binary form. I Source code located in scripts/dtc I The Device Tree Blob is produced by the compiler, and is the binary that gets loaded by the bootloader and parsed by the kernel at boot time. I arch/arm/boot/dts/Makefile lists which DTBs should be generated at build time. dtb-$(CONFIG_ARCH_MVEBU) += armada-370-db.dtb armada-370-mirabox.dtb ... Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 11/47
  • 21. Exploring the DT on the target I In /sys/firmware/devicetree/base, there is a directory/
  • 22. le representation of the Device Tree contents # ls -l /sys/firmware/devicetree/base/ total 0 -r--r--r-- 1 root root 4 Jan 1 00:00 #address-cells -r--r--r-- 1 root root 4 Jan 1 00:00 #size-cells drwxr-xr-x 2 root root 0 Jan 1 00:00 chosen drwxr-xr-x 3 root root 0 Jan 1 00:00 clocks -r--r--r-- 1 root root 34 Jan 1 00:00 compatible [...] -r--r--r-- 1 root root 1 Jan 1 00:00 name drwxr-xr-x 10 root root 0 Jan 1 00:00 soc I If dtc is available on the target, possible to "unpack" the Device Tree using: dtc -I fs /sys/firmware/devicetree/base Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 12/47
  • 23. A simple example, DT side Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 13/47
  • 24. A simple example, driver side (1) The compatible string used to bind a device with the driver static struct of_device_id mxs_auart_dt_ids[] = { { .compatible = "fsl,imx28-auart", .data = &mxs_auart_devtype[IMX28_AUART] }, { .compatible = "fsl,imx23-auart", .data = &mxs_auart_devtype[IMX23_AUART] }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, mxs_auart_dt_ids); [...] static struct platform_driver mxs_auart_driver = { .probe = mxs_auart_probe, .remove = mxs_auart_remove, .driver = { .name = "mxs-auart", .of_match_table = mxs_auart_dt_ids, }, }; Code from drivers/tty/serial/mxs-auart.c Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 14/47
  • 25. A simple example, driver side (2) I of_match_device allows to get the matching entry in the mxs_auart_dt_ids table. I Useful to get the driver-speci
  • 27. eld, typically used to alter the behavior of the driver depending on the variant of the detected device. static int mxs_auart_probe(struct platform_device *pdev) { const struct of_device_id *of_id = of_match_device(mxs_auart_dt_ids, &pdev->dev); if (of_id) { /* Use of_id->data here */ [...] } [...] } Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 15/47
  • 28. A simple example, driver side (3) I Getting a reference to the clock I described by the clocks property I s->clk = clk_get(&pdev->dev, NULL); I Getting the I/O registers resource I described by the reg property I r = platform_get_resource(pdev, IORESOURCE_MEM, 0); I Getting the interrupt I described by the interrupts property I s->irq = platform_get_irq(pdev, 0); I Get a DMA channel I described by the dmas property I s->rx_dma_chan = dma_request_slave_channel(s->dev, "rx"); I s->tx_dma_chan = dma_request_slave_channel(s->dev, "tx"); I Check some custom property I struct device_node *np = pdev->dev.of_node; I if (of_get_property(np, "fsl,uart-has-rtscts", NULL)) Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 16/47
  • 29. Device Tree inclusion I Device Tree
  • 30. les are not monolithic, they can be split in several
  • 31. les, including each other. I .dtsi
  • 35. nal Device Trees I Typically, .dtsi will contain de
  • 36. nition of SoC-level information (or sometimes de
  • 37. nitions common to several almost identical boards). I The .dts
  • 38. le contains the board-level information. I The inclusion works by overlaying the tree of the including
  • 39. le over the tree of the included
  • 40. le. I Inclusion using the DT operator /include/, or since a few kernel releases, the DTS go through the C preprocessor, so #include is recommended. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 17/47
  • 41. Device Tree inclusion example Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 18/47
  • 42. Device Tree inclusion example (2) Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 19/47
  • 43. Concept of Device Tree binding I Quoting the ePAPR: I This chapter contains requirements, known as bindings, for how speci
  • 44. c types and classes of devices are represented in the device tree. I The compatible property of a device node describes the speci
  • 45. c binding (or bindings) to which the node complies. I When creating a new device tree representation for a device, a binding should be created that fully describes the required properties and value of the device. This set of properties shall be suciently descriptive to provide device drivers with needed attributes of the device. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 20/47
  • 46. Documentation of Device Tree bindings I All Device Tree bindings recognized by the kernel are documented in Documentation/devicetree/bindings. I Each binding documentation described which properties are accepted, with which values, which properties are mandatory vs. optional, etc. I All new Device Tree bindings must be reviewed by the Device Tree maintainers, by being posted to devicetree@vger.kernel.org. This ensures correctness and consistency across bindings. OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS M: Rob Herring rob.herring@calxeda.com M: Pawel Moll pawel.moll@arm.com M: Mark Rutland mark.rutland@arm.com M: Stephen Warren swarren@wwwdotorg.org M: Ian Campbell ijc+devicetree@hellion.org.uk L: devicetree@vger.kernel.org Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 21/47
  • 47. Device Tree binding documentation example * Freescale MXS Application UART (AUART) Required properties: - compatible : Should be fsl,soc-auart. The supported SoCs include imx23 and imx28. - reg : Address and length of the register set for the device - interrupts : Should contain the auart interrupt numbers - dmas: DMA specifier, consisting of a phandle to DMA controller node and AUART DMA channel ID. Refer to dma.txt and fsl-mxs-dma.txt for details. - dma-names: rx for RX channel, tx for TX channel. Example: auart0: serial@8006a000 { compatible = fsl,imx28-auart, fsl,imx23-auart; reg = 0x8006a000 0x2000; interrupts = 112; dmas = dma_apbx 8, dma_apbx 9; dma-names = rx, tx; }; Note: Each auart port should have an alias correctly numbered in aliases node. Example: [...] Documentation/devicetree/bindings/tty/serial/fsl-mxs-auart.txt Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 22/47
  • 48. Device Tree organization: top-level nodes Under the root of the Device Tree, one typically
  • 49. nds the following top-level nodes: I A cpus node, which sub-nodes describing each CPU in the system. I A memory node, which de
  • 50. nes the location and size of the RAM. I A chosen node, which de
  • 52. ned by the system
  • 53. rmware at boot time. In practice, one of its usage is to pass the kernel command line. I A aliases node, to de
  • 54. ne shortcuts to certain nodes. I One or more nodes de
  • 55. ning the buses in the SoC. I One or mode nodes de
  • 56. ning on-board devices. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 23/47
  • 57. Device Tree organization: imx28.dtsi arch/arm/boot/dts/imx28.dtsi / { aliases { ... }; cpus { ... }; apb@80000000 { apbh@80000000 { /* Some devices */ }; apbx@80040000 { /* Some devices */ }; }; ahb@80080000 { /* Some devices */ }; }; Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 24/47
  • 58. i.MX28 buses organization Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 25/47
  • 59. Device Tree organization: imx28-evk.dts arch/arm/boot/dts/imx28-evk.dts / { model = Freescale i.MX28 Evaluation Kit; compatible = fsl,imx28-evk, fsl,imx28; memory { reg = 0x40000000 0x08000000; }; apb@80000000 { apbh@80000000 { ... }; apbx@80040000 { ... }; }; ahb@80080000 { ... }; sound { ... }; leds { ... }; backlight { ... }; }; Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 26/47
  • 60. Top-level compatible property I The top-level compatible property typically de
  • 61. nes a compatible string for the board, and then for the SoC. I Values always given with the most-speci
  • 62. c
  • 64. c last. I Used to match with the dt_compat
  • 65. eld of the DT_MACHINE structure: static const char *mxs_dt_compat[] __initdata = { fsl,imx28, fsl,imx23, NULL, }; DT_MACHINE_START(MXS, Freescale MXS (Device Tree)) .dt_compat = mxs_dt_compat, [...] MACHINE_END I Can also be used within code to test the machine: if (of_machine_is_compatible(fsl,imx28-evk)) imx28_evk_init(); Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 27/47
  • 66. Bus, address cells and size cells Inside a bus, one typically needs to de
  • 67. ne the following properties: I A compatible property, which identi
  • 68. es the bus controller (in case of I2C, SPI, PCI, etc.). A special value compatible = simple-bus means a simple memory-mapped bus with no speci
  • 69. c handling or driver. Child nodes will be registered as platform devices. I The #address-cells property indicate how many cells (i.e 32 bits values) are needed to form the base address part in the reg property. I The #size-cells is the same, for the size part of the reg property. I The ranges property can describe an address translation between the child bus and the parent bus. When simply de
  • 70. ned as ranges;, it means that the translation is an identity translation. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 28/47
  • 71. simple-bus, address cells and size cells apbh@80000000 { compatible = simple-bus; #address-cells = 1; #size-cells = 1; reg = 0x80000000 0x3c900; ranges; [...] hsadc: hsadc@80002000 { reg = 0x80002000 0x2000; interrupts = 13; dmas = dma_apbh 12; dma-names = rx; status = disabled; }; [...] }; Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 29/47
  • 72. I2C bus, address cells and size cells i2c0: i2c@80058000 { #address-cells = 1; #size-cells = 0; compatible = fsl,imx28-i2c; reg = 0x80058000 0x2000; interrupts = 111; [...] sgtl5000: codec@0a { compatible = fsl,sgtl5000; reg = 0x0a; VDDA-supply = reg_3p3v; VDDIO-supply = reg_3p3v; clocks = saif0; }; at24@51 { compatible = at24,24c32; pagesize = 32; reg = 0x51; }; }; Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 30/47
  • 73. Interrupt handling I interrupt-controller; is a boolean property that indicates that the current node is an interrupt controller. I #interrupt-cells indicates the number of cells in the interrupts property for the interrupts managed by the selected interrupt controller. I interrupt-parent is a phandle that points to the interrupt controller for the current node. There is generally a top-level interrupt-parent de
  • 74. nition for the main interrupt controller. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 31/47
  • 75. Interrupt example: imx28.dtsi / { interrupt-parent = icoll; apb@80000000 { apbh@80000000 { icoll: interrupt-controller@80000000 { compatible = fsl,imx28-icoll, fsl,icoll; interrupt-controller; #interrupt-cells = 1; reg = 0x80000000 0x2000; }; ssp0: ssp@80010000 { [...] interrupts = 96; }; }; }; }; Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 32/47
  • 76. A more complicated example on Tegra 20 Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 33/47
  • 77. Interrupt example: tegra20.dtsi / { interrupt-parent = intc; intc: interrupt-controller { compatible = arm,cortex-a9-gic; reg = 0x50041000 0x1000 0x50040100 0x0100; interrupt-controller; #interrupt-cells = 3; }; i2c@7000c000 { compatible = nvidia,tegra20-i2c; reg = 0x7000c000 0x100; interrupts = GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH; #address-cells = 1; #size-cells = 0; [...] }; gpio: gpio { compatible = nvidia,tegra20-gpio; reg = 0x6000d000 0x1000; interrupts = GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH, GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH, [...], GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH; #gpio-cells = 2; gpio-controller; #interrupt-cells = 2; interrupt-controller; }; }; Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 34/47
  • 78. Interrupt example: tegra20-harmony.dts i2c@7000c000 { status = okay; clock-frequency = 400000; wm8903: wm8903@1a { compatible = wlf,wm8903; reg = 0x1a; interrupt-parent = gpio; interrupts = TEGRA_GPIO(X, 3) IRQ_TYPE_LEVEL_HIGH; gpio-controller; #gpio-cells = 2; micdet-cfg = 0; micdet-delay = 100; gpio-cfg = 0xffffffff 0xffffffff 0 0xffffffff 0xffffffff; }; }; Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 35/47
  • 79. DT is hardware description, not con
  • 80. guration I The Device Tree is really a hardware description language. I It should describe the hardware layout, and how it works. I But it should not describe which particular hardware con
  • 81. guration you're interested in. I As an example: I You may describe in the DT whether a particular piece of hardware supports DMA or not. I But you may not describe in the DT if you want to use DMA or not. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 36/47
  • 82. DT bindings as an ABI I Since the DT is OS independent, it should also be stable. I The original idea is that DTBs can be ashed on some devices by the manufacturer, so that the user can install whichever operating system it wants. I Once a Device Tree binding is de
  • 83. ned, and used in DTBs, it should no longer be changed anymore. It can only be extended. I This normally means that Device Tree bindings become part of the kernel ABI, and it should be handled with the same care. I However, kernel developers are realizing that this is really hard to achieve and slowing down the integration of drivers. I The ARM Kernel Mini-summit discussions have relaxed those rules. I There will be additional discussions during the Kernel Summit, with
  • 84. nal conclusions published afterwards. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 37/47
  • 85. Basic guidelines for binding design I A precise compatible string is better than a vague one I You have a driver that covers both variants T320 and T330 of your hardware. You may be tempted to use foo,t3xx as your compatible string. I Bad idea: what if T340 is slightly dierent, in an incompatible way? You'd better use foo,t320 for both T320 and T330. I Do not encode too much hardware details in the DT I When two hardware variants are quite similar, some developers are tempted to encode all the dierences in the DT, including register osets, bit masks or osets. I Bad idea: it makes the binding more complex, and therefore less resilient to future changes. Instead, use two dierent compatible strings and handle the dierences in the driver. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 38/47
  • 86. Future directions I More DT bindings for various subsystems I A tool to validate DTS against bindings I Currently, the DT compiler only makes syntax checks, no conformance checks against bindings. I Proposal from Benoit Cousson and Fabien Parent, [RFC 00/15] Device Tree schemas and validation I Talk from Tomasz Figa at this ELC. I Take out the Device Tree source
  • 87. les from the kernel tree I DTs are OS independent, so they can be used for other purposes than just Linux. They are already used by Barebox or U-Boot. I Having them outside of the kernel reduces the amount of churn in the kernel source. I But is IMO likely to cause a huge number of compatibility issues. Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 39/47
  • 88. References I Power.orgTM Standard for Embedded Power Architecture Platform Requirements (ePAPR), http://www.power.org/ resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf I DeviceTree.org website, http://www.devicetree.org I Device Tree documentation in the kernel sources, Documentation/devicetree I The Device Tree kernel mailing list, http: //dir.gmane.org/gmane.linux.drivers.devicetree Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 40/47
  • 89. Questions? Thomas Petazzoni thomas.petazzoni@free-electrons.com Slides under CC-BY-SA 3.0 http://free-electrons.com/pub/conferences/2014/elc/petazzoni-device- tree-dummies/ Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 41/47
  • 90. Backup slides Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 42/47
  • 91. Clock tree example, Marvell Armada XP Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 43/47
  • 92. Clock examples: instantiating clocks soc { coreclk: mvebu-sar@18230 { compatible = marvell,armada-xp-core-clock; reg = 0x18230 0x08; #clock-cells = 1; }; cpuclk: clock-complex@18700 { #clock-cells = 1; compatible = marvell,armada-xp-cpu-clock; reg = 0x18700 0xA0; clocks = coreclk 1; }; gateclk: clock-gating-control@18220 { compatible = marvell,armada-xp-gating-clock; reg = 0x18220 0x4; clocks = coreclk 0; #clock-cells = 1; }; } clocks { /* 25 MHz reference crystal */ refclk: oscillator { compatible = fixed-clock; #clock-cells = 0; clock-frequency = 25000000; }; }; Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 44/47
  • 93. Clock examples: consuming clocks CPU, using a cpuclk cpu@0 { device_type = cpu; compatible = marvell,sheeva-v7; reg = 0; clocks = cpuclk 0; }; Timer, using either a coreclk or refclk timer@20300 { compatible = marvell,armada-xp-timer; clocks = coreclk 2, refclk; clock-names = nbclk, fixed; }; USB, using a gateclk usb@52000 { compatible = marvell,orion-ehci; reg = 0x52000 0x500; interrupts = 47; clocks = gateclk 20; status = disabled; }; Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 45/47
  • 94. pinctrl binding: consumer side I The pinctrl subsystem allows to manage pin muxing. I In the Device Tree, devices that need pins to be muxed in a certain way must declare the pinctrl con
  • 95. guration they need. I The pinctrl-n properties allow to give the list of pinctrl con
  • 96. guration needed for a certain state of the device. I The pinctrl-names property allows to give a name to each state. I When a device is probed, its default pinctrl state is requested automatically. ssp0: ssp@80010000 { pinctrl-names = default; pinctrl-0 = mmc0_8bit_pins_a mmc0_cd_cfg mmc0_sck_cfg; [...] }; Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 46/47
  • 98. gurations I A pinctrl con
  • 99. guration provides a list of pins and their con
  • 102. ned as sub-nodes of the pinctrl device, either at the SoC-level, or board-level. I The binding for such con
  • 103. gurations is highly dependent on the speci
  • 104. c pinctrl driver being used. i.MX28 mmc0_8bit_pins_a: mmc0-8bit@0 { fsl,pinmux-ids = 0x2000 /* MX28_PAD_SSP0_DATA0__SSP0_D0 */ 0x2010 /* MX28_PAD_SSP0_DATA1__SSP0_D1 */ [...] 0x2090 /* MX28_PAD_SSP0_DETECT__SSP0_... */ 0x20a0 /* MX28_PAD_SSP0_SCK__SSP0_SCK */ ; fsl,drive-strength = 1; fsl,voltage = 1; fsl,pull-up = 1; }; Marvell Kirkwood pmx_nand: pmx-nand { marvell,pins = mpp0, mpp1, mpp2, mpp3, mpp4, mpp5, mpp18, mpp19; marvell,function = nand; }; Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 47/47