1*cd60bc56SAndroid Build Coastguard Worker\documentclass[a4paper,twocolumn]{article} 2*cd60bc56SAndroid Build Coastguard Worker 3*cd60bc56SAndroid Build Coastguard Worker\usepackage{abstract} 4*cd60bc56SAndroid Build Coastguard Worker\usepackage{xspace} 5*cd60bc56SAndroid Build Coastguard Worker\usepackage{amssymb} 6*cd60bc56SAndroid Build Coastguard Worker\usepackage{latexsym} 7*cd60bc56SAndroid Build Coastguard Worker\usepackage{tabularx} 8*cd60bc56SAndroid Build Coastguard Worker\usepackage[T1]{fontenc} 9*cd60bc56SAndroid Build Coastguard Worker\usepackage{calc} 10*cd60bc56SAndroid Build Coastguard Worker\usepackage{listings} 11*cd60bc56SAndroid Build Coastguard Worker\usepackage{color} 12*cd60bc56SAndroid Build Coastguard Worker\usepackage{url} 13*cd60bc56SAndroid Build Coastguard Worker 14*cd60bc56SAndroid Build Coastguard Worker\title{Device trees everywhere} 15*cd60bc56SAndroid Build Coastguard Worker 16*cd60bc56SAndroid Build Coastguard Worker\author{David Gibson \texttt{<{dwg}{@}{au1.ibm.com}>}\\ 17*cd60bc56SAndroid Build Coastguard Worker Benjamin Herrenschmidt \texttt{<{benh}{@}{kernel.crashing.org}>}\\ 18*cd60bc56SAndroid Build Coastguard Worker \emph{OzLabs, IBM Linux Technology Center}} 19*cd60bc56SAndroid Build Coastguard Worker 20*cd60bc56SAndroid Build Coastguard Worker\newcommand{\R}{\textsuperscript{\textregistered}\xspace} 21*cd60bc56SAndroid Build Coastguard Worker\newcommand{\tm}{\textsuperscript{\texttrademark}\xspace} 22*cd60bc56SAndroid Build Coastguard Worker\newcommand{\tge}{$\geqslant$} 23*cd60bc56SAndroid Build Coastguard Worker%\newcommand{\ditto}{\textquotedbl\xspace} 24*cd60bc56SAndroid Build Coastguard Worker 25*cd60bc56SAndroid Build Coastguard Worker\newcommand{\fixme}[1]{$\bigstar$\emph{\textbf{\large #1}}$\bigstar$\xspace} 26*cd60bc56SAndroid Build Coastguard Worker 27*cd60bc56SAndroid Build Coastguard Worker\newcommand{\ppc}{\mbox{PowerPC}\xspace} 28*cd60bc56SAndroid Build Coastguard Worker\newcommand{\of}{Open Firmware\xspace} 29*cd60bc56SAndroid Build Coastguard Worker\newcommand{\benh}{Ben Herrenschmidt\xspace} 30*cd60bc56SAndroid Build Coastguard Worker\newcommand{\kexec}{\texttt{kexec()}\xspace} 31*cd60bc56SAndroid Build Coastguard Worker\newcommand{\dtbeginnode}{\texttt{OF\_DT\_BEGIN\_NODE\xspace}} 32*cd60bc56SAndroid Build Coastguard Worker\newcommand{\dtendnode}{\texttt{OF\_DT\_END\_NODE\xspace}} 33*cd60bc56SAndroid Build Coastguard Worker\newcommand{\dtprop}{\texttt{OF\_DT\_PROP\xspace}} 34*cd60bc56SAndroid Build Coastguard Worker\newcommand{\dtend}{\texttt{OF\_DT\_END\xspace}} 35*cd60bc56SAndroid Build Coastguard Worker\newcommand{\dtc}{\texttt{dtc}\xspace} 36*cd60bc56SAndroid Build Coastguard Worker\newcommand{\phandle}{\texttt{linux,phandle}\xspace} 37*cd60bc56SAndroid Build Coastguard Worker\begin{document} 38*cd60bc56SAndroid Build Coastguard Worker 39*cd60bc56SAndroid Build Coastguard Worker\maketitle 40*cd60bc56SAndroid Build Coastguard Worker 41*cd60bc56SAndroid Build Coastguard Worker\begin{abstract} 42*cd60bc56SAndroid Build Coastguard Worker We present a method for booting a \ppc{}\R Linux\R kernel on an 43*cd60bc56SAndroid Build Coastguard Worker embedded machine. To do this, we supply the kernel with a compact 44*cd60bc56SAndroid Build Coastguard Worker flattened-tree representation of the system's hardware based on the 45*cd60bc56SAndroid Build Coastguard Worker device tree supplied by Open Firmware on IBM\R servers and Apple\R 46*cd60bc56SAndroid Build Coastguard Worker Power Macintosh\R machines. 47*cd60bc56SAndroid Build Coastguard Worker 48*cd60bc56SAndroid Build Coastguard Worker The ``blob'' representing the device tree can be created using \dtc 49*cd60bc56SAndroid Build Coastguard Worker --- the Device Tree Compiler --- that turns a simple text 50*cd60bc56SAndroid Build Coastguard Worker representation of the tree into the compact representation used by 51*cd60bc56SAndroid Build Coastguard Worker the kernel. The compiler can produce either a binary ``blob'' or an 52*cd60bc56SAndroid Build Coastguard Worker assembler file ready to be built into a firmware or bootwrapper 53*cd60bc56SAndroid Build Coastguard Worker image. 54*cd60bc56SAndroid Build Coastguard Worker 55*cd60bc56SAndroid Build Coastguard Worker This flattened-tree approach is now the only supported method of 56*cd60bc56SAndroid Build Coastguard Worker booting a \texttt{ppc64} kernel without Open Firmware, and we plan 57*cd60bc56SAndroid Build Coastguard Worker to make it the only supported method for all \texttt{powerpc} 58*cd60bc56SAndroid Build Coastguard Worker kernels in the future. 59*cd60bc56SAndroid Build Coastguard Worker\end{abstract} 60*cd60bc56SAndroid Build Coastguard Worker 61*cd60bc56SAndroid Build Coastguard Worker\section{Introduction} 62*cd60bc56SAndroid Build Coastguard Worker 63*cd60bc56SAndroid Build Coastguard Worker\subsection{OF and the device tree} 64*cd60bc56SAndroid Build Coastguard Worker 65*cd60bc56SAndroid Build Coastguard WorkerHistorically, ``everyday'' \ppc machines have booted with the help of 66*cd60bc56SAndroid Build Coastguard Worker\of (OF), a firmware environment defined by IEEE1275 \cite{IEEE1275}. 67*cd60bc56SAndroid Build Coastguard WorkerAmong other boot-time services, OF maintains a device tree that 68*cd60bc56SAndroid Build Coastguard Workerdescribes all of the system's hardware devices and how they're 69*cd60bc56SAndroid Build Coastguard Workerconnected. During boot, before taking control of memory management, 70*cd60bc56SAndroid Build Coastguard Workerthe Linux kernel uses OF calls to scan the device tree and transfer it 71*cd60bc56SAndroid Build Coastguard Workerto an internal representation that is used at run time to look up 72*cd60bc56SAndroid Build Coastguard Workervarious device information. 73*cd60bc56SAndroid Build Coastguard Worker 74*cd60bc56SAndroid Build Coastguard WorkerThe device tree consists of nodes representing devices or 75*cd60bc56SAndroid Build Coastguard Workerbuses\footnote{Well, mostly. There are a few special exceptions.}. 76*cd60bc56SAndroid Build Coastguard WorkerEach node contains \emph{properties}, name--value pairs that give 77*cd60bc56SAndroid Build Coastguard Workerinformation about the device. The values are arbitrary byte strings, 78*cd60bc56SAndroid Build Coastguard Workerand for some properties, they contain tables or other structured 79*cd60bc56SAndroid Build Coastguard Workerinformation. 80*cd60bc56SAndroid Build Coastguard Worker 81*cd60bc56SAndroid Build Coastguard Worker\subsection{The bad old days} 82*cd60bc56SAndroid Build Coastguard Worker 83*cd60bc56SAndroid Build Coastguard WorkerEmbedded systems, by contrast, usually have a minimal firmware that 84*cd60bc56SAndroid Build Coastguard Workermight supply a few vital system parameters (size of RAM and the like), 85*cd60bc56SAndroid Build Coastguard Workerbut nothing as detailed or complete as the OF device tree. This has 86*cd60bc56SAndroid Build Coastguard Workermeant that the various 32-bit \ppc embedded ports have required a 87*cd60bc56SAndroid Build Coastguard Workervariety of hacks spread across the kernel to deal with the lack of 88*cd60bc56SAndroid Build Coastguard Workerdevice tree. These vary from specialised boot wrappers to parse 89*cd60bc56SAndroid Build Coastguard Workerparameters (which are at least reasonably localised) to 90*cd60bc56SAndroid Build Coastguard WorkerCONFIG-dependent hacks in drivers to override normal probe logic with 91*cd60bc56SAndroid Build Coastguard Workerhardcoded addresses for a particular board. As well as being ugly of 92*cd60bc56SAndroid Build Coastguard Workeritself, such CONFIG-dependent hacks make it hard to build a single 93*cd60bc56SAndroid Build Coastguard Workerkernel image that supports multiple embedded machines. 94*cd60bc56SAndroid Build Coastguard Worker 95*cd60bc56SAndroid Build Coastguard WorkerUntil relatively recently, the only 64-bit \ppc machines without OF 96*cd60bc56SAndroid Build Coastguard Workerwere legacy (pre-POWER5\R) iSeries\R machines. iSeries machines often 97*cd60bc56SAndroid Build Coastguard Workeronly have virtual IO devices, which makes it quite simple to work 98*cd60bc56SAndroid Build Coastguard Workeraround the lack of a device tree. Even so, the lack means the iSeries 99*cd60bc56SAndroid Build Coastguard Workerboot sequence must be quite different from the pSeries or Macintosh, 100*cd60bc56SAndroid Build Coastguard Workerwhich is not ideal. 101*cd60bc56SAndroid Build Coastguard Worker 102*cd60bc56SAndroid Build Coastguard WorkerThe device tree also presents a problem for implementing \kexec. When 103*cd60bc56SAndroid Build Coastguard Workerthe kernel boots, it takes over full control of the system from OF, 104*cd60bc56SAndroid Build Coastguard Workereven re-using OF's memory. So, when \kexec comes to boot another 105*cd60bc56SAndroid Build Coastguard Workerkernel, OF is no longer around for the second kernel to query. 106*cd60bc56SAndroid Build Coastguard Worker 107*cd60bc56SAndroid Build Coastguard Worker\section{The Flattened Tree} 108*cd60bc56SAndroid Build Coastguard Worker 109*cd60bc56SAndroid Build Coastguard WorkerIn May 2005 \benh implemented a new approach to handling the device 110*cd60bc56SAndroid Build Coastguard Workertree that addresses all these problems. When booting on OF systems, 111*cd60bc56SAndroid Build Coastguard Workerthe first thing the kernel runs is a small piece of code in 112*cd60bc56SAndroid Build Coastguard Worker\texttt{prom\_init.c}, which executes in the context of OF. This code 113*cd60bc56SAndroid Build Coastguard Workerwalks the device tree using OF calls, and transcribes it into a 114*cd60bc56SAndroid Build Coastguard Workercompact, flattened format. The resulting device tree ``blob'' is then 115*cd60bc56SAndroid Build Coastguard Workerpassed to the kernel proper, which eventually unflattens the tree into 116*cd60bc56SAndroid Build Coastguard Workerits runtime form. This blob is the only data communicated between the 117*cd60bc56SAndroid Build Coastguard Worker\texttt{prom\_init.c} bootstrap and the rest of the kernel. 118*cd60bc56SAndroid Build Coastguard Worker 119*cd60bc56SAndroid Build Coastguard WorkerWhen OF isn't available, either because the machine doesn't have it at 120*cd60bc56SAndroid Build Coastguard Workerall or because \kexec has been used, the kernel instead starts 121*cd60bc56SAndroid Build Coastguard Workerdirectly from the entry point taking a flattened device tree. The 122*cd60bc56SAndroid Build Coastguard Workerdevice tree blob must be passed in from outside, rather than generated 123*cd60bc56SAndroid Build Coastguard Workerby part of the kernel from OF. For \kexec, the userland 124*cd60bc56SAndroid Build Coastguard Worker\texttt{kexec} tools build the blob from the runtime device tree 125*cd60bc56SAndroid Build Coastguard Workerbefore invoking the new kernel. For embedded systems the blob can 126*cd60bc56SAndroid Build Coastguard Workercome either from the embedded bootloader, or from a specialised 127*cd60bc56SAndroid Build Coastguard Workerversion of the \texttt{zImage} wrapper for the system in question. 128*cd60bc56SAndroid Build Coastguard Worker 129*cd60bc56SAndroid Build Coastguard Worker\subsection{Properties of the flattened tree} 130*cd60bc56SAndroid Build Coastguard Worker 131*cd60bc56SAndroid Build Coastguard WorkerThe flattened tree format should be easy to handle, both for the 132*cd60bc56SAndroid Build Coastguard Workerkernel that parses it and the bootloader that generates it. In 133*cd60bc56SAndroid Build Coastguard Workerparticular, the following properties are desirable: 134*cd60bc56SAndroid Build Coastguard Worker 135*cd60bc56SAndroid Build Coastguard Worker\begin{itemize} 136*cd60bc56SAndroid Build Coastguard Worker\item \emph{relocatable}: the bootloader or kernel should be able to 137*cd60bc56SAndroid Build Coastguard Worker move the blob around as a whole, without needing to parse or adjust 138*cd60bc56SAndroid Build Coastguard Worker its internals. In practice that means we must not use pointers 139*cd60bc56SAndroid Build Coastguard Worker within the blob. 140*cd60bc56SAndroid Build Coastguard Worker\item \emph{insert and delete}: sometimes the bootloader might want to 141*cd60bc56SAndroid Build Coastguard Worker make tweaks to the flattened tree, such as deleting or inserting a 142*cd60bc56SAndroid Build Coastguard Worker node (or whole subtree). It should be possible to do this without 143*cd60bc56SAndroid Build Coastguard Worker having to effectively regenerate the whole flattened tree. In 144*cd60bc56SAndroid Build Coastguard Worker practice this means limiting the use of internal offsets in the blob 145*cd60bc56SAndroid Build Coastguard Worker that need recalculation if a section is inserted or removed with 146*cd60bc56SAndroid Build Coastguard Worker \texttt{memmove()}. 147*cd60bc56SAndroid Build Coastguard Worker\item \emph{compact}: embedded systems are frequently short of 148*cd60bc56SAndroid Build Coastguard Worker resources, particularly RAM and flash memory space. Thus, the tree 149*cd60bc56SAndroid Build Coastguard Worker representation should be kept as small as conveniently possible. 150*cd60bc56SAndroid Build Coastguard Worker\end{itemize} 151*cd60bc56SAndroid Build Coastguard Worker 152*cd60bc56SAndroid Build Coastguard Worker\subsection{Format of the device tree blob} 153*cd60bc56SAndroid Build Coastguard Worker\label{sec:format} 154*cd60bc56SAndroid Build Coastguard Worker 155*cd60bc56SAndroid Build Coastguard Worker\begin{figure}[htb!] 156*cd60bc56SAndroid Build Coastguard Worker \centering 157*cd60bc56SAndroid Build Coastguard Worker \footnotesize 158*cd60bc56SAndroid Build Coastguard Worker \begin{tabular}{r|c|l} 159*cd60bc56SAndroid Build Coastguard Worker \multicolumn{1}{r}{\textbf{Offset}}& \multicolumn{1}{c}{\textbf{Contents}} \\\cline{2-2} 160*cd60bc56SAndroid Build Coastguard Worker \texttt{0x00} & \texttt{0xd00dfeed} & magic number \\\cline{2-2} 161*cd60bc56SAndroid Build Coastguard Worker \texttt{0x04} & \emph{totalsize} \\\cline{2-2} 162*cd60bc56SAndroid Build Coastguard Worker \texttt{0x08} & \emph{off\_struct} & \\\cline{2-2} 163*cd60bc56SAndroid Build Coastguard Worker \texttt{0x0C} & \emph{off\_strs} & \\\cline{2-2} 164*cd60bc56SAndroid Build Coastguard Worker \texttt{0x10} & \emph{off\_rsvmap} & \\\cline{2-2} 165*cd60bc56SAndroid Build Coastguard Worker \texttt{0x14} & \emph{version} \\\cline{2-2} 166*cd60bc56SAndroid Build Coastguard Worker \texttt{0x18} & \emph{last\_comp\_ver} & \\\cline{2-2} 167*cd60bc56SAndroid Build Coastguard Worker \texttt{0x1C} & \emph{boot\_cpu\_id} & \tge v2 only\\\cline{2-2} 168*cd60bc56SAndroid Build Coastguard Worker \texttt{0x20} & \emph{size\_strs} & \tge v3 only\\\cline{2-2} 169*cd60bc56SAndroid Build Coastguard Worker \multicolumn{1}{r}{\vdots} & \multicolumn{1}{c}{\vdots} & \\\cline{2-2} 170*cd60bc56SAndroid Build Coastguard Worker \emph{off\_rsvmap} & \emph{address0} & memory reserve \\ 171*cd60bc56SAndroid Build Coastguard Worker + \texttt{0x04} & ...& table \\\cline{2-2} 172*cd60bc56SAndroid Build Coastguard Worker + \texttt{0x08} & \emph{len0} & \\ 173*cd60bc56SAndroid Build Coastguard Worker + \texttt{0x0C} & ...& \\\cline{2-2} 174*cd60bc56SAndroid Build Coastguard Worker \vdots & \multicolumn{1}{c|}{\vdots} & \\\cline{2-2} 175*cd60bc56SAndroid Build Coastguard Worker & \texttt{0x00000000}- & end marker\\ 176*cd60bc56SAndroid Build Coastguard Worker & \texttt{00000000} & \\\cline{2-2} 177*cd60bc56SAndroid Build Coastguard Worker & \texttt{0x00000000}- & \\ 178*cd60bc56SAndroid Build Coastguard Worker & \texttt{00000000} & \\\cline{2-2} 179*cd60bc56SAndroid Build Coastguard Worker \multicolumn{1}{r}{\vdots} & \multicolumn{1}{c}{\vdots} & \\\cline{2-2} 180*cd60bc56SAndroid Build Coastguard Worker \emph{off\_strs} & \texttt{'n' 'a' 'm' 'e'} & strings block \\ 181*cd60bc56SAndroid Build Coastguard Worker + \texttt{0x04} & \texttt{~0~ 'm' 'o' 'd'} & \\ 182*cd60bc56SAndroid Build Coastguard Worker + \texttt{0x08} & \texttt{'e' 'l' ~0~ \makebox[\widthof{~~~}]{\textrm{...}}} & \\ 183*cd60bc56SAndroid Build Coastguard Worker \vdots & \multicolumn{1}{c|}{\vdots} & \\\cline{2-2} 184*cd60bc56SAndroid Build Coastguard Worker \multicolumn{1}{r}{+ \emph{size\_strs}} \\ 185*cd60bc56SAndroid Build Coastguard Worker \multicolumn{1}{r}{\vdots} & \multicolumn{1}{c}{\vdots} & \\\cline{2-2} 186*cd60bc56SAndroid Build Coastguard Worker \emph{off\_struct} & \dtbeginnode & structure block \\\cline{2-2} 187*cd60bc56SAndroid Build Coastguard Worker + \texttt{0x04} & \texttt{'/' ~0~ ~0~ ~0~} & root node\\\cline{2-2} 188*cd60bc56SAndroid Build Coastguard Worker + \texttt{0x08} & \dtprop & \\\cline{2-2} 189*cd60bc56SAndroid Build Coastguard Worker + \texttt{0x0C} & \texttt{0x00000005} & ``\texttt{model}''\\\cline{2-2} 190*cd60bc56SAndroid Build Coastguard Worker + \texttt{0x10} & \texttt{0x00000008} & \\\cline{2-2} 191*cd60bc56SAndroid Build Coastguard Worker + \texttt{0x14} & \texttt{'M' 'y' 'B' 'o'} & \\ 192*cd60bc56SAndroid Build Coastguard Worker + \texttt{0x18} & \texttt{'a' 'r' 'd' ~0~} & \\\cline{2-2} 193*cd60bc56SAndroid Build Coastguard Worker \vdots & \multicolumn{1}{c|}{\vdots} & \\\cline{2-2} 194*cd60bc56SAndroid Build Coastguard Worker & \texttt{\dtendnode} \\\cline{2-2} 195*cd60bc56SAndroid Build Coastguard Worker & \texttt{\dtend} \\\cline{2-2} 196*cd60bc56SAndroid Build Coastguard Worker \multicolumn{1}{r}{\vdots} & \multicolumn{1}{c}{\vdots} & \\\cline{2-2} 197*cd60bc56SAndroid Build Coastguard Worker \multicolumn{1}{r}{\emph{totalsize}} \\ 198*cd60bc56SAndroid Build Coastguard Worker \end{tabular} 199*cd60bc56SAndroid Build Coastguard Worker \caption{Device tree blob layout} 200*cd60bc56SAndroid Build Coastguard Worker \label{fig:blob-layout} 201*cd60bc56SAndroid Build Coastguard Worker\end{figure} 202*cd60bc56SAndroid Build Coastguard Worker 203*cd60bc56SAndroid Build Coastguard WorkerThe format for the blob we devised, was first described on the 204*cd60bc56SAndroid Build Coastguard Worker\texttt{linuxppc64-dev} mailing list in \cite{noof1}. The format has 205*cd60bc56SAndroid Build Coastguard Workersince evolved through various revisions, and the current version is 206*cd60bc56SAndroid Build Coastguard Workerincluded as part of the \dtc (see \S\ref{sec:dtc}) git tree, 207*cd60bc56SAndroid Build Coastguard Worker\cite{dtcgit}. 208*cd60bc56SAndroid Build Coastguard Worker 209*cd60bc56SAndroid Build Coastguard WorkerFigure \ref{fig:blob-layout} shows the layout of the blob of data 210*cd60bc56SAndroid Build Coastguard Workercontaining the device tree. It has three sections of variable size: 211*cd60bc56SAndroid Build Coastguard Workerthe \emph{memory reserve table}, the \emph{structure block} and the 212*cd60bc56SAndroid Build Coastguard Worker\emph{strings block}. A small header gives the blob's size and 213*cd60bc56SAndroid Build Coastguard Workerversion and the locations of the three sections, plus a handful of 214*cd60bc56SAndroid Build Coastguard Workervital parameters used during early boot. 215*cd60bc56SAndroid Build Coastguard Worker 216*cd60bc56SAndroid Build Coastguard WorkerThe memory reserve map section gives a list of regions of memory that 217*cd60bc56SAndroid Build Coastguard Workerthe kernel must not use\footnote{Usually such ranges contain some data 218*cd60bc56SAndroid Build Coastguard Workerstructure initialised by the firmware that must be preserved by the 219*cd60bc56SAndroid Build Coastguard Workerkernel.}. The list is represented as a simple array of (address, 220*cd60bc56SAndroid Build Coastguard Workersize) pairs of 64 bit values, terminated by a zero size entry. The 221*cd60bc56SAndroid Build Coastguard Workerstrings block is similarly simple, consisting of a number of 222*cd60bc56SAndroid Build Coastguard Workernull-terminated strings appended together, which are referenced from 223*cd60bc56SAndroid Build Coastguard Workerthe structure block as described below. 224*cd60bc56SAndroid Build Coastguard Worker 225*cd60bc56SAndroid Build Coastguard WorkerThe structure block contains the device tree proper. Each node is 226*cd60bc56SAndroid Build Coastguard Workerintroduced with a 32-bit \dtbeginnode tag, followed by the node's name 227*cd60bc56SAndroid Build Coastguard Workeras a null-terminated string, padded to a 32-bit boundary. Then 228*cd60bc56SAndroid Build Coastguard Workerfollows all of the properties of the node, each introduced with a 229*cd60bc56SAndroid Build Coastguard Worker\dtprop tag, then all of the node's subnodes, each introduced with 230*cd60bc56SAndroid Build Coastguard Workertheir own \dtbeginnode tag. The node ends with an \dtendnode tag, and 231*cd60bc56SAndroid Build Coastguard Workerafter the \dtendnode for the root node is an \dtend tag, indicating 232*cd60bc56SAndroid Build Coastguard Workerthe end of the whole tree\footnote{This is redundant, but included for 233*cd60bc56SAndroid Build Coastguard Workerease of parsing.}. The structure block starts with the \dtbeginnode 234*cd60bc56SAndroid Build Coastguard Workerintroducing the description of the root node (named \texttt{/}). 235*cd60bc56SAndroid Build Coastguard Worker 236*cd60bc56SAndroid Build Coastguard WorkerEach property, after the \dtprop, has a 32-bit value giving an offset 237*cd60bc56SAndroid Build Coastguard Workerfrom the beginning of the strings block at which the property name is 238*cd60bc56SAndroid Build Coastguard Workerstored. Because it's common for many nodes to have properties with 239*cd60bc56SAndroid Build Coastguard Workerthe same name, this approach can substantially reduce the total size 240*cd60bc56SAndroid Build Coastguard Workerof the blob. The name offset is followed by the length of the 241*cd60bc56SAndroid Build Coastguard Workerproperty value (as a 32-bit value) and then the data itself padded to 242*cd60bc56SAndroid Build Coastguard Workera 32-bit boundary. 243*cd60bc56SAndroid Build Coastguard Worker 244*cd60bc56SAndroid Build Coastguard Worker\subsection{Contents of the tree} 245*cd60bc56SAndroid Build Coastguard Worker\label{sec:treecontents} 246*cd60bc56SAndroid Build Coastguard Worker 247*cd60bc56SAndroid Build Coastguard WorkerHaving seen how to represent the device tree structure as a flattened 248*cd60bc56SAndroid Build Coastguard Workerblob, what actually goes into the tree? The short answer is ``the 249*cd60bc56SAndroid Build Coastguard Workersame as an OF tree''. On OF systems, the flattened tree is 250*cd60bc56SAndroid Build Coastguard Workertranscribed directly from the OF device tree, so for simplicity we 251*cd60bc56SAndroid Build Coastguard Workeralso use OF conventions for the tree on other systems. 252*cd60bc56SAndroid Build Coastguard Worker 253*cd60bc56SAndroid Build Coastguard WorkerIn many cases a flat tree can be simpler than a typical OF provided 254*cd60bc56SAndroid Build Coastguard Workerdevice tree. The flattened tree need only provide those nodes and 255*cd60bc56SAndroid Build Coastguard Workerproperties that the kernel actually requires; the flattened tree 256*cd60bc56SAndroid Build Coastguard Workergenerally need not include devices that the kernel can probe itself. 257*cd60bc56SAndroid Build Coastguard WorkerFor example, an OF device tree would normally include nodes for each 258*cd60bc56SAndroid Build Coastguard WorkerPCI device on the system. A flattened tree need only include nodes 259*cd60bc56SAndroid Build Coastguard Workerfor the PCI host bridges; the kernel will scan the buses thus 260*cd60bc56SAndroid Build Coastguard Workerdescribed to find the subsidiary devices. The device tree can include 261*cd60bc56SAndroid Build Coastguard Workernodes for devices where the kernel needs extra information, though: 262*cd60bc56SAndroid Build Coastguard Workerfor example, for ISA devices on a subsidiary PCI/ISA bridge, or for 263*cd60bc56SAndroid Build Coastguard Workerdevices with unusual interrupt routing. 264*cd60bc56SAndroid Build Coastguard Worker 265*cd60bc56SAndroid Build Coastguard WorkerWhere they exist, we follow the IEEE1275 bindings that specify how to 266*cd60bc56SAndroid Build Coastguard Workerdescribe various buses in the device tree (for example, 267*cd60bc56SAndroid Build Coastguard Worker\cite{IEEE1275-pci} describe how to represent PCI devices). The 268*cd60bc56SAndroid Build Coastguard Workerstandard has not been updated for a long time, however, and lacks 269*cd60bc56SAndroid Build Coastguard Workerbindings for many modern buses and devices. In particular, embedded 270*cd60bc56SAndroid Build Coastguard Workerspecific devices such as the various System-on-Chip buses are not 271*cd60bc56SAndroid Build Coastguard Workercovered. We intend to create new bindings for such buses, in keeping 272*cd60bc56SAndroid Build Coastguard Workerwith the general conventions of IEEE1275 (a simple such binding for a 273*cd60bc56SAndroid Build Coastguard WorkerSystem-on-Chip bus was included in \cite{noof5} a revision of 274*cd60bc56SAndroid Build Coastguard Worker\cite{noof1}). 275*cd60bc56SAndroid Build Coastguard Worker 276*cd60bc56SAndroid Build Coastguard WorkerOne complication arises for representing ``phandles'' in the flattened 277*cd60bc56SAndroid Build Coastguard Workertree. In OF, each node in the tree has an associated phandle, a 278*cd60bc56SAndroid Build Coastguard Worker32-bit integer that uniquely identifies the node\footnote{In practice 279*cd60bc56SAndroid Build Coastguard Workerusually implemented as a pointer or offset within OF memory.}. This 280*cd60bc56SAndroid Build Coastguard Workerhandle is used by the various OF calls to query and traverse the tree. 281*cd60bc56SAndroid Build Coastguard WorkerSometimes phandles are also used within the tree to refer to other 282*cd60bc56SAndroid Build Coastguard Workernodes in the tree. For example, devices that produce interrupts 283*cd60bc56SAndroid Build Coastguard Workergenerally have an \texttt{interrupt-parent} property giving the 284*cd60bc56SAndroid Build Coastguard Workerphandle of the interrupt controller that handles interrupts from this 285*cd60bc56SAndroid Build Coastguard Workerdevice. Parsing these and other interrupt related properties allows 286*cd60bc56SAndroid Build Coastguard Workerthe kernel to build a complete representation of the system's 287*cd60bc56SAndroid Build Coastguard Workerinterrupt tree, which can be quite different from the tree of bus 288*cd60bc56SAndroid Build Coastguard Workerconnections. 289*cd60bc56SAndroid Build Coastguard Worker 290*cd60bc56SAndroid Build Coastguard WorkerIn the flattened tree, a node's phandle is represented by a special 291*cd60bc56SAndroid Build Coastguard Worker\phandle property. When the kernel generates a flattened tree from 292*cd60bc56SAndroid Build Coastguard WorkerOF, it adds a \phandle property to each node, containing the phandle 293*cd60bc56SAndroid Build Coastguard Workerretrieved from OF. When the tree is generated without OF, however, 294*cd60bc56SAndroid Build Coastguard Workeronly nodes that are actually referred to by phandle need to have this 295*cd60bc56SAndroid Build Coastguard Workerproperty. 296*cd60bc56SAndroid Build Coastguard Worker 297*cd60bc56SAndroid Build Coastguard WorkerAnother complication arises because nodes in an OF tree have two 298*cd60bc56SAndroid Build Coastguard Workernames. First they have the ``unit name'', which is how the node is 299*cd60bc56SAndroid Build Coastguard Workerreferred to in an OF path. The unit name generally consists of a 300*cd60bc56SAndroid Build Coastguard Workerdevice type followed by an \texttt{@} followed by a \emph{unit 301*cd60bc56SAndroid Build Coastguard Workeraddress}. For example \texttt{/memory@0} is the full path of a memory 302*cd60bc56SAndroid Build Coastguard Workernode at address 0, \texttt{/ht@0,f2000000/pci@1} is the path of a PCI 303*cd60bc56SAndroid Build Coastguard Workerbus node, which is under a HyperTransport\tm bus node. The form of 304*cd60bc56SAndroid Build Coastguard Workerthe unit address is bus dependent, but is generally derived from the 305*cd60bc56SAndroid Build Coastguard Workernode's \texttt{reg} property. In addition, nodes have a property, 306*cd60bc56SAndroid Build Coastguard Worker\texttt{name}, whose value is usually equal to the first path of the 307*cd60bc56SAndroid Build Coastguard Workerunit name. For example, the nodes in the previous example would have 308*cd60bc56SAndroid Build Coastguard Worker\texttt{name} properties equal to \texttt{memory} and \texttt{pci}, 309*cd60bc56SAndroid Build Coastguard Workerrespectively. To save space in the blob, the current version of the 310*cd60bc56SAndroid Build Coastguard Workerflattened tree format only requires the unit names to be present. 311*cd60bc56SAndroid Build Coastguard WorkerWhen the kernel unflattens the tree, it automatically generates a 312*cd60bc56SAndroid Build Coastguard Worker\texttt{name} property from the node's path name. 313*cd60bc56SAndroid Build Coastguard Worker 314*cd60bc56SAndroid Build Coastguard Worker\section{The Device Tree Compiler} 315*cd60bc56SAndroid Build Coastguard Worker\label{sec:dtc} 316*cd60bc56SAndroid Build Coastguard Worker 317*cd60bc56SAndroid Build Coastguard Worker\begin{figure}[htb!] 318*cd60bc56SAndroid Build Coastguard Worker \centering 319*cd60bc56SAndroid Build Coastguard Worker \begin{lstlisting}[frame=single,basicstyle=\footnotesize\ttfamily, 320*cd60bc56SAndroid Build Coastguard Worker tabsize=3,numbers=left,xleftmargin=2em] 321*cd60bc56SAndroid Build Coastguard Worker/memreserve/ 0x20000000-0x21FFFFFF; 322*cd60bc56SAndroid Build Coastguard Worker 323*cd60bc56SAndroid Build Coastguard Worker/ { 324*cd60bc56SAndroid Build Coastguard Worker model = "MyBoard"; 325*cd60bc56SAndroid Build Coastguard Worker compatible = "MyBoardFamily"; 326*cd60bc56SAndroid Build Coastguard Worker #address-cells = <2>; 327*cd60bc56SAndroid Build Coastguard Worker #size-cells = <2>; 328*cd60bc56SAndroid Build Coastguard Worker 329*cd60bc56SAndroid Build Coastguard Worker cpus { 330*cd60bc56SAndroid Build Coastguard Worker #address-cells = <1>; 331*cd60bc56SAndroid Build Coastguard Worker #size-cells = <0>; 332*cd60bc56SAndroid Build Coastguard Worker PowerPC,970@0 { 333*cd60bc56SAndroid Build Coastguard Worker device_type = "cpu"; 334*cd60bc56SAndroid Build Coastguard Worker reg = <0>; 335*cd60bc56SAndroid Build Coastguard Worker clock-frequency = <5f5e1000>; 336*cd60bc56SAndroid Build Coastguard Worker timebase-frequency = <1FCA055>; 337*cd60bc56SAndroid Build Coastguard Worker linux,boot-cpu; 338*cd60bc56SAndroid Build Coastguard Worker i-cache-size = <10000>; 339*cd60bc56SAndroid Build Coastguard Worker d-cache-size = <8000>; 340*cd60bc56SAndroid Build Coastguard Worker }; 341*cd60bc56SAndroid Build Coastguard Worker }; 342*cd60bc56SAndroid Build Coastguard Worker 343*cd60bc56SAndroid Build Coastguard Worker memory@0 { 344*cd60bc56SAndroid Build Coastguard Worker device_type = "memory"; 345*cd60bc56SAndroid Build Coastguard Worker memreg: reg = <00000000 00000000 346*cd60bc56SAndroid Build Coastguard Worker 00000000 20000000>; 347*cd60bc56SAndroid Build Coastguard Worker }; 348*cd60bc56SAndroid Build Coastguard Worker 349*cd60bc56SAndroid Build Coastguard Worker mpic@0x3fffdd08400 { 350*cd60bc56SAndroid Build Coastguard Worker /* Interrupt controller */ 351*cd60bc56SAndroid Build Coastguard Worker /* ... */ 352*cd60bc56SAndroid Build Coastguard Worker }; 353*cd60bc56SAndroid Build Coastguard Worker 354*cd60bc56SAndroid Build Coastguard Worker pci@40000000000000 { 355*cd60bc56SAndroid Build Coastguard Worker /* PCI host bridge */ 356*cd60bc56SAndroid Build Coastguard Worker /* ... */ 357*cd60bc56SAndroid Build Coastguard Worker }; 358*cd60bc56SAndroid Build Coastguard Worker 359*cd60bc56SAndroid Build Coastguard Worker chosen { 360*cd60bc56SAndroid Build Coastguard Worker bootargs = "root=/dev/sda2"; 361*cd60bc56SAndroid Build Coastguard Worker linux,platform = <00000600>; 362*cd60bc56SAndroid Build Coastguard Worker interrupt-controller = 363*cd60bc56SAndroid Build Coastguard Worker < &/mpic@0x3fffdd08400 >; 364*cd60bc56SAndroid Build Coastguard Worker }; 365*cd60bc56SAndroid Build Coastguard Worker}; 366*cd60bc56SAndroid Build Coastguard Worker\end{lstlisting} 367*cd60bc56SAndroid Build Coastguard Worker \caption{Example \dtc source} 368*cd60bc56SAndroid Build Coastguard Worker \label{fig:dts} 369*cd60bc56SAndroid Build Coastguard Worker\end{figure} 370*cd60bc56SAndroid Build Coastguard Worker 371*cd60bc56SAndroid Build Coastguard WorkerAs we've seen, the flattened device tree format provides a convenient 372*cd60bc56SAndroid Build Coastguard Workerway of communicating device tree information to the kernel. It's 373*cd60bc56SAndroid Build Coastguard Workersimple for the kernel to parse, and simple for bootloaders to 374*cd60bc56SAndroid Build Coastguard Workermanipulate. On OF systems, it's easy to generate the flattened tree 375*cd60bc56SAndroid Build Coastguard Workerby walking the OF maintained tree. However, for embedded systems, the 376*cd60bc56SAndroid Build Coastguard Workerflattened tree must be generated from scratch. 377*cd60bc56SAndroid Build Coastguard Worker 378*cd60bc56SAndroid Build Coastguard WorkerEmbedded bootloaders are generally built for a particular board. So, 379*cd60bc56SAndroid Build Coastguard Workerit's usually possible to build the device tree blob at compile time 380*cd60bc56SAndroid Build Coastguard Workerand include it in the bootloader image. For minor revisions of the 381*cd60bc56SAndroid Build Coastguard Workerboard, the bootloader can contain code to make the necessary tweaks to 382*cd60bc56SAndroid Build Coastguard Workerthe tree before passing it to the booted kernel. 383*cd60bc56SAndroid Build Coastguard Worker 384*cd60bc56SAndroid Build Coastguard WorkerThe device trees for embedded boards are usually quite simple, and 385*cd60bc56SAndroid Build Coastguard Workerit's possible to hand construct the necessary blob by hand, but doing 386*cd60bc56SAndroid Build Coastguard Workerso is tedious. The ``device tree compiler'', \dtc{}\footnote{\dtc can 387*cd60bc56SAndroid Build Coastguard Workerbe obtained from \cite{dtcgit}.}, is designed to make creating device 388*cd60bc56SAndroid Build Coastguard Workertree blobs easier by converting a text representation of the tree 389*cd60bc56SAndroid Build Coastguard Workerinto the necessary blob. 390*cd60bc56SAndroid Build Coastguard Worker 391*cd60bc56SAndroid Build Coastguard Worker\subsection{Input and output formats} 392*cd60bc56SAndroid Build Coastguard Worker 393*cd60bc56SAndroid Build Coastguard WorkerAs well as the normal mode of compiling a device tree blob from text 394*cd60bc56SAndroid Build Coastguard Workersource, \dtc can convert a device tree between a number of 395*cd60bc56SAndroid Build Coastguard Workerrepresentations. It can take its input in one of three different 396*cd60bc56SAndroid Build Coastguard Workerformats: 397*cd60bc56SAndroid Build Coastguard Worker\begin{itemize} 398*cd60bc56SAndroid Build Coastguard Worker\item source, the normal case. The device tree is described in a text 399*cd60bc56SAndroid Build Coastguard Worker form, described in \S\ref{sec:dts}. 400*cd60bc56SAndroid Build Coastguard Worker\item blob (\texttt{dtb}), the flattened tree format described in 401*cd60bc56SAndroid Build Coastguard Worker \S\ref{sec:format}. This mode is useful for checking a pre-existing 402*cd60bc56SAndroid Build Coastguard Worker device tree blob. 403*cd60bc56SAndroid Build Coastguard Worker\item filesystem (\texttt{fs}), input is a directory tree in the 404*cd60bc56SAndroid Build Coastguard Worker layout of \texttt{/proc/device-tree} (roughly, a directory for each 405*cd60bc56SAndroid Build Coastguard Worker node in the device tree, a file for each property). This is useful 406*cd60bc56SAndroid Build Coastguard Worker for building a blob for the device tree in use by the currently 407*cd60bc56SAndroid Build Coastguard Worker running kernel. 408*cd60bc56SAndroid Build Coastguard Worker\end{itemize} 409*cd60bc56SAndroid Build Coastguard Worker 410*cd60bc56SAndroid Build Coastguard WorkerIn addition, \dtc can output the tree in one of three different 411*cd60bc56SAndroid Build Coastguard Workerformats: 412*cd60bc56SAndroid Build Coastguard Worker\begin{itemize} 413*cd60bc56SAndroid Build Coastguard Worker\item blob (\texttt{dtb}), as in \S\ref{sec:format}. The most 414*cd60bc56SAndroid Build Coastguard Worker straightforward use of \dtc is to compile from ``source'' to 415*cd60bc56SAndroid Build Coastguard Worker ``blob'' format. 416*cd60bc56SAndroid Build Coastguard Worker\item source (\texttt{dts}), as in \S\ref{sec:dts}. If used with blob 417*cd60bc56SAndroid Build Coastguard Worker input, this allows \dtc to act as a ``decompiler''. 418*cd60bc56SAndroid Build Coastguard Worker\item assembler source (\texttt{asm}). \dtc can produce an assembler 419*cd60bc56SAndroid Build Coastguard Worker file, which will assemble into a \texttt{.o} file containing the 420*cd60bc56SAndroid Build Coastguard Worker device tree blob, with symbols giving the beginning of the blob and 421*cd60bc56SAndroid Build Coastguard Worker its various subsections. This can then be linked directly into a 422*cd60bc56SAndroid Build Coastguard Worker bootloader or firmware image. 423*cd60bc56SAndroid Build Coastguard Worker\end{itemize} 424*cd60bc56SAndroid Build Coastguard Worker 425*cd60bc56SAndroid Build Coastguard WorkerFor maximum applicability, \dtc can both read and write any of the 426*cd60bc56SAndroid Build Coastguard Workerexisting revisions of the blob format. When reading, \dtc takes the 427*cd60bc56SAndroid Build Coastguard Workerversion from the blob header, and when writing it takes a command line 428*cd60bc56SAndroid Build Coastguard Workeroption specifying the desired version. It automatically makes any 429*cd60bc56SAndroid Build Coastguard Workernecessary adjustments to the tree that are necessary for the specified 430*cd60bc56SAndroid Build Coastguard Workerversion. For example, formats before 0x10 require each node to have 431*cd60bc56SAndroid Build Coastguard Workeran explicit \texttt{name} property. When \dtc creates such a blob, it 432*cd60bc56SAndroid Build Coastguard Workerwill automatically generate \texttt{name} properties from the unit 433*cd60bc56SAndroid Build Coastguard Workernames. 434*cd60bc56SAndroid Build Coastguard Worker 435*cd60bc56SAndroid Build Coastguard Worker\subsection{Source format} 436*cd60bc56SAndroid Build Coastguard Worker\label{sec:dts} 437*cd60bc56SAndroid Build Coastguard Worker 438*cd60bc56SAndroid Build Coastguard WorkerThe ``source'' format for \dtc is a text description of the device 439*cd60bc56SAndroid Build Coastguard Workertree in a vaguely C-like form. Figure \ref{fig:dts} shows an 440*cd60bc56SAndroid Build Coastguard Workerexample. The file starts with \texttt{/memreserve/} directives, which 441*cd60bc56SAndroid Build Coastguard Workergives address ranges to add to the output blob's memory reserve table, 442*cd60bc56SAndroid Build Coastguard Workerthen the device tree proper is described. 443*cd60bc56SAndroid Build Coastguard Worker 444*cd60bc56SAndroid Build Coastguard WorkerNodes of the tree are introduced with the node name, followed by a 445*cd60bc56SAndroid Build Coastguard Worker\texttt{\{} ... \texttt{\};} block containing the node's properties 446*cd60bc56SAndroid Build Coastguard Workerand subnodes. Properties are given as just {\emph{name} \texttt{=} 447*cd60bc56SAndroid Build Coastguard Worker \emph{value}\texttt{;}}. The property values can be given in any 448*cd60bc56SAndroid Build Coastguard Workerof three forms: 449*cd60bc56SAndroid Build Coastguard Worker\begin{itemize} 450*cd60bc56SAndroid Build Coastguard Worker\item \emph{string} (for example, \texttt{"MyBoard"}). The property 451*cd60bc56SAndroid Build Coastguard Worker value is the given string, including terminating NULL. C-style 452*cd60bc56SAndroid Build Coastguard Worker escapes (\verb+\t+, \verb+\n+, \verb+\0+ and so forth) are allowed. 453*cd60bc56SAndroid Build Coastguard Worker\item \emph{cells} (for example, \texttt{<0 8000 f0000000>}). The 454*cd60bc56SAndroid Build Coastguard Worker property value is made up of a list of 32-bit ``cells'', each given 455*cd60bc56SAndroid Build Coastguard Worker as a hex value. 456*cd60bc56SAndroid Build Coastguard Worker\item \emph{bytestring} (for example, \texttt{[1234abcdef]}). The 457*cd60bc56SAndroid Build Coastguard Worker property value is given as a hex bytestring. 458*cd60bc56SAndroid Build Coastguard Worker\end{itemize} 459*cd60bc56SAndroid Build Coastguard Worker 460*cd60bc56SAndroid Build Coastguard WorkerCell properties can also contain \emph{references}. Instead of a hex 461*cd60bc56SAndroid Build Coastguard Workernumber, the source can give an ampersand (\texttt{\&}) followed by the 462*cd60bc56SAndroid Build Coastguard Workerfull path to some node in the tree. For example, in Figure 463*cd60bc56SAndroid Build Coastguard Worker\ref{fig:dts}, the \texttt{/chosen} node has an 464*cd60bc56SAndroid Build Coastguard Worker\texttt{interrupt-controller} property referring to the interrupt 465*cd60bc56SAndroid Build Coastguard Workercontroller described by the node \texttt{/mpic@0x3fffdd08400}. In the 466*cd60bc56SAndroid Build Coastguard Workeroutput tree, the value of the referenced node's phandle is included in 467*cd60bc56SAndroid Build Coastguard Workerthe property. If that node doesn't have an explicit phandle property, 468*cd60bc56SAndroid Build Coastguard Worker\dtc will automatically create a unique phandle for it. This approach 469*cd60bc56SAndroid Build Coastguard Workermakes it easy to create interrupt trees without having to explicitly 470*cd60bc56SAndroid Build Coastguard Workerassign and remember phandles for the various interrupt controller 471*cd60bc56SAndroid Build Coastguard Workernodes. 472*cd60bc56SAndroid Build Coastguard Worker 473*cd60bc56SAndroid Build Coastguard WorkerThe \dtc source can also include ``labels'', which are placed on a 474*cd60bc56SAndroid Build Coastguard Workerparticular node or property. For example, Figure \ref{fig:dts} has a 475*cd60bc56SAndroid Build Coastguard Workerlabel ``\texttt{memreg}'' on the \texttt{reg} property of the node 476*cd60bc56SAndroid Build Coastguard Worker\texttt{/memory@0}. When using assembler output, corresponding labels 477*cd60bc56SAndroid Build Coastguard Workerin the output are generated, which will assemble into symbols 478*cd60bc56SAndroid Build Coastguard Workeraddressing the part of the blob with the node or property in question. 479*cd60bc56SAndroid Build Coastguard WorkerThis is useful for the common case where an embedded board has an 480*cd60bc56SAndroid Build Coastguard Workeressentially fixed device tree with a few variable properties, such as 481*cd60bc56SAndroid Build Coastguard Workerthe size of memory. The bootloader for such a board can have a device 482*cd60bc56SAndroid Build Coastguard Workertree linked in, including a symbol referring to the right place in the 483*cd60bc56SAndroid Build Coastguard Workerblob to update the parameter with the correct value determined at 484*cd60bc56SAndroid Build Coastguard Workerruntime. 485*cd60bc56SAndroid Build Coastguard Worker 486*cd60bc56SAndroid Build Coastguard Worker\subsection{Tree checking} 487*cd60bc56SAndroid Build Coastguard Worker 488*cd60bc56SAndroid Build Coastguard WorkerBetween reading in the device tree and writing it out in the new 489*cd60bc56SAndroid Build Coastguard Workerformat, \dtc performs a number of checks on the tree: 490*cd60bc56SAndroid Build Coastguard Worker\begin{itemize} 491*cd60bc56SAndroid Build Coastguard Worker\item \emph{syntactic structure}: \dtc checks that node and property 492*cd60bc56SAndroid Build Coastguard Worker names contain only allowed characters and meet length restrictions. 493*cd60bc56SAndroid Build Coastguard Worker It checks that a node does not have multiple properties or subnodes 494*cd60bc56SAndroid Build Coastguard Worker with the same name. 495*cd60bc56SAndroid Build Coastguard Worker\item \emph{semantic structure}: In some cases, \dtc checks that 496*cd60bc56SAndroid Build Coastguard Worker properties whose contents are defined by convention have appropriate 497*cd60bc56SAndroid Build Coastguard Worker values. For example, it checks that \texttt{reg} properties have a 498*cd60bc56SAndroid Build Coastguard Worker length that makes sense given the address forms specified by the 499*cd60bc56SAndroid Build Coastguard Worker \texttt{\#address-cells} and \texttt{\#size-cells} properties. It 500*cd60bc56SAndroid Build Coastguard Worker checks that properties such as \texttt{interrupt-parent} contain a 501*cd60bc56SAndroid Build Coastguard Worker valid phandle. 502*cd60bc56SAndroid Build Coastguard Worker\item \emph{Linux requirements}: \dtc checks that the device tree 503*cd60bc56SAndroid Build Coastguard Worker contains those nodes and properties that are required by the Linux 504*cd60bc56SAndroid Build Coastguard Worker kernel to boot correctly. 505*cd60bc56SAndroid Build Coastguard Worker\end{itemize} 506*cd60bc56SAndroid Build Coastguard Worker 507*cd60bc56SAndroid Build Coastguard WorkerThese checks are useful to catch simple problems with the device tree, 508*cd60bc56SAndroid Build Coastguard Workerrather than having to debug the results on an embedded kernel. With 509*cd60bc56SAndroid Build Coastguard Workerthe blob input mode, it can also be used for diagnosing problems with 510*cd60bc56SAndroid Build Coastguard Workeran existing blob. 511*cd60bc56SAndroid Build Coastguard Worker 512*cd60bc56SAndroid Build Coastguard Worker\section{Future Work} 513*cd60bc56SAndroid Build Coastguard Worker 514*cd60bc56SAndroid Build Coastguard Worker\subsection{Board ports} 515*cd60bc56SAndroid Build Coastguard Worker 516*cd60bc56SAndroid Build Coastguard WorkerThe flattened device tree has always been the only supported way to 517*cd60bc56SAndroid Build Coastguard Workerboot a \texttt{ppc64} kernel on an embedded system. With the merge of 518*cd60bc56SAndroid Build Coastguard Worker\texttt{ppc32} and \texttt{ppc64} code it has also become the only 519*cd60bc56SAndroid Build Coastguard Workersupported way to boot any merged \texttt{powerpc} kernel, 32-bit or 520*cd60bc56SAndroid Build Coastguard Worker64-bit. In fact, the old \texttt{ppc} architecture exists mainly just 521*cd60bc56SAndroid Build Coastguard Workerto support the old ppc32 embedded ports that have not been migrated 522*cd60bc56SAndroid Build Coastguard Workerto the flattened device tree approach. We plan to remove the 523*cd60bc56SAndroid Build Coastguard Worker\texttt{ppc} architecture eventually, which will mean porting all the 524*cd60bc56SAndroid Build Coastguard Workervarious embedded boards to use the flattened device tree. 525*cd60bc56SAndroid Build Coastguard Worker 526*cd60bc56SAndroid Build Coastguard Worker\subsection{\dtc features} 527*cd60bc56SAndroid Build Coastguard Worker 528*cd60bc56SAndroid Build Coastguard WorkerWhile it is already quite usable, there are a number of extra features 529*cd60bc56SAndroid Build Coastguard Workerthat \dtc could include to make creating device trees more convenient: 530*cd60bc56SAndroid Build Coastguard Worker\begin{itemize} 531*cd60bc56SAndroid Build Coastguard Worker\item \emph{better tree checking}: Although \dtc already performs a 532*cd60bc56SAndroid Build Coastguard Worker number of checks on the device tree, they are rather haphazard. In 533*cd60bc56SAndroid Build Coastguard Worker many cases \dtc will give up after detecting a minor error early and 534*cd60bc56SAndroid Build Coastguard Worker won't pick up more interesting errors later on. There is a 535*cd60bc56SAndroid Build Coastguard Worker \texttt{-f} parameter that forces \dtc to generate an output tree 536*cd60bc56SAndroid Build Coastguard Worker even if there are errors. At present, this needs to be used more 537*cd60bc56SAndroid Build Coastguard Worker often than one might hope, because \dtc is bad at deciding which 538*cd60bc56SAndroid Build Coastguard Worker errors should really be fatal, and which rate mere warnings. 539*cd60bc56SAndroid Build Coastguard Worker\item \emph{binary include}: Occasionally, it is useful for the device 540*cd60bc56SAndroid Build Coastguard Worker tree to incorporate as a property a block of binary data for some 541*cd60bc56SAndroid Build Coastguard Worker board-specific purpose. For example, many of Apple's device trees 542*cd60bc56SAndroid Build Coastguard Worker incorporate bytecode drivers for certain platform devices. \dtc's 543*cd60bc56SAndroid Build Coastguard Worker source format ought to allow this by letting a property's value be 544*cd60bc56SAndroid Build Coastguard Worker read directly from a binary file. 545*cd60bc56SAndroid Build Coastguard Worker\item \emph{macros}: it might be useful for \dtc to implement some 546*cd60bc56SAndroid Build Coastguard Worker sort of macros so that a tree containing a number of similar devices 547*cd60bc56SAndroid Build Coastguard Worker (for example, multiple identical ethernet controllers or PCI buses) 548*cd60bc56SAndroid Build Coastguard Worker can be written more quickly. At present, this can be accomplished 549*cd60bc56SAndroid Build Coastguard Worker in part by running the source file through CPP before compiling with 550*cd60bc56SAndroid Build Coastguard Worker \dtc. It's not clear whether ``native'' support for macros would be 551*cd60bc56SAndroid Build Coastguard Worker more useful. 552*cd60bc56SAndroid Build Coastguard Worker\end{itemize} 553*cd60bc56SAndroid Build Coastguard Worker 554*cd60bc56SAndroid Build Coastguard Worker\bibliographystyle{amsplain} 555*cd60bc56SAndroid Build Coastguard Worker\bibliography{dtc-paper} 556*cd60bc56SAndroid Build Coastguard Worker 557*cd60bc56SAndroid Build Coastguard Worker\section*{About the authors} 558*cd60bc56SAndroid Build Coastguard Worker 559*cd60bc56SAndroid Build Coastguard WorkerDavid Gibson has been a member of the IBM Linux Technology Center, 560*cd60bc56SAndroid Build Coastguard Workerworking from Canberra, Australia, since 2001. Recently he has worked 561*cd60bc56SAndroid Build Coastguard Workeron Linux hugepage support and performance counter support for ppc64, 562*cd60bc56SAndroid Build Coastguard Workeras well as the device tree compiler. In the past, he has worked on 563*cd60bc56SAndroid Build Coastguard Workerbringup for various ppc and ppc64 embedded systems, the orinoco 564*cd60bc56SAndroid Build Coastguard Workerwireless driver, ramfs, and a userspace checkpointing system 565*cd60bc56SAndroid Build Coastguard Worker(\texttt{esky}). 566*cd60bc56SAndroid Build Coastguard Worker 567*cd60bc56SAndroid Build Coastguard WorkerBenjamin Herrenschmidt was a MacOS developer for about 10 years, but 568*cd60bc56SAndroid Build Coastguard Workerultimately saw the light and installed Linux on his Apple PowerPC 569*cd60bc56SAndroid Build Coastguard Workermachine. After writing a bootloader, BootX, for it in 1998, he 570*cd60bc56SAndroid Build Coastguard Workerstarted contributing to the PowerPC Linux port in various areas, 571*cd60bc56SAndroid Build Coastguard Workermostly around the support for Apple machines. He became official 572*cd60bc56SAndroid Build Coastguard WorkerPowerMac maintainer in 2001. In 2003, he joined the IBM Linux 573*cd60bc56SAndroid Build Coastguard WorkerTechnology Center in Canberra, Australia, where he ported the 64 bit 574*cd60bc56SAndroid Build Coastguard WorkerPowerPC kernel to Apple G5 machines and the Maple embedded board, 575*cd60bc56SAndroid Build Coastguard Workeramong others things. He's a member of the ppc64 development ``team'' 576*cd60bc56SAndroid Build Coastguard Workerand one of his current goals is to make the integration of embedded 577*cd60bc56SAndroid Build Coastguard Workerplatforms smoother and more maintainable than in the 32-bit PowerPC 578*cd60bc56SAndroid Build Coastguard Workerkernel. 579*cd60bc56SAndroid Build Coastguard Worker 580*cd60bc56SAndroid Build Coastguard Worker\section*{Legal Statement} 581*cd60bc56SAndroid Build Coastguard Worker 582*cd60bc56SAndroid Build Coastguard WorkerThis work represents the view of the author and does not necessarily 583*cd60bc56SAndroid Build Coastguard Workerrepresent the view of IBM. 584*cd60bc56SAndroid Build Coastguard Worker 585*cd60bc56SAndroid Build Coastguard WorkerIBM, \ppc, \ppc Architecture, POWER5, pSeries and iSeries are 586*cd60bc56SAndroid Build Coastguard Workertrademarks or registered trademarks of International Business Machines 587*cd60bc56SAndroid Build Coastguard WorkerCorporation in the United States and/or other countries. 588*cd60bc56SAndroid Build Coastguard Worker 589*cd60bc56SAndroid Build Coastguard WorkerApple and Power Macintosh are a registered trademarks of Apple 590*cd60bc56SAndroid Build Coastguard WorkerComputer Inc. in the United States, other countries, or both. 591*cd60bc56SAndroid Build Coastguard Worker 592*cd60bc56SAndroid Build Coastguard WorkerLinux is a registered trademark of Linus Torvalds. 593*cd60bc56SAndroid Build Coastguard Worker 594*cd60bc56SAndroid Build Coastguard WorkerOther company, product, and service names may be trademarks or service 595*cd60bc56SAndroid Build Coastguard Workermarks of others. 596*cd60bc56SAndroid Build Coastguard Worker 597*cd60bc56SAndroid Build Coastguard Worker\end{document} 598