Trees need care a solution to Device Tree validation problem

Similar documents
Device Tree Overview

json-schema for Devicetree Rob Herring

What tools exist to support device tree development and debugging? What new tools have been proposed or requested?

ARM Device Tree status report

Device Trees A Database Approach to Describing Hardware. Doug Abbott. Produced by EE Times

Devicetree BOF. ELC 2018 Portland, Oregon. Frank Rowand, Sony

Devicetree BOF. ELCE 2018 Edinburgh, UK. Frank Rowand, Sony. October 24, _1535

BoF: DeviceTree. Rob Herring Linus Walleij

ARM support in the Linux kernel

v0.2-dirty Devicetree Specification Release v0.2-dirty devicetree.org

Devicetree Specification

Devicetree. Overlay. Plumbers 2018 Vancouver, Canada. Frank Rowand, Sony November 14, _0833

ARM support in the Linux kernel

Devicetree BOF. Open Source Summit Japan 2018 Tokyo. Frank Rowand, Sony. June 20, _0351

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. 1/47

Devicetree BOF. ELC 2017 Portland, Oregon. Frank Rowand, Sony February 21, _1630

SMP bring up on ARM SoCs

Device Tree Tools Status. Frank Rowand, Sony December 2, _1957

Booting the Linux/ppc kernel without Open Firmware

Proposed new DTB format

Devicetree BOF. ELCE 2017 Prague, Czech Republic. Frank Rowand, Sony October 23, _2149

C++ Important Questions with Answers

Device trees everywhere

Porting Linux to a new SoC

Sony s Open Devices Project. Goals Achievements. What went right? What went wrong? Lessons learned

Zephyr OS Configuration via Device Tree

QCVS Hardware Device Tree Editor User Guide

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

Linux PL330 Mainline Driver Usage John Linn 10/17/2014 Based on Linux kernel 3.14

Two years of ARM SoC support mainlining: lessons learned

Devicetree Specification

So far, system calls have had easy syntax. Integer, character string, and structure arguments.

ECE 471 Embedded Systems Lecture 12

Bharat Bhushan, Stuart Yoder

Rethinking Machine Types

C Language Programming


Power.org Standard for Embedded Power Architecture Platform Requirements (epapr)

Context-sensitive Analysis

Context-sensitive Analysis. Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

Compilers Project 3: Semantic Analyzer

Getting Started using Linux on a New Embedded System

Fall 2015 COMP Operating Systems. Lab #3

OS Structure. Hardware protection & privilege levels Control transfer to and from the operating system

Chapter 1 Getting Started

U-Boot bootloader port done right 2017 edition

COSC 2P95 Lab 9 Signals, Mutexes, and Threads

FPGA Manager. State of the Union. Moritz Fischer, National Instruments

regmap The power of subsystems and abstractions 2012 Wolfson Microelectronics plc

Representation of Information

OPT3001EVM Linux Getting Started Guide. Felipe Balbi

A Third Look At ML. Chapter Nine Modern Programming Languages, 2nd ed. 1

CSE 120 Principles of Operating Systems

A brief introduction to C programming for Java programmers

LCA14-107: ACPI upstreaming. Wed-5-Mar, 11:15am, Al Stone, G Gregory, Hanjun Guo

Bridging of Control Interfaces over Multimedia Serial Links

Embedded Linux Conference San Diego 2016

CS 314 Principles of Programming Languages. Lecture 11

CS131 Compilers: Programming Assignment 2 Due Tuesday, April 4, 2017 at 11:59pm

Making Open Source Hardware for Retrogaming on Raspberry Pi. Leon Anavi Konsulko Group

Introduction to Linux kernel driver programming + i2c drivers

CS 470 Operating Systems Spring 2013 Shell Project

Slide Set 6. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Review of the Stable Realtime Release Process

Unified Device Properties Interface for ACPI and Device Trees

PCIe driver development for Exynos SoC

