1bbb0b128SSimon Glass# 2bbb0b128SSimon Glass# Copyright (c) 2011 The Chromium OS Authors. 3bbb0b128SSimon Glass# 4bbb0b128SSimon Glass# See file CREDITS for list of people who contributed to this 5bbb0b128SSimon Glass# project. 6bbb0b128SSimon Glass# 7bbb0b128SSimon Glass# This program is free software; you can redistribute it and/or 8bbb0b128SSimon Glass# modify it under the terms of the GNU General Public License as 9bbb0b128SSimon Glass# published by the Free Software Foundatio; either version 2 of 10bbb0b128SSimon Glass# the License, or (at your option) any later version. 11bbb0b128SSimon Glass# 12bbb0b128SSimon Glass# This program is distributed in the hope that it will be useful, 13bbb0b128SSimon Glass# but WITHOUT ANY WARRANTY; without even the implied warranty of 14bbb0b128SSimon Glass# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15bbb0b128SSimon Glass# GNU General Public License for more details. 16bbb0b128SSimon Glass# 17bbb0b128SSimon Glass# You should have received a copy of the GNU General Public License 18bbb0b128SSimon Glass# along with this program; if not, write to the Free Software 19bbb0b128SSimon Glass# Foundation, Inc., 59 Temple Place, Suite 330, Boston, 20bbb0b128SSimon Glass# MA 02111-1307 USA 21bbb0b128SSimon Glass# 22bbb0b128SSimon Glass 23bbb0b128SSimon GlassDevice Tree Control in U-Boot 24bbb0b128SSimon Glass============================= 25bbb0b128SSimon Glass 26bbb0b128SSimon GlassThis feature provides for run-time configuration of U-Boot via a flat 27bbb0b128SSimon Glassdevice tree (fdt). U-Boot configuration has traditionally been done 28bbb0b128SSimon Glassusing CONFIG options in the board config file. This feature aims to 29bbb0b128SSimon Glassmake it possible for a single U-Boot binary to support multiple boards, 30bbb0b128SSimon Glasswith the exact configuration of each board controlled by a flat device 31bbb0b128SSimon Glasstree (fdt). This is the approach recently taken by the ARM Linux kernel 32bbb0b128SSimon Glassand has been used by PowerPC for some time. 33bbb0b128SSimon Glass 34bbb0b128SSimon GlassThe fdt is a convenient vehicle for implementing run-time configuration 35bbb0b128SSimon Glassfor three reasons. Firstly it is easy to use, being a simple text file. 36bbb0b128SSimon GlassIt is extensible since it consists of nodes and properties in a nice 37bbb0b128SSimon Glasshierarchical format. 38bbb0b128SSimon Glass 39bbb0b128SSimon GlassFinally, there is already excellent infrastructure for the fdt: a 40bbb0b128SSimon Glasscompiler checks the text file and converts it to a compact binary 41bbb0b128SSimon Glassformat, and a library is already available in U-Boot (libfdt) for 42bbb0b128SSimon Glasshandling this format. 43bbb0b128SSimon Glass 44bbb0b128SSimon GlassThe dts directory contains a Makefile for building the device tree blob 45bbb0b128SSimon Glassand embedding it in your U-Boot image. This is useful since it allows 46bbb0b128SSimon GlassU-Boot to configure itself according to what it finds there. If you have 47bbb0b128SSimon Glassa number of similar boards with different peripherals, you can describe 48bbb0b128SSimon Glassthe features of each board in the device tree file, and have a single 49bbb0b128SSimon Glassgeneric source base. 50bbb0b128SSimon Glass 51bbb0b128SSimon GlassTo enable this feature, add CONFIG_OF_CONTROL to your board config file. 52bbb0b128SSimon Glass 53bbb0b128SSimon Glass 54bbb0b128SSimon GlassWhat is a Flat Device Tree? 55bbb0b128SSimon Glass--------------------------- 56bbb0b128SSimon Glass 57bbb0b128SSimon GlassAn fdt can be specified in source format as a text file. To read about 58bbb0b128SSimon Glassthe fdt syntax, take a look at the specification here: 59bbb0b128SSimon Glass 60bbb0b128SSimon Glasshttps://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf 61bbb0b128SSimon Glass 62bbb0b128SSimon GlassYou also might find this section of the Linux kernel documentation 63bbb0b128SSimon Glassuseful: (access this in the Linux kernel source code) 64bbb0b128SSimon Glass 65bbb0b128SSimon Glass Documentation/devicetree/booting-without-of.txt 66bbb0b128SSimon Glass 67bbb0b128SSimon GlassThere is also a mailing list: 68bbb0b128SSimon Glass 69bbb0b128SSimon Glass http://lists.ozlabs.org/listinfo/devicetree-discuss 70bbb0b128SSimon Glass 71bbb0b128SSimon GlassIn case you are wondering, OF stands for Open Firmware. 72bbb0b128SSimon Glass 73bbb0b128SSimon Glass 74bbb0b128SSimon GlassTools 75bbb0b128SSimon Glass----- 76bbb0b128SSimon Glass 77bbb0b128SSimon GlassTo use this feature you will need to get the device tree compiler here: 78bbb0b128SSimon Glass 79bbb0b128SSimon Glass git://jdl.com/software/dtc.git 80bbb0b128SSimon Glass 81bbb0b128SSimon GlassFor example: 82bbb0b128SSimon Glass 83bbb0b128SSimon Glass $ git clone git://jdl.com/software/dtc.git 84bbb0b128SSimon Glass $ cd dtc 85bbb0b128SSimon Glass $ make 86bbb0b128SSimon Glass $ sudo make install 87bbb0b128SSimon Glass 88bbb0b128SSimon GlassThen run the compiler (your version will vary): 89bbb0b128SSimon Glass 90bbb0b128SSimon Glass $ dtc -v 91bbb0b128SSimon Glass Version: DTC 1.2.0-g2cb4b51f 92bbb0b128SSimon Glass $ make tests 93bbb0b128SSimon Glass $ cd tests 94bbb0b128SSimon Glass $ ./run_tests.sh 95bbb0b128SSimon Glass ********** TEST SUMMARY 96bbb0b128SSimon Glass * Total testcases: 1371 97bbb0b128SSimon Glass * PASS: 1371 98bbb0b128SSimon Glass * FAIL: 0 99bbb0b128SSimon Glass * Bad configuration: 0 100bbb0b128SSimon Glass * Strange test result: 0 101bbb0b128SSimon Glass 102bbb0b128SSimon GlassYou will also find a useful ftdump utility for decoding a binary file. 103bbb0b128SSimon Glass 104bbb0b128SSimon Glass 105bbb0b128SSimon GlassWhere do I get an fdt file for my board? 106bbb0b128SSimon Glass---------------------------------------- 107bbb0b128SSimon Glass 108bbb0b128SSimon GlassYou may find that the Linux kernel has a suitable file. Look in the 109bbb0b128SSimon Glasskernel source in arch/<arch>/boot/dts. 110bbb0b128SSimon Glass 111bbb0b128SSimon GlassIf not you might find other boards with suitable files that you can 112bbb0b128SSimon Glassmodify to your needs. Look in the board directories for files with a 113bbb0b128SSimon Glass.dts extension. 114bbb0b128SSimon Glass 115bbb0b128SSimon GlassFailing that, you could write one from scratch yourself! 116bbb0b128SSimon Glass 117bbb0b128SSimon Glass 118bbb0b128SSimon GlassConfiguration 119bbb0b128SSimon Glass------------- 120bbb0b128SSimon Glass 121bbb0b128SSimon GlassUse: 122bbb0b128SSimon Glass 123bbb0b128SSimon Glass#define CONFIG_DEFAULT_DEVICE_TREE "<name>" 124bbb0b128SSimon Glass 125bbb0b128SSimon Glassto set the filename of the device tree source. Then put your device tree 126bbb0b128SSimon Glassfile into 127bbb0b128SSimon Glass 128bbb0b128SSimon Glass board/<vendor>/dts/<name>.dts 129bbb0b128SSimon Glass 130bbb0b128SSimon GlassThis should include your CPU or SOC's device tree file, placed in 131bbb0b128SSimon Glassarch/<arch>/dts, and then make any adjustments required. The name of this 132bbb0b128SSimon Glassis CONFIG_ARCH_DEVICE_TREE.dts. 133bbb0b128SSimon Glass 134bbb0b128SSimon GlassIf CONFIG_OF_EMBED is defined, then it will be picked up and built into 135bbb0b128SSimon Glassthe U-Boot image (including u-boot.bin). 136bbb0b128SSimon Glass 137bbb0b128SSimon GlassIf CONFIG_OF_SEPARATE is defined, then it will be built and placed in 138bbb0b128SSimon Glassa u-boot.dtb file alongside u-boot.bin. A common approach is then to 139bbb0b128SSimon Glassjoin the two: 140bbb0b128SSimon Glass 141bbb0b128SSimon Glass cat u-boot.bin u-boot.dtb >image.bin 142bbb0b128SSimon Glass 143bbb0b128SSimon Glassand then flash image.bin onto your board. 144bbb0b128SSimon Glass 145bbb0b128SSimon GlassYou cannot use both of these options at the same time. 146bbb0b128SSimon Glass 147*eea63e05SSimon GlassIf you wish to put the fdt at a different address in memory, you can 148*eea63e05SSimon Glassdefine the "fdtcontroladdr" environment variable. This is the hex 149*eea63e05SSimon Glassaddress of the fdt binary blob, and will override either of the options. 150*eea63e05SSimon GlassBe aware that this environment variable is checked prior to relocation, 151*eea63e05SSimon Glasswhen only the compiled-in environment is available. Therefore it is not 152*eea63e05SSimon Glasspossible to define this variable in the saved SPI/NAND flash 153*eea63e05SSimon Glassenvironment, for example (it will be ignored). 154*eea63e05SSimon Glass 155*eea63e05SSimon GlassTo use this, put something like this in your board header file: 156*eea63e05SSimon Glass 157*eea63e05SSimon Glass#define CONFIG_EXTRA_ENV_SETTINGS "fdtcontroladdr=10000\0" 158*eea63e05SSimon Glass 159bbb0b128SSimon Glass 160bbb0b128SSimon GlassLimitations 161bbb0b128SSimon Glass----------- 162bbb0b128SSimon Glass 163bbb0b128SSimon GlassU-Boot is designed to build with a single architecture type and CPU 164bbb0b128SSimon Glasstype. So for example it is not possible to build a single ARM binary 165bbb0b128SSimon Glasswhich runs on your AT91 and OMAP boards, relying on an fdt to configure 166bbb0b128SSimon Glassthe various features. This is because you must select one of 167bbb0b128SSimon Glassthe CPU families within arch/arm/cpu/arm926ejs (omap or at91) at build 168bbb0b128SSimon Glasstime. Similarly you cannot build for multiple cpu types or 169bbb0b128SSimon Glassarchitectures. 170bbb0b128SSimon Glass 171bbb0b128SSimon GlassThat said the complexity reduction by using fdt to support variants of 172bbb0b128SSimon Glassboards which use the same SOC / CPU can be substantial. 173bbb0b128SSimon Glass 174bbb0b128SSimon GlassIt is important to understand that the fdt only selects options 175bbb0b128SSimon Glassavailable in the platform / drivers. It cannot add new drivers (yet). So 176bbb0b128SSimon Glassyou must still have the CONFIG option to enable the driver. For example, 177bbb0b128SSimon Glassyou need to define CONFIG_SYS_NS16550 to bring in the NS16550 driver, 178bbb0b128SSimon Glassbut can use the fdt to specific the UART clock, peripheral address, etc. 179bbb0b128SSimon GlassIn very broad terms, the CONFIG options in general control *what* driver 180bbb0b128SSimon Glassfiles are pulled in, and the fdt controls *how* those files work. 181bbb0b128SSimon Glass 182bbb0b128SSimon Glass-- 183bbb0b128SSimon GlassSimon Glass <sjg@chromium.org> 184bbb0b128SSimon Glass1-Sep-11 185