Documentation ¶
Overview ¶
Package dt contains utilities for device tree.
Index ¶
- Constants
- Variables
- type Empty
- type FDT
- type Header
- type Node
- type PHandle
- type Property
- func (p *Property) AsEmpty() (Empty, error)
- func (p *Property) AsPHandle() (PHandle, error)
- func (p *Property) AsPropEncodedArray() ([]byte, error)
- func (p *Property) AsString() (string, error)
- func (p *Property) AsStringList() ([]string, error)
- func (p *Property) AsType(val PropertyType) (interface{}, error)
- func (p *Property) AsU32() (uint32, error)
- func (p *Property) AsU64() (uint64, error)
- func (p *Property) PredictType() PropertyType
- type PropertyType
- type ReserveEntry
Constants ¶
const ( // Magic value seen in the FDT Header. Magic uint32 = 0xd00dfeed // MaxTotalSize is a limitation imposed by this implementation. This // prevents the integers from wrapping around. Typically, the total size is // a few megabytes, so this is not restrictive. MaxTotalSize = 1024 * 1024 * 1024 )
Variables ¶
var StandardPropertyTypes = map[string]PropertyType{ "compatible": StringListType, "model": StringType, "phandle": PHandleType, "status": StringType, "#address-cells": U32Type, "#size-cells": U32Type, "reg": PropEncodedArrayType, "virtual-reg": U32Type, "ranges": PropEncodedArrayType, "dma-ranges": PropEncodedArrayType, "name": StringType, "device_tree": StringType, }
StandardPropertyTypes maps properties to values as defined by the spec.
Functions ¶
This section is empty.
Types ¶
type FDT ¶
type FDT struct { Header Header ReserveEntries []ReserveEntry RootNode *Node }
FDT contains the parsed contents of a Flattend Device Tree (.dtb).
The format is relatively simple and defined in chapter 5 of the Devicetree Specification Release 0.2.
See: https://github.com/devicetree-org/devicetree-specification/releases/tag/v0.2
This package is compatible with version 16 and 17 of DTSpec.
type Header ¶
type Header struct { Magic uint32 TotalSize uint32 OffDtStruct uint32 OffDtStrings uint32 OffMemRsvmap uint32 Version uint32 LastCompVersion uint32 BootCpuidPhys uint32 SizeDtStrings uint32 SizeDtStruct uint32 }
Header appears at offset 0.
type Node ¶
type Node struct { Name string Properties []Property `json:",omitempty"` Children []*Node `json:",omitempty"` }
Node is one Node in the Device Tree.
type Property ¶
Property is a name-value pair. Note the PropertyType of Value is not encoded.
func (*Property) AsPropEncodedArray ¶
AsPropEncodedArray converts the property to the Go []byte type.
func (*Property) AsString ¶
AsString converts the property to the Go string type. The trailing null character is stripped.
func (*Property) AsStringList ¶
AsStringList converts the property to the Go []string type. The trailing null character of each string is stripped.
func (*Property) AsType ¶
func (p *Property) AsType(val PropertyType) (interface{}, error)
AsType converts a Property to a Go type using one of the AsXYX() functions. The resulting Go type is as follows:
AsType(fdt.EmptyType) -> fdt.Empty AsType(fdt.U32Type) -> uint32 AsType(fdt.U64Type) -> uint64 AsType(fdt.StringType) -> string AsType(fdt.PropEncodedArrayType) -> []byte AsType(fdt.PHandleType) -> fdt.PHandle AsType(fdt.StringListType) -> []string
func (*Property) PredictType ¶
func (p *Property) PredictType() PropertyType
PredictType makes a prediction on what value the property contains based on its name and data. The data types are not encoded in the data structure, so some heuristics are used.
type PropertyType ¶
type PropertyType int
PropertyType is an enum of possible property types.
const ( EmptyType PropertyType = iota U32Type U64Type StringType PropEncodedArrayType PHandleType StringListType )
These are the possible values for PropertyType.
type ReserveEntry ¶
ReserveEntry defines a memory region which is reserved.