The Device Tree: Plug and play for Embedded Linux



Similar documents
OpenAMP Framework for Zynq Devices

Common clock framework: how to use it

The Freescale Embedded Hypervisor

Fastboot Techniques for x86 Architectures. Marcus Bortel Field Application Engineer QNX Software Systems

Embedded Linux Platform Developer

Accessing I2C devices with Digi Embedded Linux 5.2 example on Digi Connect ME 9210

The Linux Kernel Device Model

Lesson 06: Basics of Software Development (W02D2

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Linux Driver Devices. Why, When, Which, How?

DragonBoard 410c based on Qualcomm Snapdragon 410 processor Peripherals Programming Guide, Linux Android

The embedded Linux quick start guide lab notes

Design and Implementation of the Heterogeneous Multikernel Operating System

Performance Monitor on PowerQUICC II Pro Processors

Embedded Trusted Computing on ARM-based systems

Upgrading Intel AMT 5.0 drivers to Linux kernel v2.6.31

Visual Basic Programming. An Introduction

How to Run the MQX RTOS on Various RAM Memories for i.mx 6SoloX

Virtuozzo Virtualization SDK

ADL User Guide for Open AT V4.10

Freescale Semiconductor, I

Operating System Manual. Realtime Communication System for netx. Kernel API Function Reference.

Hacking Linux-Powered Devices. Stefan Arentz

Binary storage of graphs and related data

Application Note: AN00141 xcore-xa - Application Development

Lecture 22: C Programming 4 Embedded Systems

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Data Types in the Kernel

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

TEST CHAPTERS 1 & 2 OPERATING SYSTEMS

Top 10 Bug-Killing Coding Standard Rules

UG103.8 APPLICATION DEVELOPMENT FUNDAMENTALS: TOOLS

BIOS and CMOS. Overview. The Function of BIOS. The Bus

Open Flow Controller and Switch Datasheet

Embedded Linux Development Guide

EMC NetWorker Module for Microsoft for Windows Bare Metal Recovery Solution

13. Publishing Component Information to Embedded Software

EXPLORING LINUX KERNEL: THE EASY WAY!

i.mx USB loader A white paper by Tristan Lelong

3. Programming the STM32F4-Discovery

The Advanced JTAG Bridge. Nathan Yawn 05/12/09

Android Sensors This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. CC-BY Google

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Intel Do-It-Yourself Challenge Lab 2: Intel Galileo s Linux side Nicolas Vailliet

Keil C51 Cross Compiler

The Embedded Linux Quick Start Guide In the Beginning... Embedded Linux Conference Europe 2010

Xenomai: integration and qualification of a real time operating system ARMadeus Systems

Software based Finite State Machine (FSM) with general purpose processors

Object Oriented Software Design II

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Chapter 14 MS-DOS Operating System

AN1229. Class B Safety Software Library for PIC MCUs and dspic DSCs OVERVIEW OF THE IEC STANDARD INTRODUCTION

CHAPTER 2: HARDWARE BASICS: INSIDE THE BOX

VoIP Laboratory B How to re flash an IP04

Sistemi Operativi. Lezione 25: JOS processes (ENVS) Corso: Sistemi Operativi Danilo Bruschi A.A. 2015/2016

Applying Clang Static Analyzer to Linux Kernel

Priority Based Implementation in Pintos

A+ Guide to Managing and Maintaining Your PC, 7e. Chapter 1 Introducing Hardware

EMC NetWorker Module for Microsoft for Windows Bare Metal Recovery Solution

STM32JAVA. Embedded Java Solutions for STM32

Introduction to Operating Systems. Perspective of the Computer. System Software. Indiana University Chen Yu

RS-485 Protocol Manual

Research and Design of Universal and Open Software Development Platform for Digital Home

Memory Systems. Static Random Access Memory (SRAM) Cell

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Do More With Less. On Driver-less Interfacing with Embedded Devices. Peter Korsgaard

Secure Boot on i.mx50, i.mx53, and i.mx 6 Series using HABv4

Hardware monitoring on Fujitsu mainboards. Hardware monitoring on Fujitsu mainboards

Secure Boot on i.mx25, i.mx35, and i.mx51 using HABv3

Intel RAID Controller Troubleshooting Guide

Adapting the PowerPC 403 ROM Monitor Software for a 512Kb Flash Device

Pre-tested System-on-Chip Design. Accelerates PLD Development

APPLICATION NOTE. RTD Linux Support Overview. SWM Rev C

Camera Sensor Driver Development And Integration

MPLAB Harmony System Service Libraries Help

Using EDA Databases: Milkyway & OpenAccess

Operating Systems (Linux)

Byte Ordering of Multibyte Data Items

Software Development Environment

Application Note AN0008. Data Logging Extension. For. Venus 8 GPS Receiver

Semantic Analysis: Types and Type Checking

Assignment 5: Adding and testing a new system call to Linux kernel

What else can you do with Android? Inside Android. Chris Simmonds. Embedded Linux Conference Europe Copyright 2010, 2net Limited.

Migration of Process Credentials

ACP ThinManager Tech Notes ThinManager and PXE Boot

Kernel Synchronization and Interrupt Handling

Chapter 4. System Software. What You Will Learn... Computers Are Your Future. System Software. What You Will Learn... Starting the Computer

1 Classical Universal Computer 3

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

In-System Programmer USER MANUAL RN-ISP-UM RN-WIFLYCR-UM

Chapter 8 Objectives. Chapter 8 Operating Systems and Utility Programs. Operating Systems. Operating Systems. Operating Systems.

EE8205: Embedded Computer System Electrical and Computer Engineering, Ryerson University. Multitasking ARM-Applications with uvision and RTX

PKCS #11 opencryptoki for Linux HOWTO

Computer Systems II. Unix system calls. fork( ) wait( ) exit( ) How To Create New Processes? Creating and Executing Processes

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

SmartFusion csoc: Basic Bootloader and Field Upgrade envm Through IAP Interface

Transcription:

The Device Tree: Plug and play for Embedded Linux December 3rd, 2012 This work is released under Creative Common s CC0 license version 1.0 or later. To the extent possible under law, the author has waived all copyright and related or neighboring rights to this work.

1 Introduction 2 3 4 5

Introduction

Embedded processors System on Chip (SoC) FPGAs May have the same instruction set, but...... number of cores, memory size, frequency may vary... different peripherals on the bus... different boards No BIOS to convey this information.

Sources for hardware information The kernel command line The kernel configuration Hardcoded in the boot sources Header files The device tree The result: See arch/arm/

Device tree forms The device tree comes in three forms: A text file (*.dts) source A binary blob (*.dtb) binary blob A file system: /proc/device-tree runtime The blob is loaded into RAM before the kernel kicks off.

Names and acronyms Device Tree Flattened Device Tree (FDT) Open Firmware (OF)

Syntax Introduction Curly brackets: Hierarchy (directory) The hierarchy s (node) name just before curly bracket Assignments: Content (file) Strings and integers: C-style (0x hex notation) Arrays of integers ( cells ) within <and > Lists of values separated by commas C-style comments C-style labels

A sample device tree.dts listing /dts-v1/; / { #address-cells = <1>; #size-cells = <1>; compatible = "xlnx,zynq-zed"; interrupt-parent = <&gic>; model = "Xillinux for Zedboard"; aliases { serial0 = &ps7_uart_1; chosen { bootargs = "consoleblank=0 root=/dev/mmcblk0p2 rw rootwait earlyprintk"; linux,stdout-path = "/axi@0/uart@e0001000"; }; cpus { [... CPU definitions... ] ps7_ddr_0: memory@0 { device_type = "memory"; reg = < 0x0 0x20000000 >;

A sample device tree.dts listing (cont.) ps7_axi_interconnect_0: axi@0 { #address-cells = <1>; #size-cells = <1>; compatible = "xlnx,ps7-axi-interconnect-1.00.a", "simple-bus"; ranges ; gic: interrupt-controller@f8f01000 { #interrupt-cells = < 3 >; compatible = "arm,cortex-a9-gic"; interrupt-controller ; reg = < 0xf8f01000 0x1000 >,< 0xf8f00100 0x100 >; pl310: pl310-controller@f8f02000 { arm,data-latency = < 3 2 2 >; arm,tag-latency = < 2 2 2 >; cache-level = < 2 >; cache-unified ; compatible = "arm,pl310-cache"; interrupts = < 0 34 4 >; reg = < 0xf8f02000 0x1000 >; [... more peripheral definitions... ]

Accessing /proc/device-tree # hexdump -C /proc/device-tree/#size-cells 00000000 00 00 00 01... 00000004 # hexdump -C /proc/device-tree/axi@0/compatible 00000000 78 6c 6e 78 2c 70 73 37 2d 61 78 69 2d 69 6e 74 xlnx,ps7-axi-int 00000010 65 72 63 6f 6e 6e 65 63 74 2d 31 2e 30 30 2e 61 erconnect-1.00.a 00000020 00 73 69 6d 70 6c 65 2d 62 75 73 00.simple-bus. 0000002c # cat /proc/device-tree/axi@0/compatible xlnx,ps7-axi-interconnect-1.00.asimple-bus Note the Big Endian representation of the integer!

Compilation and reverse compilation The compiler is part of the Linux kernel tree. Compiles from any to any format Source to blob: $ scripts/dtc/dtc -I dts -O dtb -o /path/to/my-tree.dtb /path/to/my-tree.dts Blob to source: $ scripts/dtc/dtc -I dtb -O dts -o /path/to/fromdtb.dts /path/to/found_this.dtb The /proc/device pseudo filesystem can be converted to source as well

A starter Introduction /dts-v1/; / { #address-cells = <1>; #size-cells = <1>; compatible = "xlnx,zynq-zed"; interrupt-parent = <&gic>; model = "Xillinux for Zedboard"; aliases { serial0 = &ps7_uart_1; chosen { bootargs = "consoleblank=0 root=/dev/mmcblk0p2 rw rootwait earlyprintk"; linux,stdout-path = "/axi@0/uart@e0001000"; };

CPUs Introduction cpus { #address-cells = <1>; #cpus = <0x2>; #size-cells = <0>; ps7_cortexa9_0: cpu@0 { clock-frequency = <666666688>; compatible = "xlnx,ps7-cortexa9-1.00.a"; d-cache-line-size = <0x20>; d-cache-size = <0x8000>; device_type = "cpu"; i-cache-line-size = <0x20>; i-cache-size = <0x8000>; model = "ps7_cortexa9,1.00.a"; reg = <0>; timebase-frequency = <333333344>; xlnx,cpu-1x-clk-freq-hz = <0x69f6bcb>; xlnx,cpu-clk-freq-hz = <0x27bc86c0>; ps7_cortexa9_1: cpu@1 { [... repeated, of course... ]

Memory Introduction ps7_ddr_0: memory@0 { device_type = "memory"; reg = < 0x0 0x20000000 >; 0x20000000 = 512M

Peripherals Introduction ps7_axi_interconnect_0: axi@0 { #address-cells = <1>; #size-cells = <1>; compatible = "xlnx,ps7-axi-interconnect-1.00.a", "simple-bus"; ranges ; gic: interrupt-controller@f8f01000 { #interrupt-cells = < 3 >; compatible = "arm,cortex-a9-gic"; interrupt-controller ; reg = < 0xf8f01000 0x1000 >,< 0xf8f00100 0x100 >; pl310: pl310-controller@f8f02000 { arm,data-latency = < 3 2 2 >; arm,tag-latency = < 2 2 2 >; cache-level = < 2 >; cache-unified ; compatible = "arm,pl310-cache"; interrupts = < 0 34 4 >; reg = < 0xf8f02000 0x1000 >; [... ]

Its entry in the device tree xillybus_0: xillybus@50000000 { compatible = "xlnx,xillybus-1.00.a"; reg = < 0x50000000 0x1000 >; interrupts = < 0 59 1 >; interrupt-parent = <&gic>; xlnx,max-burst-len = <0x10>; xlnx,native-data-width = <0x20>; xlnx,slv-awidth = <0x20>; xlnx,slv-dwidth = <0x20>; xlnx,use-wstrb = <0x1>;

Kernel code: Load me! static struct of_device_id xillybus_of_match[] devinitdata = { {.compatible = "xlnx,xillybus-1.00.a", }, {} }; MODULE_DEVICE_TABLE(of, xillybus_of_match); [... ] static struct platform_driver xillybus_platform_driver = {.probe = xilly_drv_probe,.remove = xilly_drv_remove,.driver = {.name = "xillybus",.owner = THIS_MODULE,.of_match_table = xillybus_of_match, }, }; platform driver register(&xillybus platform driver) must be called in the modules initialization function.

The probe method A sanity check. Not clear if it s really needed: static int devinit xilly_drv_probe(struct platform_device *op) { const struct of_device_id *match; match = of_match_device(xillybus_of_match, &op->dev); if (!match) return -EINVAL;

The probe method (cont.) Accessing registers: int rc = 0; struct resource res; void *registers; rc = of_address_to_resource(&op->dev.of_node, 0, &res); if (rc) { /* Fail */ } if (!request_mem_region(res.start, resource_size(&res), "xillybus")) { /* Fail */ } registers = of_iomap(op->dev.of_node, 0); if (!registers) { /* Fail */ }

The probe method (cont.) Register the interrupt handler: irq = irq_of_parse_and_map(op->dev.of_node, 0); rc = request_irq(irq, xillybus_isr, 0, "xillybus", op->dev); This relates to: interrupts = < 0 59 1 >; interrupt-parent = <&gic>; in the device tree. The numbers meaning is driver dependent (and sometimes completely off-beat even if it works).

The probe method (cont.) Grab this piece of data from the device tree: xlnx,slv-awidth = <0x20>; Kernel code: void *ptr; int value; ptr = of_get_property(op->dev.of_node, "xlnx,slv-awidth", NULL); if (!ptr) { /* Couldn t find the entry */ } value = be32_to_cpup(ptr);

Conclusions Introduction It s simple! It makes sense It s useful It s a winner but... Nobody has cared to explain how it works Therefore it s messy A lot of useless stuff nobody dares to delete

Sources Introduction http://xillybus.com/tutorials/device-tree-zynq-1 http://devicetree.org/device_tree_usage include/linux/of.h (and of_*.h) in the kernel tree

Thank you! Introduction Questions?