Understanding Device Tree Files in Multicore Hypervisor/LWE Implementations

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

Creating a Shell or Command Interperter Program CSCI411 Lab

Operating Systems. 18. Remote Procedure Calls. Paul Krzyzanowski. Rutgers University. Spring /20/ Paul Krzyzanowski

CS 351 Week 15. Course Review

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong:

Syntax-Directed Translation. CS Compiler Design. SDD and SDT scheme. Example: SDD vs SDT scheme infix to postfix trans

Today. Review. Unix as an OS case study Intro to Shell Scripting. What is an Operating System? What are its goals? How do we evaluate it?

ABOUT THE DEVICE TREE

ECE2049 E17 Lecture 4 MSP430 Architecture & Intro to Digital I/O

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline

Reversing. Time to get with the program

LLVMLinux: x86 Kernel Build

Microprocessors. Microprocessors and rpeanut. Memory. Eric McCreath

Pushing The Limits Of Linux On ARM

Microprocessors and rpeanut. Eric McCreath

CS 326: Operating Systems. Process Execution. Lecture 5

CSCE 548 Building Secure Software Dirty COW Race Condition Attack

Devicetree and its underlying concepts

Hardware OS & OS- Application interface

Introduction. This project will focus primarily on processes.

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).

CPSC 427a: Object-Oriented Programming

Distributed Systems 8. Remote Procedure Calls

Flattened Device Trees for Embedded FreeBSD

ECE 471 Embedded Systems Lecture 2

Functions & First Class Function Values

RDBE Host Software. Doc No: X3C 2009_07_21_1 TODO: Add appropriate document number. XCube Communication 1(13)

CS201 Some Important Definitions

Transcription:

Trees need care a solution to Device Tree validation problem April 30, 2014 Embedded Linux Conference San Jose, CA Tomasz Figa Linux Kernel Developer Samsung R&D Institute Poland

Overview 1. Device Tree recap 2. Device Tree data flow 3. What s wrong? 4. Problem analysis 5. History of work 6. Solution proposal 7. What s next? 8. Q&A

A quick recap. Device Tree

Device Tree Root node / Nodes Bus Device Device Sub-nodes Device Device Device Properties Interrupt MMIO GPIO Clock Data structure for describing hardware Needed to tell the OS about devices that cannot be detected automatically Tree-like structure correllated with hardware topology 4

Device Tree Describes resources needed by devices Represents relations between devices Passed to kernel at boot Replaces hard-coded platform details in the OS 5

Device Tree Terminology: Property: a key-value pair; key property name, value arbitrary data. Node: a set of properties and/or child nodes. Bindings: a description how a device is described using device tree; a list of properties and nodes (and their formats) necessary to describe a device. 6

Device Tree Widely adopted SPARC, PowerPC, ARM, MIPS, C6x, Metag, OpenRISC, Xtensa, Microblaze, ARC Even x86 ;-) More than 600 in-tree board device tree source files* More than 4000 compatible strings defined* *As of Linux 3.14 7

Device Tree 1000 900 800 700 600 500 400 Initial DT support on ARM 300 200 100 0 Number of *.dts* files Number of documentation files

What s happening to our trees? Device Tree data flow

