Documentation ¶
Overview ¶
Package dt contains utilities for device tree.
Package dt contains utilities for device tree reading on Linux.
Index ¶
- Constants
- Variables
- type Empty
- type FDT
- type FDTReader
- type Header
- type Node
- func (n *Node) Find(f func(*Node) bool) (*Node, bool)
- func (n *Node) FindAll(f func(*Node) bool) ([]*Node, bool)
- func (n *Node) LookProperty(name string) (*Property, bool)
- func (n *Node) NodeByName(name string) (*Node, bool)
- func (n *Node) RemoveProperty(name string) bool
- func (n *Node) String() string
- func (n *Node) UpdateProperty(name string, value []byte) bool
- func (n *Node) Walk(f func(*Node) error) error
- type NodeWalk
- func (nq *NodeWalk) AsString() (string, error)
- func (nq *NodeWalk) Find(f func(*Node) bool) (*Node, error)
- func (nq *NodeWalk) FindAll(f func(*Node) bool) ([]*Node, error)
- func (nq *NodeWalk) ListChildNodes() ([]string, error)
- func (nq *NodeWalk) Property(name string) *PropertyWalk
- func (nq *NodeWalk) Walk(name string) *NodeWalk
- 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) AsRegion() (*Region, 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
- func (p *Property) String() string
- type PropertyType
- type PropertyWalk
- type Region
- 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 ErrNoValidReaders = errors.New("No FDT readers succeeded")
ErrNoValidReaders indicates that no readers succeeded.
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.
func LoadFDT ¶
LoadFDT loads a flattened device tree from current running system.
It first tries to load it from given io.ReaderAt, then from that passed-in file name. If there are not passed-in file names, it will try sysfsFDT.
BUGS: It is a bit clunky due to its origins; in the original version it even had a race. hopefully we can deprecate it in a future u-root release.
func New ¶
New returns a new FDT, trying each FDTReader in turn until it succeeds or all have failed. It will return the last error. TODO: once we move to go 1.20, use the new error tree support.
func ReadFDT ¶
func ReadFDT(f io.ReadSeeker) (*FDT, error)
ReadFDT reads an FDT from an io.ReadSeeker.
func (*FDT) NodeByName ¶
NodeByName finds a node by name.
type FDTReader ¶
FDTReader is a function type with no args that returns a *FDT or an error.
func WithFileName ¶
WithFileName constructs an FDTReader with the provided file name.
func WithReaderAt ¶
WithReaderAt constructs an FDTReader with the provided io.ReaderAt.
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.
func (*Node) LookProperty ¶
LookProperty finds a property by name.
func (*Node) NodeByName ¶
NodeByName uses Find to find a node by name.
func (*Node) RemoveProperty ¶
RemoveProperty deletes a property by name.
func (*Node) UpdateProperty ¶
UpdateProperty updates a property in the node, adding it if it does not exist.
Returning boolean to indicate if the property was found.
type NodeWalk ¶
type NodeWalk struct {
// contains filtered or unexported fields
}
NodeWalk is used to contain state for walking the FDT, such as an error. A Walk with a non-nil error value can not proceed. Many walks will start with a root, but it is possible to Walk to a node, make a copy of the Walk, and in that way do multiple Walks from that one node. This is very similar to how 9p clients walk 9p servers.
func (*NodeWalk) Find ¶
Find returns a Node given a matching function starting at the current NodeWalk.
func (*NodeWalk) FindAll ¶
FindAll returns all Nodes given a matching function starting at the current NodeWalk.
func (*NodeWalk) ListChildNodes ¶
ListChildNodes returns a string array with the Names of each child Node
func (*NodeWalk) Property ¶
func (nq *NodeWalk) Property(name string) *PropertyWalk
Property walks from a Node to a Property of that Node, returning a PropertyWalk.
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 PropertyWalk ¶
type PropertyWalk struct {
// contains filtered or unexported fields
}
PropertyWalk contains the state from a Walk to a Property.
func (*PropertyWalk) AsBytes ¶
func (pq *PropertyWalk) AsBytes() ([]byte, error)
AsBytes returns the PropertyWalk value as a []byte.
func (*PropertyWalk) AsString ¶
func (pq *PropertyWalk) AsString() (string, error)
AsString returns the PropertyWalk value as a string.
func (*PropertyWalk) AsU64 ¶
func (pq *PropertyWalk) AsU64() (uint64, error)
AsU64 returns the PropertyWalk value as a uint64.
type ReserveEntry ¶
ReserveEntry defines a memory region which is reserved.