PageRenderTime 40ms CodeModel.GetById 22ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Documentation/powerpc/booting-without-of.txt

https://bitbucket.org/abioy/linux
Plain Text | 1474 lines | 1197 code | 277 blank | 0 comment | 0 complexity | 1b7eb950c8a73884eab80fa7d74f2ac0 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

   1           Booting the Linux/ppc kernel without Open Firmware
   2           --------------------------------------------------
   3
   4(c) 2005 Benjamin Herrenschmidt <benh at kernel.crashing.org>,
   5    IBM Corp.
   6(c) 2005 Becky Bruce <becky.bruce at freescale.com>,
   7    Freescale Semiconductor, FSL SOC and 32-bit additions
   8(c) 2006 MontaVista Software, Inc.
   9    Flash chip node definition
  10
  11Table of Contents
  12=================
  13
  14  I - Introduction
  15    1) Entry point for arch/powerpc
  16    2) Board support
  17
  18  II - The DT block format
  19    1) Header
  20    2) Device tree generalities
  21    3) Device tree "structure" block
  22    4) Device tree "strings" block
  23
  24  III - Required content of the device tree
  25    1) Note about cells and address representation
  26    2) Note about "compatible" properties
  27    3) Note about "name" properties
  28    4) Note about node and property names and character set
  29    5) Required nodes and properties
  30      a) The root node
  31      b) The /cpus node
  32      c) The /cpus/* nodes
  33      d) the /memory node(s)
  34      e) The /chosen node
  35      f) the /soc<SOCname> node
  36
  37  IV - "dtc", the device tree compiler
  38
  39  V - Recommendations for a bootloader
  40
  41  VI - System-on-a-chip devices and nodes
  42    1) Defining child nodes of an SOC
  43    2) Representing devices without a current OF specification
  44      a) PHY nodes
  45      b) Interrupt controllers
  46      c) 4xx/Axon EMAC ethernet nodes
  47      d) Xilinx IP cores
  48      e) USB EHCI controllers
  49      f) MDIO on GPIOs
  50      g) SPI busses
  51
  52  VII - Marvell Discovery mv64[345]6x System Controller chips
  53    1) The /system-controller node
  54    2) Child nodes of /system-controller
  55      a) Marvell Discovery MDIO bus
  56      b) Marvell Discovery ethernet controller
  57      c) Marvell Discovery PHY nodes
  58      d) Marvell Discovery SDMA nodes
  59      e) Marvell Discovery BRG nodes
  60      f) Marvell Discovery CUNIT nodes
  61      g) Marvell Discovery MPSCROUTING nodes
  62      h) Marvell Discovery MPSCINTR nodes
  63      i) Marvell Discovery MPSC nodes
  64      j) Marvell Discovery Watch Dog Timer nodes
  65      k) Marvell Discovery I2C nodes
  66      l) Marvell Discovery PIC (Programmable Interrupt Controller) nodes
  67      m) Marvell Discovery MPP (Multipurpose Pins) multiplexing nodes
  68      n) Marvell Discovery GPP (General Purpose Pins) nodes
  69      o) Marvell Discovery PCI host bridge node
  70      p) Marvell Discovery CPU Error nodes
  71      q) Marvell Discovery SRAM Controller nodes
  72      r) Marvell Discovery PCI Error Handler nodes
  73      s) Marvell Discovery Memory Controller nodes
  74
  75  VIII - Specifying interrupt information for devices
  76    1) interrupts property
  77    2) interrupt-parent property
  78    3) OpenPIC Interrupt Controllers
  79    4) ISA Interrupt Controllers
  80
  81  IX - Specifying GPIO information for devices
  82    1) gpios property
  83    2) gpio-controller nodes
  84
  85  X - Specifying device power management information (sleep property)
  86
  87  Appendix A - Sample SOC node for MPC8540
  88
  89
  90Revision Information
  91====================
  92
  93   May 18, 2005: Rev 0.1 - Initial draft, no chapter III yet.
  94
  95   May 19, 2005: Rev 0.2 - Add chapter III and bits & pieces here or
  96                           clarifies the fact that a lot of things are
  97                           optional, the kernel only requires a very
  98                           small device tree, though it is encouraged
  99                           to provide an as complete one as possible.
 100
 101   May 24, 2005: Rev 0.3 - Precise that DT block has to be in RAM
 102			 - Misc fixes
 103			 - Define version 3 and new format version 16
 104			   for the DT block (version 16 needs kernel
 105			   patches, will be fwd separately).
 106			   String block now has a size, and full path
 107			   is replaced by unit name for more
 108			   compactness.
 109			   linux,phandle is made optional, only nodes
 110			   that are referenced by other nodes need it.
 111			   "name" property is now automatically
 112			   deduced from the unit name
 113
 114   June 1, 2005: Rev 0.4 - Correct confusion between OF_DT_END and
 115                           OF_DT_END_NODE in structure definition.
 116                         - Change version 16 format to always align
 117                           property data to 4 bytes. Since tokens are
 118                           already aligned, that means no specific
 119                           required alignment between property size
 120                           and property data. The old style variable
 121                           alignment would make it impossible to do
 122                           "simple" insertion of properties using
 123                           memmove (thanks Milton for
 124                           noticing). Updated kernel patch as well
 125			 - Correct a few more alignment constraints
 126			 - Add a chapter about the device-tree
 127                           compiler and the textural representation of
 128                           the tree that can be "compiled" by dtc.
 129
 130   November 21, 2005: Rev 0.5
 131			 - Additions/generalizations for 32-bit
 132			 - Changed to reflect the new arch/powerpc
 133			   structure
 134			 - Added chapter VI
 135
 136
 137 ToDo:
 138	- Add some definitions of interrupt tree (simple/complex)
 139	- Add some definitions for PCI host bridges
 140	- Add some common address format examples
 141	- Add definitions for standard properties and "compatible"
 142	  names for cells that are not already defined by the existing
 143	  OF spec.
 144	- Compare FSL SOC use of PCI to standard and make sure no new
 145	  node definition required.
 146	- Add more information about node definitions for SOC devices
 147  	  that currently have no standard, like the FSL CPM.
 148
 149
 150I - Introduction
 151================
 152
 153During the recent development of the Linux/ppc64 kernel, and more
 154specifically, the addition of new platform types outside of the old
 155IBM pSeries/iSeries pair, it was decided to enforce some strict rules
 156regarding the kernel entry and bootloader <-> kernel interfaces, in
 157order to avoid the degeneration that had become the ppc32 kernel entry
 158point and the way a new platform should be added to the kernel. The
 159legacy iSeries platform breaks those rules as it predates this scheme,
 160but no new board support will be accepted in the main tree that
 161doesn't follows them properly.  In addition, since the advent of the
 162arch/powerpc merged architecture for ppc32 and ppc64, new 32-bit
 163platforms and 32-bit platforms which move into arch/powerpc will be
 164required to use these rules as well.
 165
 166The main requirement that will be defined in more detail below is
 167the presence of a device-tree whose format is defined after Open
 168Firmware specification. However, in order to make life easier
 169to embedded board vendors, the kernel doesn't require the device-tree
 170to represent every device in the system and only requires some nodes
 171and properties to be present. This will be described in detail in
 172section III, but, for example, the kernel does not require you to
 173create a node for every PCI device in the system. It is a requirement
 174to have a node for PCI host bridges in order to provide interrupt
 175routing informations and memory/IO ranges, among others. It is also
 176recommended to define nodes for on chip devices and other busses that
 177don't specifically fit in an existing OF specification. This creates a
 178great flexibility in the way the kernel can then probe those and match
 179drivers to device, without having to hard code all sorts of tables. It
 180also makes it more flexible for board vendors to do minor hardware
 181upgrades without significantly impacting the kernel code or cluttering
 182it with special cases.
 183
 184
 1851) Entry point for arch/powerpc
 186-------------------------------
 187
 188   There is one and one single entry point to the kernel, at the start
 189   of the kernel image. That entry point supports two calling
 190   conventions:
 191
 192        a) Boot from Open Firmware. If your firmware is compatible
 193        with Open Firmware (IEEE 1275) or provides an OF compatible
 194        client interface API (support for "interpret" callback of
 195        forth words isn't required), you can enter the kernel with:
 196
 197              r5 : OF callback pointer as defined by IEEE 1275
 198              bindings to powerpc. Only the 32-bit client interface
 199              is currently supported
 200
 201              r3, r4 : address & length of an initrd if any or 0
 202
 203              The MMU is either on or off; the kernel will run the
 204              trampoline located in arch/powerpc/kernel/prom_init.c to
 205              extract the device-tree and other information from open
 206              firmware and build a flattened device-tree as described
 207              in b). prom_init() will then re-enter the kernel using
 208              the second method. This trampoline code runs in the
 209              context of the firmware, which is supposed to handle all
 210              exceptions during that time.
 211
 212        b) Direct entry with a flattened device-tree block. This entry
 213        point is called by a) after the OF trampoline and can also be
 214        called directly by a bootloader that does not support the Open
 215        Firmware client interface. It is also used by "kexec" to
 216        implement "hot" booting of a new kernel from a previous
 217        running one. This method is what I will describe in more
 218        details in this document, as method a) is simply standard Open
 219        Firmware, and thus should be implemented according to the
 220        various standard documents defining it and its binding to the
 221        PowerPC platform. The entry point definition then becomes:
 222
 223                r3 : physical pointer to the device-tree block
 224                (defined in chapter II) in RAM
 225
 226                r4 : physical pointer to the kernel itself. This is
 227                used by the assembly code to properly disable the MMU
 228                in case you are entering the kernel with MMU enabled
 229                and a non-1:1 mapping.
 230
 231                r5 : NULL (as to differentiate with method a)
 232
 233        Note about SMP entry: Either your firmware puts your other
 234        CPUs in some sleep loop or spin loop in ROM where you can get
 235        them out via a soft reset or some other means, in which case
 236        you don't need to care, or you'll have to enter the kernel
 237        with all CPUs. The way to do that with method b) will be
 238        described in a later revision of this document.
 239
 240
 2412) Board support
 242----------------
 243
 24464-bit kernels:
 245
 246   Board supports (platforms) are not exclusive config options. An
 247   arbitrary set of board supports can be built in a single kernel
 248   image. The kernel will "know" what set of functions to use for a
 249   given platform based on the content of the device-tree. Thus, you
 250   should:
 251
 252        a) add your platform support as a _boolean_ option in
 253        arch/powerpc/Kconfig, following the example of PPC_PSERIES,
 254        PPC_PMAC and PPC_MAPLE. The later is probably a good
 255        example of a board support to start from.
 256
 257        b) create your main platform file as
 258        "arch/powerpc/platforms/myplatform/myboard_setup.c" and add it
 259        to the Makefile under the condition of your CONFIG_
 260        option. This file will define a structure of type "ppc_md"
 261        containing the various callbacks that the generic code will
 262        use to get to your platform specific code
 263
 264        c) Add a reference to your "ppc_md" structure in the
 265        "machines" table in arch/powerpc/kernel/setup_64.c if you are
 266        a 64-bit platform.
 267
 268        d) request and get assigned a platform number (see PLATFORM_*
 269        constants in arch/powerpc/include/asm/processor.h
 270
 27132-bit embedded kernels:
 272
 273  Currently, board support is essentially an exclusive config option.
 274  The kernel is configured for a single platform.  Part of the reason
 275  for this is to keep kernels on embedded systems small and efficient;
 276  part of this is due to the fact the code is already that way. In the
 277  future, a kernel may support multiple platforms, but only if the
 278  platforms feature the same core architecture.  A single kernel build
 279  cannot support both configurations with Book E and configurations
 280  with classic Powerpc architectures.
 281
 282  32-bit embedded platforms that are moved into arch/powerpc using a
 283  flattened device tree should adopt the merged tree practice of
 284  setting ppc_md up dynamically, even though the kernel is currently
 285  built with support for only a single platform at a time.  This allows
 286  unification of the setup code, and will make it easier to go to a
 287  multiple-platform-support model in the future.
 288
 289NOTE: I believe the above will be true once Ben's done with the merge
 290of the boot sequences.... someone speak up if this is wrong!
 291
 292  To add a 32-bit embedded platform support, follow the instructions
 293  for 64-bit platforms above, with the exception that the Kconfig
 294  option should be set up such that the kernel builds exclusively for
 295  the platform selected.  The processor type for the platform should
 296  enable another config option to select the specific board
 297  supported.
 298
 299NOTE: If Ben doesn't merge the setup files, may need to change this to
 300point to setup_32.c
 301
 302
 303   I will describe later the boot process and various callbacks that
 304   your platform should implement.
 305
 306
 307II - The DT block format
 308========================
 309
 310
 311This chapter defines the actual format of the flattened device-tree
 312passed to the kernel. The actual content of it and kernel requirements
 313are described later. You can find example of code manipulating that
 314format in various places, including arch/powerpc/kernel/prom_init.c
 315which will generate a flattened device-tree from the Open Firmware
 316representation, or the fs2dt utility which is part of the kexec tools
 317which will generate one from a filesystem representation. It is
 318expected that a bootloader like uboot provides a bit more support,
 319that will be discussed later as well.
 320
 321Note: The block has to be in main memory. It has to be accessible in
 322both real mode and virtual mode with no mapping other than main
 323memory. If you are writing a simple flash bootloader, it should copy
 324the block to RAM before passing it to the kernel.
 325
 326
 3271) Header
 328---------
 329
 330   The kernel is entered with r3 pointing to an area of memory that is
 331   roughly described in arch/powerpc/include/asm/prom.h by the structure
 332   boot_param_header:
 333
 334struct boot_param_header {
 335        u32     magic;                  /* magic word OF_DT_HEADER */
 336        u32     totalsize;              /* total size of DT block */
 337        u32     off_dt_struct;          /* offset to structure */
 338        u32     off_dt_strings;         /* offset to strings */
 339        u32     off_mem_rsvmap;         /* offset to memory reserve map
 340                                           */
 341        u32     version;                /* format version */
 342        u32     last_comp_version;      /* last compatible version */
 343
 344        /* version 2 fields below */
 345        u32     boot_cpuid_phys;        /* Which physical CPU id we're
 346                                           booting on */
 347        /* version 3 fields below */
 348        u32     size_dt_strings;        /* size of the strings block */
 349
 350        /* version 17 fields below */
 351        u32	size_dt_struct;		/* size of the DT structure block */
 352};
 353
 354   Along with the constants:
 355
 356/* Definitions used by the flattened device tree */
 357#define OF_DT_HEADER            0xd00dfeed      /* 4: version,
 358						   4: total size */
 359#define OF_DT_BEGIN_NODE        0x1             /* Start node: full name
 360						   */
 361#define OF_DT_END_NODE          0x2             /* End node */
 362#define OF_DT_PROP              0x3             /* Property: name off,
 363                                                   size, content */
 364#define OF_DT_END               0x9
 365
 366   All values in this header are in big endian format, the various
 367   fields in this header are defined more precisely below. All
 368   "offset" values are in bytes from the start of the header; that is
 369   from the value of r3.
 370
 371   - magic
 372
 373     This is a magic value that "marks" the beginning of the
 374     device-tree block header. It contains the value 0xd00dfeed and is
 375     defined by the constant OF_DT_HEADER
 376
 377   - totalsize
 378
 379     This is the total size of the DT block including the header. The
 380     "DT" block should enclose all data structures defined in this
 381     chapter (who are pointed to by offsets in this header). That is,
 382     the device-tree structure, strings, and the memory reserve map.
 383
 384   - off_dt_struct
 385
 386     This is an offset from the beginning of the header to the start
 387     of the "structure" part the device tree. (see 2) device tree)
 388
 389   - off_dt_strings
 390
 391     This is an offset from the beginning of the header to the start
 392     of the "strings" part of the device-tree
 393
 394   - off_mem_rsvmap
 395
 396     This is an offset from the beginning of the header to the start
 397     of the reserved memory map. This map is a list of pairs of 64-
 398     bit integers. Each pair is a physical address and a size. The
 399     list is terminated by an entry of size 0. This map provides the
 400     kernel with a list of physical memory areas that are "reserved"
 401     and thus not to be used for memory allocations, especially during
 402     early initialization. The kernel needs to allocate memory during
 403     boot for things like un-flattening the device-tree, allocating an
 404     MMU hash table, etc... Those allocations must be done in such a
 405     way to avoid overriding critical things like, on Open Firmware
 406     capable machines, the RTAS instance, or on some pSeries, the TCE
 407     tables used for the iommu. Typically, the reserve map should
 408     contain _at least_ this DT block itself (header,total_size). If
 409     you are passing an initrd to the kernel, you should reserve it as
 410     well. You do not need to reserve the kernel image itself. The map
 411     should be 64-bit aligned.
 412
 413   - version
 414
 415     This is the version of this structure. Version 1 stops
 416     here. Version 2 adds an additional field boot_cpuid_phys.
 417     Version 3 adds the size of the strings block, allowing the kernel
 418     to reallocate it easily at boot and free up the unused flattened
 419     structure after expansion. Version 16 introduces a new more
 420     "compact" format for the tree itself that is however not backward
 421     compatible. Version 17 adds an additional field, size_dt_struct,
 422     allowing it to be reallocated or moved more easily (this is
 423     particularly useful for bootloaders which need to make
 424     adjustments to a device tree based on probed information). You
 425     should always generate a structure of the highest version defined
 426     at the time of your implementation. Currently that is version 17,
 427     unless you explicitly aim at being backward compatible.
 428
 429   - last_comp_version
 430
 431     Last compatible version. This indicates down to what version of
 432     the DT block you are backward compatible. For example, version 2
 433     is backward compatible with version 1 (that is, a kernel build
 434     for version 1 will be able to boot with a version 2 format). You
 435     should put a 1 in this field if you generate a device tree of
 436     version 1 to 3, or 16 if you generate a tree of version 16 or 17
 437     using the new unit name format.
 438
 439   - boot_cpuid_phys
 440
 441     This field only exist on version 2 headers. It indicate which
 442     physical CPU ID is calling the kernel entry point. This is used,
 443     among others, by kexec. If you are on an SMP system, this value
 444     should match the content of the "reg" property of the CPU node in
 445     the device-tree corresponding to the CPU calling the kernel entry
 446     point (see further chapters for more informations on the required
 447     device-tree contents)
 448
 449   - size_dt_strings
 450
 451     This field only exists on version 3 and later headers.  It
 452     gives the size of the "strings" section of the device tree (which
 453     starts at the offset given by off_dt_strings).
 454
 455   - size_dt_struct
 456
 457     This field only exists on version 17 and later headers.  It gives
 458     the size of the "structure" section of the device tree (which
 459     starts at the offset given by off_dt_struct).
 460
 461   So the typical layout of a DT block (though the various parts don't
 462   need to be in that order) looks like this (addresses go from top to
 463   bottom):
 464
 465
 466             ------------------------------
 467       r3 -> |  struct boot_param_header  |
 468             ------------------------------
 469             |      (alignment gap) (*)   |
 470             ------------------------------
 471             |      memory reserve map    |
 472             ------------------------------
 473             |      (alignment gap)       |
 474             ------------------------------
 475             |                            |
 476             |    device-tree structure   |
 477             |                            |
 478             ------------------------------
 479             |      (alignment gap)       |
 480             ------------------------------
 481             |                            |
 482             |     device-tree strings    |
 483             |                            |
 484      -----> ------------------------------
 485      |
 486      |
 487      --- (r3 + totalsize)
 488
 489  (*) The alignment gaps are not necessarily present; their presence
 490      and size are dependent on the various alignment requirements of
 491      the individual data blocks.
 492
 493
 4942) Device tree generalities
 495---------------------------
 496
 497This device-tree itself is separated in two different blocks, a
 498structure block and a strings block. Both need to be aligned to a 4
 499byte boundary.
 500
 501First, let's quickly describe the device-tree concept before detailing
 502the storage format. This chapter does _not_ describe the detail of the
 503required types of nodes & properties for the kernel, this is done
 504later in chapter III.
 505
 506The device-tree layout is strongly inherited from the definition of
 507the Open Firmware IEEE 1275 device-tree. It's basically a tree of
 508nodes, each node having two or more named properties. A property can
 509have a value or not.
 510
 511It is a tree, so each node has one and only one parent except for the
 512root node who has no parent.
 513
 514A node has 2 names. The actual node name is generally contained in a
 515property of type "name" in the node property list whose value is a
 516zero terminated string and is mandatory for version 1 to 3 of the
 517format definition (as it is in Open Firmware). Version 16 makes it
 518optional as it can generate it from the unit name defined below.
 519
 520There is also a "unit name" that is used to differentiate nodes with
 521the same name at the same level, it is usually made of the node
 522names, the "@" sign, and a "unit address", which definition is
 523specific to the bus type the node sits on.
 524
 525The unit name doesn't exist as a property per-se but is included in
 526the device-tree structure. It is typically used to represent "path" in
 527the device-tree. More details about the actual format of these will be
 528below.
 529
 530The kernel powerpc generic code does not make any formal use of the
 531unit address (though some board support code may do) so the only real
 532requirement here for the unit address is to ensure uniqueness of
 533the node unit name at a given level of the tree. Nodes with no notion
 534of address and no possible sibling of the same name (like /memory or
 535/cpus) may omit the unit address in the context of this specification,
 536or use the "@0" default unit address. The unit name is used to define
 537a node "full path", which is the concatenation of all parent node
 538unit names separated with "/".
 539
 540The root node doesn't have a defined name, and isn't required to have
 541a name property either if you are using version 3 or earlier of the
 542format. It also has no unit address (no @ symbol followed by a unit
 543address). The root node unit name is thus an empty string. The full
 544path to the root node is "/".
 545
 546Every node which actually represents an actual device (that is, a node
 547which isn't only a virtual "container" for more nodes, like "/cpus"
 548is) is also required to have a "device_type" property indicating the
 549type of node .
 550
 551Finally, every node that can be referenced from a property in another
 552node is required to have a "linux,phandle" property. Real open
 553firmware implementations provide a unique "phandle" value for every
 554node that the "prom_init()" trampoline code turns into
 555"linux,phandle" properties. However, this is made optional if the
 556flattened device tree is used directly. An example of a node
 557referencing another node via "phandle" is when laying out the
 558interrupt tree which will be described in a further version of this
 559document.
 560
 561This "linux, phandle" property is a 32-bit value that uniquely
 562identifies a node. You are free to use whatever values or system of
 563values, internal pointers, or whatever to generate these, the only
 564requirement is that every node for which you provide that property has
 565a unique value for it.
 566
 567Here is an example of a simple device-tree. In this example, an "o"
 568designates a node followed by the node unit name. Properties are
 569presented with their name followed by their content. "content"
 570represents an ASCII string (zero terminated) value, while <content>
 571represents a 32-bit hexadecimal value. The various nodes in this
 572example will be discussed in a later chapter. At this point, it is
 573only meant to give you a idea of what a device-tree looks like. I have
 574purposefully kept the "name" and "linux,phandle" properties which
 575aren't necessary in order to give you a better idea of what the tree
 576looks like in practice.
 577
 578  / o device-tree
 579      |- name = "device-tree"
 580      |- model = "MyBoardName"
 581      |- compatible = "MyBoardFamilyName"
 582      |- #address-cells = <2>
 583      |- #size-cells = <2>
 584      |- linux,phandle = <0>
 585      |
 586      o cpus
 587      | | - name = "cpus"
 588      | | - linux,phandle = <1>
 589      | | - #address-cells = <1>
 590      | | - #size-cells = <0>
 591      | |
 592      | o PowerPC,970@0
 593      |   |- name = "PowerPC,970"
 594      |   |- device_type = "cpu"
 595      |   |- reg = <0>
 596      |   |- clock-frequency = <5f5e1000>
 597      |   |- 64-bit
 598      |   |- linux,phandle = <2>
 599      |
 600      o memory@0
 601      | |- name = "memory"
 602      | |- device_type = "memory"
 603      | |- reg = <00000000 00000000 00000000 20000000>
 604      | |- linux,phandle = <3>
 605      |
 606      o chosen
 607        |- name = "chosen"
 608        |- bootargs = "root=/dev/sda2"
 609        |- linux,phandle = <4>
 610
 611This tree is almost a minimal tree. It pretty much contains the
 612minimal set of required nodes and properties to boot a linux kernel;
 613that is, some basic model informations at the root, the CPUs, and the
 614physical memory layout.  It also includes misc information passed
 615through /chosen, like in this example, the platform type (mandatory)
 616and the kernel command line arguments (optional).
 617
 618The /cpus/PowerPC,970@0/64-bit property is an example of a
 619property without a value. All other properties have a value. The
 620significance of the #address-cells and #size-cells properties will be
 621explained in chapter IV which defines precisely the required nodes and
 622properties and their content.
 623
 624
 6253) Device tree "structure" block
 626
 627The structure of the device tree is a linearized tree structure. The
 628"OF_DT_BEGIN_NODE" token starts a new node, and the "OF_DT_END_NODE"
 629ends that node definition. Child nodes are simply defined before
 630"OF_DT_END_NODE" (that is nodes within the node). A 'token' is a 32
 631bit value. The tree has to be "finished" with a OF_DT_END token
 632
 633Here's the basic structure of a single node:
 634
 635     * token OF_DT_BEGIN_NODE (that is 0x00000001)
 636     * for version 1 to 3, this is the node full path as a zero
 637       terminated string, starting with "/". For version 16 and later,
 638       this is the node unit name only (or an empty string for the
 639       root node)
 640     * [align gap to next 4 bytes boundary]
 641     * for each property:
 642        * token OF_DT_PROP (that is 0x00000003)
 643        * 32-bit value of property value size in bytes (or 0 if no
 644          value)
 645        * 32-bit value of offset in string block of property name
 646        * property value data if any
 647        * [align gap to next 4 bytes boundary]
 648     * [child nodes if any]
 649     * token OF_DT_END_NODE (that is 0x00000002)
 650
 651So the node content can be summarized as a start token, a full path,
 652a list of properties, a list of child nodes, and an end token. Every
 653child node is a full node structure itself as defined above.
 654
 655NOTE: The above definition requires that all property definitions for
 656a particular node MUST precede any subnode definitions for that node.
 657Although the structure would not be ambiguous if properties and
 658subnodes were intermingled, the kernel parser requires that the
 659properties come first (up until at least 2.6.22).  Any tools
 660manipulating a flattened tree must take care to preserve this
 661constraint.
 662
 6634) Device tree "strings" block
 664
 665In order to save space, property names, which are generally redundant,
 666are stored separately in the "strings" block. This block is simply the
 667whole bunch of zero terminated strings for all property names
 668concatenated together. The device-tree property definitions in the
 669structure block will contain offset values from the beginning of the
 670strings block.
 671
 672
 673III - Required content of the device tree
 674=========================================
 675
 676WARNING: All "linux,*" properties defined in this document apply only
 677to a flattened device-tree. If your platform uses a real
 678implementation of Open Firmware or an implementation compatible with
 679the Open Firmware client interface, those properties will be created
 680by the trampoline code in the kernel's prom_init() file. For example,
 681that's where you'll have to add code to detect your board model and
 682set the platform number. However, when using the flattened device-tree
 683entry point, there is no prom_init() pass, and thus you have to
 684provide those properties yourself.
 685
 686
 6871) Note about cells and address representation
 688----------------------------------------------
 689
 690The general rule is documented in the various Open Firmware
 691documentations. If you choose to describe a bus with the device-tree
 692and there exist an OF bus binding, then you should follow the
 693specification. However, the kernel does not require every single
 694device or bus to be described by the device tree.
 695
 696In general, the format of an address for a device is defined by the
 697parent bus type, based on the #address-cells and #size-cells
 698properties.  Note that the parent's parent definitions of #address-cells
 699and #size-cells are not inherited so every node with children must specify
 700them.  The kernel requires the root node to have those properties defining
 701addresses format for devices directly mapped on the processor bus.
 702
 703Those 2 properties define 'cells' for representing an address and a
 704size. A "cell" is a 32-bit number. For example, if both contain 2
 705like the example tree given above, then an address and a size are both
 706composed of 2 cells, and each is a 64-bit number (cells are
 707concatenated and expected to be in big endian format). Another example
 708is the way Apple firmware defines them, with 2 cells for an address
 709and one cell for a size.  Most 32-bit implementations should define
 710#address-cells and #size-cells to 1, which represents a 32-bit value.
 711Some 32-bit processors allow for physical addresses greater than 32
 712bits; these processors should define #address-cells as 2.
 713
 714"reg" properties are always a tuple of the type "address size" where
 715the number of cells of address and size is specified by the bus
 716#address-cells and #size-cells. When a bus supports various address
 717spaces and other flags relative to a given address allocation (like
 718prefetchable, etc...) those flags are usually added to the top level
 719bits of the physical address. For example, a PCI physical address is
 720made of 3 cells, the bottom two containing the actual address itself
 721while the top cell contains address space indication, flags, and pci
 722bus & device numbers.
 723
 724For busses that support dynamic allocation, it's the accepted practice
 725to then not provide the address in "reg" (keep it 0) though while
 726providing a flag indicating the address is dynamically allocated, and
 727then, to provide a separate "assigned-addresses" property that
 728contains the fully allocated addresses. See the PCI OF bindings for
 729details.
 730
 731In general, a simple bus with no address space bits and no dynamic
 732allocation is preferred if it reflects your hardware, as the existing
 733kernel address parsing functions will work out of the box. If you
 734define a bus type with a more complex address format, including things
 735like address space bits, you'll have to add a bus translator to the
 736prom_parse.c file of the recent kernels for your bus type.
 737
 738The "reg" property only defines addresses and sizes (if #size-cells is
 739non-0) within a given bus. In order to translate addresses upward
 740(that is into parent bus addresses, and possibly into CPU physical
 741addresses), all busses must contain a "ranges" property. If the
 742"ranges" property is missing at a given level, it's assumed that
 743translation isn't possible, i.e., the registers are not visible on the
 744parent bus.  The format of the "ranges" property for a bus is a list
 745of:
 746
 747	bus address, parent bus address, size
 748
 749"bus address" is in the format of the bus this bus node is defining,
 750that is, for a PCI bridge, it would be a PCI address. Thus, (bus
 751address, size) defines a range of addresses for child devices. "parent
 752bus address" is in the format of the parent bus of this bus. For
 753example, for a PCI host controller, that would be a CPU address. For a
 754PCI<->ISA bridge, that would be a PCI address. It defines the base
 755address in the parent bus where the beginning of that range is mapped.
 756
 757For a new 64-bit powerpc board, I recommend either the 2/2 format or
 758Apple's 2/1 format which is slightly more compact since sizes usually
 759fit in a single 32-bit word.   New 32-bit powerpc boards should use a
 7601/1 format, unless the processor supports physical addresses greater
 761than 32-bits, in which case a 2/1 format is recommended.
 762
 763Alternatively, the "ranges" property may be empty, indicating that the
 764registers are visible on the parent bus using an identity mapping
 765translation.  In other words, the parent bus address space is the same
 766as the child bus address space.
 767
 7682) Note about "compatible" properties
 769-------------------------------------
 770
 771These properties are optional, but recommended in devices and the root
 772node. The format of a "compatible" property is a list of concatenated
 773zero terminated strings. They allow a device to express its
 774compatibility with a family of similar devices, in some cases,
 775allowing a single driver to match against several devices regardless
 776of their actual names.
 777
 7783) Note about "name" properties
 779-------------------------------
 780
 781While earlier users of Open Firmware like OldWorld macintoshes tended
 782to use the actual device name for the "name" property, it's nowadays
 783considered a good practice to use a name that is closer to the device
 784class (often equal to device_type). For example, nowadays, ethernet
 785controllers are named "ethernet", an additional "model" property
 786defining precisely the chip type/model, and "compatible" property
 787defining the family in case a single driver can driver more than one
 788of these chips. However, the kernel doesn't generally put any
 789restriction on the "name" property; it is simply considered good
 790practice to follow the standard and its evolutions as closely as
 791possible.
 792
 793Note also that the new format version 16 makes the "name" property
 794optional. If it's absent for a node, then the node's unit name is then
 795used to reconstruct the name. That is, the part of the unit name
 796before the "@" sign is used (or the entire unit name if no "@" sign
 797is present).
 798
 7994) Note about node and property names and character set
 800-------------------------------------------------------
 801
 802While open firmware provides more flexible usage of 8859-1, this
 803specification enforces more strict rules. Nodes and properties should
 804be comprised only of ASCII characters 'a' to 'z', '0' to
 805'9', ',', '.', '_', '+', '#', '?', and '-'. Node names additionally
 806allow uppercase characters 'A' to 'Z' (property names should be
 807lowercase. The fact that vendors like Apple don't respect this rule is
 808irrelevant here). Additionally, node and property names should always
 809begin with a character in the range 'a' to 'z' (or 'A' to 'Z' for node
 810names).
 811
 812The maximum number of characters for both nodes and property names
 813is 31. In the case of node names, this is only the leftmost part of
 814a unit name (the pure "name" property), it doesn't include the unit
 815address which can extend beyond that limit.
 816
 817
 8185) Required nodes and properties
 819--------------------------------
 820  These are all that are currently required. However, it is strongly
 821  recommended that you expose PCI host bridges as documented in the
 822  PCI binding to open firmware, and your interrupt tree as documented
 823  in OF interrupt tree specification.
 824
 825  a) The root node
 826
 827  The root node requires some properties to be present:
 828
 829    - model : this is your board name/model
 830    - #address-cells : address representation for "root" devices
 831    - #size-cells: the size representation for "root" devices
 832    - device_type : This property shouldn't be necessary. However, if
 833      you decide to create a device_type for your root node, make sure it
 834      is _not_ "chrp" unless your platform is a pSeries or PAPR compliant
 835      one for 64-bit, or a CHRP-type machine for 32-bit as this will
 836      matched by the kernel this way.
 837
 838  Additionally, some recommended properties are:
 839
 840    - compatible : the board "family" generally finds its way here,
 841      for example, if you have 2 board models with a similar layout,
 842      that typically get driven by the same platform code in the
 843      kernel, you would use a different "model" property but put a
 844      value in "compatible". The kernel doesn't directly use that
 845      value but it is generally useful.
 846
 847  The root node is also generally where you add additional properties
 848  specific to your board like the serial number if any, that sort of
 849  thing. It is recommended that if you add any "custom" property whose
 850  name may clash with standard defined ones, you prefix them with your
 851  vendor name and a comma.
 852
 853  b) The /cpus node
 854
 855  This node is the parent of all individual CPU nodes. It doesn't
 856  have any specific requirements, though it's generally good practice
 857  to have at least:
 858
 859               #address-cells = <00000001>
 860               #size-cells    = <00000000>
 861
 862  This defines that the "address" for a CPU is a single cell, and has
 863  no meaningful size. This is not necessary but the kernel will assume
 864  that format when reading the "reg" properties of a CPU node, see
 865  below
 866
 867  c) The /cpus/* nodes
 868
 869  So under /cpus, you are supposed to create a node for every CPU on
 870  the machine. There is no specific restriction on the name of the
 871  CPU, though It's common practice to call it PowerPC,<name>. For
 872  example, Apple uses PowerPC,G5 while IBM uses PowerPC,970FX.
 873
 874  Required properties:
 875
 876    - device_type : has to be "cpu"
 877    - reg : This is the physical CPU number, it's a single 32-bit cell
 878      and is also used as-is as the unit number for constructing the
 879      unit name in the full path. For example, with 2 CPUs, you would
 880      have the full path:
 881        /cpus/PowerPC,970FX@0
 882        /cpus/PowerPC,970FX@1
 883      (unit addresses do not require leading zeroes)
 884    - d-cache-block-size : one cell, L1 data cache block size in bytes (*)
 885    - i-cache-block-size : one cell, L1 instruction cache block size in
 886      bytes
 887    - d-cache-size : one cell, size of L1 data cache in bytes
 888    - i-cache-size : one cell, size of L1 instruction cache in bytes
 889
 890(*) The cache "block" size is the size on which the cache management
 891instructions operate. Historically, this document used the cache
 892"line" size here which is incorrect. The kernel will prefer the cache
 893block size and will fallback to cache line size for backward
 894compatibility.
 895
 896  Recommended properties:
 897
 898    - timebase-frequency : a cell indicating the frequency of the
 899      timebase in Hz. This is not directly used by the generic code,
 900      but you are welcome to copy/paste the pSeries code for setting
 901      the kernel timebase/decrementer calibration based on this
 902      value.
 903    - clock-frequency : a cell indicating the CPU core clock frequency
 904      in Hz. A new property will be defined for 64-bit values, but if
 905      your frequency is < 4Ghz, one cell is enough. Here as well as
 906      for the above, the common code doesn't use that property, but
 907      you are welcome to re-use the pSeries or Maple one. A future
 908      kernel version might provide a common function for this.
 909    - d-cache-line-size : one cell, L1 data cache line size in bytes
 910      if different from the block size
 911    - i-cache-line-size : one cell, L1 instruction cache line size in
 912      bytes if different from the block size
 913
 914  You are welcome to add any property you find relevant to your board,
 915  like some information about the mechanism used to soft-reset the
 916  CPUs. For example, Apple puts the GPIO number for CPU soft reset
 917  lines in there as a "soft-reset" property since they start secondary
 918  CPUs by soft-resetting them.
 919
 920
 921  d) the /memory node(s)
 922
 923  To define the physical memory layout of your board, you should
 924  create one or more memory node(s). You can either create a single
 925  node with all memory ranges in its reg property, or you can create
 926  several nodes, as you wish. The unit address (@ part) used for the
 927  full path is the address of the first range of memory defined by a
 928  given node. If you use a single memory node, this will typically be
 929  @0.
 930
 931  Required properties:
 932
 933    - device_type : has to be "memory"
 934    - reg : This property contains all the physical memory ranges of
 935      your board. It's a list of addresses/sizes concatenated
 936      together, with the number of cells of each defined by the
 937      #address-cells and #size-cells of the root node. For example,
 938      with both of these properties being 2 like in the example given
 939      earlier, a 970 based machine with 6Gb of RAM could typically
 940      have a "reg" property here that looks like:
 941
 942      00000000 00000000 00000000 80000000
 943      00000001 00000000 00000001 00000000
 944
 945      That is a range starting at 0 of 0x80000000 bytes and a range
 946      starting at 0x100000000 and of 0x100000000 bytes. You can see
 947      that there is no memory covering the IO hole between 2Gb and
 948      4Gb. Some vendors prefer splitting those ranges into smaller
 949      segments, but the kernel doesn't care.
 950
 951  e) The /chosen node
 952
 953  This node is a bit "special". Normally, that's where open firmware
 954  puts some variable environment information, like the arguments, or
 955  the default input/output devices.
 956
 957  This specification makes a few of these mandatory, but also defines
 958  some linux-specific properties that would be normally constructed by
 959  the prom_init() trampoline when booting with an OF client interface,
 960  but that you have to provide yourself when using the flattened format.
 961
 962  Recommended properties:
 963
 964    - bootargs : This zero-terminated string is passed as the kernel
 965      command line
 966    - linux,stdout-path : This is the full path to your standard
 967      console device if any. Typically, if you have serial devices on
 968      your board, you may want to put the full path to the one set as
 969      the default console in the firmware here, for the kernel to pick
 970      it up as its own default console. If you look at the function
 971      set_preferred_console() in arch/ppc64/kernel/setup.c, you'll see
 972      that the kernel tries to find out the default console and has
 973      knowledge of various types like 8250 serial ports. You may want
 974      to extend this function to add your own.
 975
 976  Note that u-boot creates and fills in the chosen node for platforms
 977  that use it.
 978
 979  (Note: a practice that is now obsolete was to include a property
 980  under /chosen called interrupt-controller which had a phandle value
 981  that pointed to the main interrupt controller)
 982
 983  f) the /soc<SOCname> node
 984
 985  This node is used to represent a system-on-a-chip (SOC) and must be
 986  present if the processor is a SOC. The top-level soc node contains
 987  information that is global to all devices on the SOC. The node name
 988  should contain a unit address for the SOC, which is the base address
 989  of the memory-mapped register set for the SOC. The name of an soc
 990  node should start with "soc", and the remainder of the name should
 991  represent the part number for the soc.  For example, the MPC8540's
 992  soc node would be called "soc8540".
 993
 994  Required properties:
 995
 996    - device_type : Should be "soc"
 997    - ranges : Should be defined as specified in 1) to describe the
 998      translation of SOC addresses for memory mapped SOC registers.
 999    - bus-frequency: Contains the bus frequency for the SOC node.
1000      Typically, the value of this field is filled in by the boot
1001      loader.
1002
1003
1004  Recommended properties:
1005
1006    - reg : This property defines the address and size of the
1007      memory-mapped registers that are used for the SOC node itself.
1008      It does not include the child device registers - these will be
1009      defined inside each child node.  The address specified in the
1010      "reg" property should match the unit address of the SOC node.
1011    - #address-cells : Address representation for "soc" devices.  The
1012      format of this field may vary depending on whether or not the
1013      device registers are memory mapped.  For memory mapped
1014      registers, this field represents the number of cells needed to
1015      represent the address of the registers.  For SOCs that do not
1016      use MMIO, a special address format should be defined that
1017      contains enough cells to represent the required information.
1018      See 1) above for more details on defining #address-cells.
1019    - #size-cells : Size representation for "soc" devices
1020    - #interrupt-cells : Defines the width of cells used to represent
1021       interrupts.  Typically this value is <2>, which includes a
1022       32-bit number that represents the interrupt number, and a
1023       32-bit number that represents the interrupt sense and level.
1024       This field is only needed if the SOC contains an interrupt
1025       controller.
1026
1027  The SOC node may contain child nodes for each SOC device that the
1028  platform uses.  Nodes should not be created for devices which exist
1029  on the SOC but are not used by a particular platform. See chapter VI
1030  for more information on how to specify devices that are part of a SOC.
1031
1032  Example SOC node for the MPC8540:
1033
1034	soc8540@e0000000 {
1035		#address-cells = <1>;
1036		#size-cells = <1>;
1037		#interrupt-cells = <2>;
1038		device_type = "soc";
1039		ranges = <00000000 e0000000 00100000>
1040		reg = <e0000000 00003000>;
1041		bus-frequency = <0>;
1042	}
1043
1044
1045
1046IV - "dtc", the device tree compiler
1047====================================
1048
1049
1050dtc source code can be found at
1051<http://ozlabs.org/~dgibson/dtc/dtc.tar.gz>
1052
1053WARNING: This version is still in early development stage; the
1054resulting device-tree "blobs" have not yet been validated with the
1055kernel. The current generated bloc lacks a useful reserve map (it will
1056be fixed to generate an empty one, it's up to the bootloader to fill
1057it up) among others. The error handling needs work, bugs are lurking,
1058etc...
1059
1060dtc basically takes a device-tree in a given format and outputs a
1061device-tree in another format. The currently supported formats are:
1062
1063  Input formats:
1064  -------------
1065
1066     - "dtb": "blob" format, that is a flattened device-tree block
1067       with
1068        header all in a binary blob.
1069     - "dts": "source" format. This is a text file containing a
1070       "source" for a device-tree. The format is defined later in this
1071        chapter.
1072     - "fs" format. This is a representation equivalent to the
1073        output of /proc/device-tree, that is nodes are directories and
1074	properties are files
1075
1076 Output formats:
1077 ---------------
1078
1079     - "dtb": "blob" format
1080     - "dts": "source" format
1081     - "asm": assembly language file. This is a file that can be
1082       sourced by gas to generate a device-tree "blob". That file can
1083       then simply be added to your Makefile. Additionally, the
1084       assembly file exports some symbols that can be used.
1085
1086
1087The syntax of the dtc tool is
1088
1089    dtc [-I <input-format>] [-O <output-format>]
1090        [-o output-filename] [-V output_version] input_filename
1091
1092
1093The "output_version" defines what version of the "blob" format will be
1094generated. Supported versions are 1,2,3 and 16. The default is
1095currently version 3 but that may change in the future to version 16.
1096
1097Additionally, dtc performs various sanity checks on the tree, like the
1098uniqueness of linux, phandle properties, validity of strings, etc...
1099
1100The format of the .dts "source" file is "C" like, supports C and C++
1101style comments.
1102
1103/ {
1104}
1105
1106The above is the "device-tree" definition. It's the only statement
1107supported currently at the toplevel.
1108
1109/ {
1110  property1 = "string_value";	/* define a property containing a 0
1111                                 * terminated string
1112				 */
1113
1114  property2 = <1234abcd>;	/* define a property containing a
1115                                 * numerical 32-bit value (hexadecimal)
1116				 */
1117
1118  property3 = <12345678 12345678 deadbeef>;
1119                                /* define a property containing 3
1120                                 * numerical 32-bit values (cells) in
1121                                 * hexadecimal
1122				 */
1123  property4 = [0a 0b 0c 0d de ea ad be ef];
1124                                /* define a property whose content is
1125                                 * an arbitrary array of bytes
1126                                 */
1127
1128  childnode@addresss {	/* define a child node named "childnode"
1129                                 * whose unit name is "childnode at
1130				 * address"
1131                                 */
1132
1133    childprop = "hello\n";      /* define a property "childprop" of
1134                                 * childnode (in this case, a string)
1135                                 */
1136  };
1137};
1138
1139Nodes can contain other nodes etc... thus defining the hierarchical
1140structure of the tree.
1141
1142Strings support common escape sequences from C: "\n", "\t", "\r",
1143"\(octal value)", "\x(hex value)".
1144
1145It is also suggested that you pipe your source file through cpp (gcc
1146preprocessor) so you can use #include's, #define for constants, …

Large files files are truncated, but you can click here to view the full file