Device Tree data flow [...] cpus { #address-cells = <1>; #size-cells = <0>; Device Tree Source (DTS) Plain text Human-readable Developer- and GIT-friendly cpu@0 { device_type = "cpu"; compatible = "arm,arm1176jzf-s", "arm,arm1176"; reg = <0x0>; soc: soc { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <1>; ranges; vic0: interrupt-controller@71200000 { compatible = "arm,pl192-vic"; interrupt-controller; reg = <0x71200000 0x1000>; #interrupt-cells = <1>; vic1: interrupt-controller@71300000 { compatible = "arm,pl192-vic"; interrupt-controller; reg = <0x71300000 0x1000>; #interrupt-cells = <1>; [...] sdhci0: sdhci@7c200000 { compatible = "samsung,s3c6410-sdhci"; reg = <0x7c200000 0x100>; interrupt-parent = <&vic1>; interrupts = <24>; 10

Device Tree data flow Device Tree Blob (DTB) Binary representation called Flattened Device Tree (FDT) Machine-readable CPU-friendly 00000000 d0 0d fe ed 00 00 03 a1 00 00 00 38 00 00 03 14...8... 00000010 00 00 00 28 00 00 00 11 00 00 00 10 00 00 00 00...(... 00000020 00 00 00 8d 00 00 02 dc 00 00 00 00 00 00 00 00... 00000030 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00... 00000040 00 00 00 03 00 00 00 04 00 00 00 00 00 00 00 01... 00000050 00 00 00 03 00 00 00 04 00 00 00 0f 00 00 00 01... 00000060 00 00 00 01 63 68 6f 73 65 6e 00 00 00 00 00 02...chosen... 00000070 00 00 00 01 61 6c 69 61 73 65 73 00 00 00 00 02...aliases... 00000080 00 00 00 01 6d 65 6d 6f 72 79 00 00 00 00 00 03...memory... 00000090 00 00 00 07 00 00 00 1b 6d 65 6d 6f 72 79 00 00...memory.. 000000a0 00 00 00 03 00 00 00 08 00 00 00 27 00 00 00 00...'... 000000b0 00 00 00 00 00 00 00 02 00 00 00 01 63 70 75 73...cpus 000000c0 00 00 00 00 00 00 00 03 00 00 00 04 00 00 00 00... 000000d0 00 00 00 01 00 00 00 03 00 00 00 04 00 00 00 0f... 000000e0 00 00 00 00 00 00 00 01 63 70 75 40 30 00 00 00...cpu@0... 000000f0 00 00 00 03 00 00 00 04 00 00 00 1b 63 70 75 00...cpu. 00000100 00 00 00 03 00 00 00 1d 00 00 00 2b 61 72 6d 2c...+arm, 00000110 61 72 6d 31 31 37 36 6a 7a 66 2d 73 00 61 72 6d arm1176jzf-s.arm 00000120 2c 61 72 6d 31 31 37 36 00 00 00 00 00 00 00 03,arm1176... 00000130 00 00 00 04 00 00 00 27 00 00 00 00 00 00 00 02...'... 00000140 00 00 00 02 00 00 00 01 73 6f 63 00 00 00 00 03...soc... 00000150 00 00 00 0b 00 00 00 2b 73 69 6d 70 6c 65 2d 62...+simple-b 00000160 75 73 00 00 00 00 00 03 00 00 00 04 00 00 00 00 us... 00000170 00 00 00 01 00 00 00 03 00 00 00 04 00 00 00 0f... 00000180 00 00 00 01 00 00 00 03 00 00 00 00 00 00 00 36...6 00000190 00 00 00 01 69 6e 74 65 72 72 75 70 74 2d 63 6f...interrupt-co 000001a0 6e 74 72 6f 6c 6c 65 72 40 37 31 32 30 30 30 30 ntroller@7120000 000001b0 30 00 00 00 00 00 00 03 00 00 00 0e 00 00 00 2b 0...+ 000001c0 61 72 6d 2c 70 6c 31 39 32 2d 76 69 63 00 00 00 arm,pl192-vic... 000001d0 00 00 00 03 00 00 00 00 00 00 00 3d 00 00 00 03...=... 000001e0 00 00 00 08 00 00 00 27 71 20 00 00 00 00 10 00...'q... 000001f0 00 00 00 03 00 00 00 04 00 00 00 52 00 00 00 01...R... 00000200 00 00 00 02 00 00 00 01 69 6e 74 65 72 72 75 70...interrup 00000210 74 2d 63 6f 6e 74 72 6f 6c 6c 65 72 40 37 31 33 t-controller@713 00000220 30 30 30 30 30 00 00 00 00 00 00 03 00 00 00 0e 00000... 00000230 00 00 00 2b 61 72 6d 2c 70 6c 31 39 32 2d 76 69...+arm,pl192-vi 00000240 63 00 00 00 00 00 00 03 00 00 00 00 00 00 00 3d c...= 00000250 00 00 00 03 00 00 00 08 00 00 00 27 71 30 00 00...'q0.. 00000260 00 00 10 00 00 00 00 03 00 00 00 04 00 00 00 52...R 00000270 00 00 00 01 00 00 00 03 00 00 00 04 00 00 00 63...c 00000280 00 00 00 01 00 00 00 03 00 00 00 04 00 00 00 69...i 00000290 00 00 00 01 00 00 00 02 00 00 00 01 73 64 68 63...sdhc 000002a0 69 40 37 63 32 30 30 30 30 30 00 00 00 00 00 03 i@7c200000... 11

Device Tree data flow Device Tree Compiler (DTC) [1] Translates between various DT representations Usually DTS -> DTB Contains simple DTS parser built with Flex+Bison [1] DTC GIT repo at kernel.org

A story of a failure. What s wrong?

What s wrong? DTC translates data directly from one representation to another Every node/property reaches output file Almost no checks performed on input data Let s see... 14

What s wrong? sample.dts (part of arch/arm/boot/dts/s3c64xx.dtsi) [...] vic0: interrupt-controller@71200000 { compatible = "arm,pl192-vic"; interrupt-controlller; reg = <0x71200000 0x1000>; #interrupt-cells = <1>; vic1: interrupt-controller@71300000 { compatible = "arm,pl192-vic"; interrupt-controller; reg = <0x71300000 0x1000>; #interrupt-calls = <1>; [...] sdhci0: sdhci@7c200000 { compatible = "samsung,s3c6410-sdhci"; reg = <0x7c200000 0x100>; interrupt-parent = <&vic1>; interrupts = <24 0>; How many errors can you spot in this snippet? 15

What s wrong? sample.dts (part of arch/arm/boot/dts/s3c64xx.dtsi) [...] vic0: interrupt-controller@71200000 { compatible = "arm,pl192-vic"; interrupt-controlller; reg = <0x71200000 0x1000>; #interrupt-cells = <1>; vic1: interrupt-controller@71300000 { compatible = "arm,pl192-vic"; interrupt-controller; reg = <0x71300000 0x1000>; #interrupt-calls = <1>; [...] sdhci0: sdhci@7c200000 { compatible = "samsung,s3c6410-sdhci"; reg = <0x7c200000 0x100>; interrupt-parent = <&vic1>; interrupts = <24 0>; And the answer is 16

What s wrong? t.figa@amdc1227 ~/kernel $ scripts/dtc/dtc -O dtb -o sample.dtb arch/arm/boot/dts/sample.dts t.figa@amdc1227 ~/kernel $ ls -l sample.dtb -rw-r--r-- 1 t.figa t.figa 929 04-21 14:21 sample.dtb t.figa@amdc1227 ~/kernel $ Hmm... Zero? 17

Getting back on the right track. Device Tree validation

Device Tree validation Current state Bindings define nodes and their contents Documented in a humanreadable format (varying between files) Non-parsable Validation of DT sources done by IVM* * Intelligent Validation Machines aka Maintainers

Conclusion 1 We need a formal way to describe DT bindings 20

Device Tree validation Initial attempt In March 2012, Jon Smirl posted on devicetree-discuss@lists.ozlabs.org [1]: In the XML world you can make schemas that describe what is legally allowed in an XML document. Device trees don't seem to any any kind of schema mechanism describing what is and isn't legal to put in a tree. Instead of recreating the entire world of schemas, has anyone looked at using XML schemas to define what is a valid device tree and then write a tool to validate the existing device trees? The topic did not receive much attention, though. [1] Schemas for device trees

Device Tree validation Further attempts RFC by Benoit Cousson and Fabien Parent [1] September 2013 DTS-like schema language Simple, readable, nice Not flexible enough /dts-v1/; / { compatible = "ti,omap[0-9]+-timer"; ti,hwmods { is-required; /dts-v1/; / { compatible = "ti,twl[0-9]+-rtc"; interrupt-controller { is-required; can-be-inherited; / { compatible = "abc"; abc { type = "integer"; def { type = "string"; [1] [RFC 00/15] Device Tree schemas and validation 22

Device Tree validation Further attempts RFC by Tomasz Figa [1] October 2013 Another DTS-like schema language Sooo complex, ugh Still not flexible enough /template/ interrupts { /arg/ interrupt-count = <1>; /inheritable/?interrupt-parent = phandle; interrupts = (cell{$( $interrupt-parent)/#interrupt-cells}) {$interrupt-count { compatible = string("ti,dm64410-spi", "ti,da830-spi"); /use/ device; /use/ spi { cs-cells = <1>; /use/ interrupts { interrupt-count = <1>; /use/ clocks { count = <1>; ti,davinci-spi-intr-line = cell(<0>, <1>); [1] [RFC 0/1] Device Tree Schema Source format proposal 23

Device Tree validation Not that simple bus: bus@0x10180000 { /*... */ #address-cells = <1> #interrupt-cells = <1>; interrupt-map-mask = <0xf800 7>; interrupt-map = <0x0000 1 &intc 9 3 // 1st slot 0x0800 1 &intc 10 3>; // 2nd slot device@0800 { /*... */ reg = <0x0800 0x100>; interrupts = <1>; Interrupt bindings. 24

Conclusion 2 A schema language is unlikely to cover the most complex bindings 25

Device Tree validation And Now For Something Completely Different RFC by Stephen Warren [1] October 2013 Validation for particular bindings implemented directly in C code of dtc Every (even trivial) binding needs to have its piece of C code Can validate interrupt bindings! void is_a_clock_consumer_by_name(struct node *node, int clock_count) { required_property(node, "clock-names"); required_property(node, "clocks"); } static const char *compats_nvidia_tegra20_i2c[] = { "nvidia,tegra20-i2c", NULL, static void checkfn_nvidia_tegra20_i2c( struct node *node) { is_an_mmio_bus_child(node, 1); is_an_i2c_bus(node); is_an_interrupt_consumer_by_index(node, 1); is_a_clock_consumer_by_name(node, 2); } [1] [RFC PATCH dtc] C-based DT schema checker integrated into dtc 26

Hybrid approach to DT schema checking Proposed solution

Proposed solution Overview RFC by Tomasz Figa [1] February 2014 C code used to validate complex generic bindings Simple schema language used to define devicespecific bindings Best of both worlds? // C file static void generic_checkfn_interrupts( const struct generic_schema *schema, struct node *root, struct node *node, struct node *params, bool required) { /* Interrupts validation goes here */ } GENERIC_SCHEMA("interrupts", interrupts); // DTSS file /dtss-v1/; wlf,wm8903 { /match/ compatible = "wlf,wm8903"; /optional/ gpio-cfg; /require/ gpio-provider { cells = <1>; [1] Hybrid approach for DT schema checking /use/ interrupts { count = <1>; // ^^ invokes generic_checkfn_interrupts()

Proposed solution Generic bindings Generic bindings are generic Can be used by many device bindings Often complex Examples: Busses (I2C, SPI) Resources (GPIO, regulators) Implementation using C code justified

Proposed solution Device bindings Bindings specific to devices Usually built from generic bindings Sometimes require a number of custom properties (mostly trivial) Lots of them Would require a patch for dtc whenever a new device is added

Proposed solution DTSS format DTS-like syntax /dtss-v1/; One node per binding Binding match List of simple properties Instances of generic bindings binding { /match/ match-name = value required-property; /optional/ optional-property; /require/ required-generic-schema; /use/ optional-generic-schema { schema-argument = <1>; 31

Proposed solution DTSS format - matches Multiple matching options compatible: compatible string, according to general compatible matching rules path: absolute path of node device_type: value of device_type property /dtss-v1/; binding1 { /match/ compatible = simple-bus ; /* Definition of binding 1 */ binding2 { /match/ path = /cpus ; /* Definition of binding 2 */ binding3 { /match/ device_type = memory ; /* Definition of binding 3 */ Only one match allowed (but might be changed?) 32

Proposed solution DTSS format simple properties Allows listing of simple properties Without type checking Can check constant values (e.g. #*-cells) Required (by default) or optional /dtss-v1/; binding1 { /match/ compatible = simple-bus ; /optional/ #address-cells; /optional/ #size-cells; binding2 { /match/ path = /cpus ; #size-cells = <0>; binding3 { /match/ device_type = memory ; reg; 33

Proposed solution DTSS format generic bindings Can /require/ or /use/ a generic binding Resource-like approach /use/ accepts missing resources /require/ bails out on any failure Arguments accessible by C schema implementation /dtss-v1/; binding1 { /match/ compatible = "wlf,wm8903 ; /require/ gpio-provider { cells = <1>; /use/ interrupts { count = <1>; binding2 { /match/ compatible = "nvidia,tegra20-i2c"; /require/ i2c-bus; 34

Proposed solution Operation 1. Scan available DTSS files and build index of matching keys 2. For each node, apply all matching DTSS schemas 3. For each DTSS schema, check presence of required simple properties and execute any referenced generic schemas 35

Proposed solution Let s use it /dtss-v1/; arm-vic { /match/ compatible = "arm,pl192-vic"; Let s create a sample schema Describes bindings shown on previous examples /require/ mmio-device { reg-count = <1>; /require/ interrupt-controller { cells = <1>; samsung-sdhci { /match/ compatible = "samsung,s3c6410-sdhci"; /require/ mmio-device { reg-count = <1>; /require/ interrupts { count = <1>; 36

Proposed solution Let s use it t.figa@amdc1227 ~/dtc $./dtc -O dtb -o sample.dtb sample.dts -x schema.dtss WARNING: no schema for node /chosen WARNING: no schema for node /aliases WARNING: no schema for node /memory WARNING: no schema for node /cpus WARNING: no schema for node /cpus/cpu@0 WARNING: no schema for node /soc ERROR: node '/soc/interrupt-controller@71200000' missing 'interrupt-controller' property ERROR: node '/soc/interrupt-controller@71300000' missing '#interrupt-cells' property ERROR: failed to parse interrupt entry 0 of node '/soc/sdhci@7c200000' t.figa@amdc1227 ~/dtc $ Hybrid validator at work 37

A (blurry) vision of the future. What s next?

What s next? To do Addressing review comments. Specification of subnodes directly from DTSS, Specification of simple property types from DTSS (cells, strings, phandles), Reporting of unrecognized properties, Sharing of parsing code with kernel, Generating binding documentation text from DTSS, Implementation of all the bindings.

What s next? Help needed Device tree army needs you to: Review the RFC Share your comments Submit further patches Start using the validator

Acknowledgements Samsung Electronics Poland For employing me to work on Linux kernel. Kernel Team of Samsung R&D Institute Poland For all the time spent on discussions about Device Tree. Linux Foundation For organizing this conference. Jon Smirl, Benouit Cousson, Fabien Parent, Stephen Warren For previous attempts of Device Tree validation. Device Tree and Linux kernel community For all the fun of working together. 41

Questions? Contact: devicetree@vger.kernel.org devicetree-compiler@vger.kernel.org #devicetree at Freenode t.figa@samsung.com Thank you!