📄 booting-without-of.txt
字号:
u32 off_mem_rsvmap; /* offset to memory reserve map */ u32 version; /* format version */ u32 last_comp_version; /* last compatible version */ /* version 2 fields below */ u32 boot_cpuid_phys; /* Which physical CPU id we're booting on */ /* version 3 fields below */ u32 size_dt_strings; /* size of the strings block */ /* version 17 fields below */ u32 size_dt_struct; /* size of the DT structure block */}; Along with the constants:/* Definitions used by the flattened device tree */#define OF_DT_HEADER 0xd00dfeed /* 4: version, 4: total size */#define OF_DT_BEGIN_NODE 0x1 /* Start node: full name */#define OF_DT_END_NODE 0x2 /* End node */#define OF_DT_PROP 0x3 /* Property: name off, size, content */#define OF_DT_END 0x9 All values in this header are in big endian format, the various fields in this header are defined more precisely below. All "offset" values are in bytes from the start of the header; that is from the value of r3. - magic This is a magic value that "marks" the beginning of the device-tree block header. It contains the value 0xd00dfeed and is defined by the constant OF_DT_HEADER - totalsize This is the total size of the DT block including the header. The "DT" block should enclose all data structures defined in this chapter (who are pointed to by offsets in this header). That is, the device-tree structure, strings, and the memory reserve map. - off_dt_struct This is an offset from the beginning of the header to the start of the "structure" part the device tree. (see 2) device tree) - off_dt_strings This is an offset from the beginning of the header to the start of the "strings" part of the device-tree - off_mem_rsvmap This is an offset from the beginning of the header to the start of the reserved memory map. This map is a list of pairs of 64- bit integers. Each pair is a physical address and a size. The list is terminated by an entry of size 0. This map provides the kernel with a list of physical memory areas that are "reserved" and thus not to be used for memory allocations, especially during early initialization. The kernel needs to allocate memory during boot for things like un-flattening the device-tree, allocating an MMU hash table, etc... Those allocations must be done in such a way to avoid overriding critical things like, on Open Firmware capable machines, the RTAS instance, or on some pSeries, the TCE tables used for the iommu. Typically, the reserve map should contain _at least_ this DT block itself (header,total_size). If you are passing an initrd to the kernel, you should reserve it as well. You do not need to reserve the kernel image itself. The map should be 64-bit aligned. - version This is the version of this structure. Version 1 stops here. Version 2 adds an additional field boot_cpuid_phys. Version 3 adds the size of the strings block, allowing the kernel to reallocate it easily at boot and free up the unused flattened structure after expansion. Version 16 introduces a new more "compact" format for the tree itself that is however not backward compatible. Version 17 adds an additional field, size_dt_struct, allowing it to be reallocated or moved more easily (this is particularly useful for bootloaders which need to make adjustments to a device tree based on probed information). You should always generate a structure of the highest version defined at the time of your implementation. Currently that is version 17, unless you explicitly aim at being backward compatible. - last_comp_version Last compatible version. This indicates down to what version of the DT block you are backward compatible. For example, version 2 is backward compatible with version 1 (that is, a kernel build for version 1 will be able to boot with a version 2 format). You should put a 1 in this field if you generate a device tree of version 1 to 3, or 16 if you generate a tree of version 16 or 17 using the new unit name format. - boot_cpuid_phys This field only exist on version 2 headers. It indicate which physical CPU ID is calling the kernel entry point. This is used, among others, by kexec. If you are on an SMP system, this value should match the content of the "reg" property of the CPU node in the device-tree corresponding to the CPU calling the kernel entry point (see further chapters for more informations on the required device-tree contents) - size_dt_strings This field only exists on version 3 and later headers. It gives the size of the "strings" section of the device tree (which starts at the offset given by off_dt_strings). - size_dt_struct This field only exists on version 17 and later headers. It gives the size of the "structure" section of the device tree (which starts at the offset given by off_dt_struct). So the typical layout of a DT block (though the various parts don't need to be in that order) looks like this (addresses go from top to bottom): ------------------------------ r3 -> | struct boot_param_header | ------------------------------ | (alignment gap) (*) | ------------------------------ | memory reserve map | ------------------------------ | (alignment gap) | ------------------------------ | | | device-tree structure | | | ------------------------------ | (alignment gap) | ------------------------------ | | | device-tree strings | | | -----> ------------------------------ | | --- (r3 + totalsize) (*) The alignment gaps are not necessarily present; their presence and size are dependent on the various alignment requirements of the individual data blocks.2) Device tree generalities---------------------------This device-tree itself is separated in two different blocks, astructure block and a strings block. Both need to be aligned to a 4byte boundary.First, let's quickly describe the device-tree concept before detailingthe storage format. This chapter does _not_ describe the detail of therequired types of nodes & properties for the kernel, this is donelater in chapter III.The device-tree layout is strongly inherited from the definition ofthe Open Firmware IEEE 1275 device-tree. It's basically a tree ofnodes, each node having two or more named properties. A property canhave a value or not.It is a tree, so each node has one and only one parent except for theroot node who has no parent.A node has 2 names. The actual node name is generally contained in aproperty of type "name" in the node property list whose value is azero terminated string and is mandatory for version 1 to 3 of theformat definition (as it is in Open Firmware). Version 16 makes itoptional as it can generate it from the unit name defined below.There is also a "unit name" that is used to differentiate nodes withthe same name at the same level, it is usually made of the nodenames, the "@" sign, and a "unit address", which definition isspecific to the bus type the node sits on.The unit name doesn't exist as a property per-se but is included inthe device-tree structure. It is typically used to represent "path" inthe device-tree. More details about the actual format of these will bebelow.The kernel powerpc generic code does not make any formal use of theunit address (though some board support code may do) so the only realrequirement here for the unit address is to ensure uniqueness ofthe node unit name at a given level of the tree. Nodes with no notionof address and no possible sibling of the same name (like /memory or/cpus) may omit the unit address in the context of this specification,or use the "@0" default unit address. The unit name is used to definea node "full path", which is the concatenation of all parent nodeunit names separated with "/".The root node doesn't have a defined name, and isn't required to havea name property either if you are using version 3 or earlier of theformat. It also has no unit address (no @ symbol followed by a unitaddress). The root node unit name is thus an empty string. The fullpath to the root node is "/".Every node which actually represents an actual device (that is, a nodewhich isn't only a virtual "container" for more nodes, like "/cpus"is) is also required to have a "device_type" property indicating thetype of node .Finally, every node that can be referenced from a property in anothernode is required to have a "linux,phandle" property. Real openfirmware implementations provide a unique "phandle" value for everynode that the "prom_init()" trampoline code turns into"linux,phandle" properties. However, this is made optional if theflattened device tree is used directly. An example of a nodereferencing another node via "phandle" is when laying out theinterrupt tree which will be described in a further version of thisdocument.This "linux, phandle" property is a 32-bit value that uniquelyidentifies a node. You are free to use whatever values or system ofvalues, internal pointers, or whatever to generate these, the onlyrequirement is that every node for which you provide that property hasa unique value for it.Here is an example of a simple device-tree. In this example, an "o"designates a node followed by the node unit name. Properties arepresented with their name followed by their content. "content"represents an ASCII string (zero terminated) value, while <content>represents a 32-bit hexadecimal value. The various nodes in thisexample will be discussed in a later chapter. At this point, it isonly meant to give you a idea of what a device-tree looks like. I havepurposefully kept the "name" and "linux,phandle" properties whicharen't necessary in order to give you a better idea of what the treelooks like in practice. / o device-tree |- name = "device-tree" |- model = "MyBoardName" |- compatible = "MyBoardFamilyName" |- #address-cells = <2> |- #size-cells = <2> |- linux,phandle = <0> | o cpus | | - name = "cpus" | | - linux,phandle = <1> | | - #address-cells = <1> | | - #size-cells = <0> | | | o PowerPC,970@0 | |- name = "PowerPC,970" | |- device_type = "cpu" | |- reg = <0> | |- clock-frequency = <5f5e1000> | |- 64-bit | |- linux,phandle = <2> | o memory@0 | |- name = "memory" | |- device_type = "memory" | |- reg = <00000000 00000000 00000000 20000000> | |- linux,phandle = <3> | o chosen |- name = "chosen" |- bootargs = "root=/dev/sda2" |- linux,phandle = <4>This tree is almost a minimal tree. It pretty much contains theminimal set of required nodes and properties to boot a linux kernel;that is, some basic model informations at the root, the CPUs, and thephysical memory layout. It also includes misc information passedthrough /chosen, like in this example, the platform type (mandatory)and the kernel command line arguments (optional).The /cpus/PowerPC,970@0/64-bit property is an example of aproperty without a value. All other properties have a value. Thesignificance of the #address-cells and #size-cells properties will beexplained in chapter IV which defines precisely the required nodes andproperties and their content.3) Device tree "structure" blockThe structure of the device tree is a linearized tree structure. The"OF_DT_BEGIN_NODE" token starts a new node, and the "OF_DT_END_NODE"ends that node definition. Child nodes are simply defined before"OF_DT_END_NODE" (that is nodes within the node). A 'token' is a 32bit value. The tree has to be "finished" with a OF_DT_END tokenHere's the basic structure of a single node: * token OF_DT_BEGIN_NODE (that is 0x00000001) * for version 1 to 3, this is the node full path as a zero terminated string, starting with "/". For version 16 and later, this is the node unit name only (or an empty string for the root node) * [align gap to next 4 bytes boundary] * for each property: * token OF_DT_PROP (that is 0x00000003) * 32-bit value of property value size in bytes (or 0 if no value) * 32-bit value of offset in string block of property name * property value data if any * [align gap to next 4 bytes boundary] * [child nodes if any] * token OF_DT_END_NODE (that is 0x00000002)So the node content can be summarized as a start token, a full path,a list of properties, a list of child nodes, and an end token. Every
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -