dt

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2020 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package dt contains utilities for device tree.

Index

Constants

View Source
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

View Source
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 Empty

type Empty struct{}

Empty represents an empty Device Tree value.

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 ReadFDT

func ReadFDT(f io.ReadSeeker) (*FDT, error)

ReadFDT reads FDT from an io.ReadSeeker.

func (*FDT) PrintDTS

func (fdt *FDT) PrintDTS(f io.Writer) error

PrintDTS prints the FDT in the .dts format. TODO: not yet implemented

func (*FDT) Write

func (fdt *FDT) Write(f io.Writer) (int, error)

Write marshals the FDT to an io.Writer and returns the size.

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) Walk

func (n *Node) Walk(f func(*Node) error) error

Walk calls f on a Node and alls its descendents.

type PHandle

type PHandle uint32

PHandle represents a pointer to another Node.

type Property

type Property struct {
	Name  string
	Value []byte
}

Property is a name-value pair. Note the PropertyType of Value is not encoded.

func (*Property) AsEmpty

func (p *Property) AsEmpty() (Empty, error)

AsEmpty converts the property to the Go fdt.Empty type.

func (*Property) AsPHandle

func (p *Property) AsPHandle() (PHandle, error)

AsPHandle converts the property to the Go fdt.PHandle type.

func (*Property) AsPropEncodedArray

func (p *Property) AsPropEncodedArray() ([]byte, error)

AsPropEncodedArray converts the property to the Go []byte type.

func (*Property) AsString

func (p *Property) AsString() (string, error)

AsString converts the property to the Go string type. The trailing null character is stripped.

func (*Property) AsStringList

func (p *Property) AsStringList() ([]string, error)

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) AsU32

func (p *Property) AsU32() (uint32, error)

AsU32 converts the property to the Go uint32 type.

func (*Property) AsU64

func (p *Property) AsU64() (uint64, error)

AsU64 converts the property to the Go uint64 type.

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

type ReserveEntry struct {
	Address uint64
	Size    uint64
}

ReserveEntry defines a memory region which is reserved.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL