Unit DeviceTree
Return to Unit Reference
Description
Ultibo Flattened Device Tree (DTB) interface unit
Using Device Tree Blob (DTB) files for passing configuration information to the Linux kernel is now widely accepted as the standard method of providing platform specific information without it needing to be hard coded into the kernel at build time.
With this adoption of device tree by Linux it is becoming increasingly common for the only source of information about the runtime configuration of specific hardware to be found in the blob loaded and configured during startup by the firmware and passed to the kernel at the beginning of the boot process.
While Ultibo targets a much smaller range of devices than Linux and does not need the generic kernel model it still requires detailed configuration information in order to be able to interface with the full range of available devices.
It can also benefit from the ability to adapt to the runtime environment by checking for known device tree parameters while registering and initializing hardware and devices. Use of device tree is considered optional and Ultibo will operate correctly with or without the information provided, however some devices may be forced to operate in a fall back or default mode without the complete configuration.
Constants
To be documented
Type definitions
To be documented
Public variables
To be documented
Function declarations
Initialization functions
procedure DeviceTreeInit;
Note | Called only during system startup |
---|
Device tree functions
function DeviceTreeValidate(Address:PtrUInt; var Size:LongWord):Boolean;
Address | The address to be validated |
---|---|
Size | On return contains the total size of the Device Tree Blob if valid |
Return | True if the address points to a valid Device Tree Blob, False if not. |
Note | Does not overwrite passed Size unless the DTB is valid |
function DeviceTreeNextNode(Parent,Previous:THandle):THandle;
Parent | Handle of the parent node to search in, INVALID_HANDLE_VALUE to search the entire tree |
---|---|
Previous | Handle of the node to start from, INVALID_HANDLE_VALUE to start from the root node |
Return | The handle of the next node in the tree or INVALID_HANDLE_VALUE if no node was found |
function DeviceTreeNextProperty(Node,Previous:THandle):THandle;
Node | Handle of the node to search in |
---|---|
Previous | Handle of the property to start from, INVALID_HANDLE_VALUE to start from the first property |
Return | The handle of the next property in the node or INVALID_HANDLE_VALUE if no property was found |
function DeviceTreeGetNode(const Path:String; Parent:THandle):THandle;
Path | The path of the node to find, relative to parent node or fully qualified if parent not specified (eg /chosen or /cpus/cpu0). |
---|---|
Parent | Handle of the parent node to search in, INVALID_HANDLE_VALUE to search the entire tree. |
Return | The handle of the node which matches the path or INVALID_HANDLE_VALUE if no node was found |
function DeviceTreeGetProperty(Node:THandle; const Name:String):THandle;
Node | Handle of the node to search in |
---|---|
Name | The name of the node to find (eg compatible) |
Return | The handle of the property which matches the name or INVALID_HANDLE_VALUE if no property was found |
function DeviceTreeGetNodeName(Handle:THandle):String;
Handle | The handle of the node to get the name of |
---|---|
Return | The name of the specified node or an empty string if the node was not valid |
procedure DeviceTreeSplitNodeName(Handle:THandle; var NodeName,UnitAddress:String);
Handle | The handle of the node to split the name of |
---|---|
NodeName | The node name on return or an empty string if the node was not valid |
UnitAddress | The unit address on return (If applicable) |
function DeviceTreeGetNodeParent(Handle:THandle):THandle;
Handle | The handle of the node to get the parent of |
---|---|
Return | The handle of the parent node or INVALID_HANDLE_VALUE if the node was not valid |
function DeviceTreeGetNodeRegCells(Handle:THandle; var Address,Size:LongWord):Boolean;
Handle | The handle of the node to get the cell sizes for |
---|---|
Address | The #address-cells value on return (or the default value if not found) |
Size | The #size-cells value on return (or the default value if not found) |
Return | True if the cell sizes were found or False if the node was not valid |
Note | The address and size values applicable to a given node will be those from a parent node, not those found in the node itself (if present).
Used by early stage boot stage processing which must limit the use of strings and other memory allocations. This function uses a memory compare for names. |
function DeviceTreeGetNodeRangeCells(Handle:THandle; var ParentAddress,NodeAddress,NodeSize:LongWord):Boolean;
Handle | The handle of the node to get the cell sizes for |
---|---|
ParentAddress | The #address-cells value from the parent on return (or the default value if not found) |
NodeAddress | The #address-cells value from this node on return (or the default value if not found) |
NodeSize | The #size-cells value from this node on return (or the default value if not found) |
Return | True if the cell sizes were found or False if the node was not valid |
Note | Range properties use the address value from the parent node and the address and size values from the node itself to determine the size of each range.
Used by early stage boot stage processing which must limit the use of strings and other memory allocations. This function uses a memory compare for names. |
function DeviceTreeGetPropertyName(Handle:THandle):String;
Handle | The handle of the property to get the name of |
---|---|
Return | The name of the specified property or an empty string if the property was not valid |
procedure DeviceTreeSplitPropertyName(Handle:THandle; var UniquePrefix,PropertyName:String);
Handle | The handle of the property to split the name of |
---|---|
UniquePrefix | The unique prefix on return (If applicable) |
PropertyName | The property name on return or an empty string if the property was not valid |
function DeviceTreeGetPropertyValue(Handle:THandle):Pointer;
Handle | The handle of the property to get the value of |
---|---|
Return | A pointer to the specified property value or nil if the property was not valid |
Note | The returned value points to the memory block where device tree is stored and should not be modified or freed |
function DeviceTreeGetPropertyLength(Handle:THandle):LongWord;
Handle | The handle of the property to get the value lenth of |
---|---|
Return | The length of the specified property value in bytes or -1 if the property was not valid |
function DeviceTreeGetPropertyString(Handle:THandle):String;
Handle | The handle of the property to get the value of |
---|---|
Return | A string representation of the value or an empty string if the property was not valid |
function DeviceTreeGetPropertyLongWord(Handle:THandle):LongWord;
Handle | The handle of the property to get the value of |
---|---|
Return | A longword representation of the value or 0 if the property was not valid |
function DeviceTreeGetPropertyQuadWord(Handle:THandle):UInt64;
Handle | The handle of the property to get the value of |
---|---|
Return | A quadword representation of the value or 0 if the property was not valid |
RTL Device tree functions
function SysDeviceTreeRead(const Path,Name:String; Buffer:Pointer; var Size:LongWord):LongWord;
Note | Not intended to be called directly by applications, use DeviceTreeRead instead. |
---|
function SysDeviceTreeRead32(const Path,Name:String; var Value:LongWord):LongWord;
Note | Not intended to be called directly by applications, use DeviceTreeRead32 instead. |
---|
function SysDeviceTreeRead64(const Path,Name:String; var Value:UInt64):LongWord;
Note | Not intended to be called directly by applications, use DeviceTreeRead64 instead. |
---|
function SysDeviceTreeReadString(const Path,Name:String; var Value:String):LongWord;
Note | Not intended to be called directly by applications, use DeviceTreeReadString instead. |
---|
Device tree helper functions
function DeviceTreeGetBootArgs:PChar;
Note | Intended primarily for use by early boot stage processing which must limit the use of strings and other memory allocations
For normal use see DeviceTreeGetNode and DeviceTreeGetProperty |
---|
function DeviceTreeGetRamdisk(var Address:PtrUInt; var Size:UInt64):Boolean;
Address | Used to return the address value |
---|---|
Size | Used to return the size value |
Return | True if an initial ram disk was specified in the device tree, False if not. |
Note | Intended primarily for use by early boot stage processing which must limit the use of strings and other memory allocations
For normal use see DeviceTreeGetNode and DeviceTreeGetProperty |
function DeviceTreeGetMemory(Index:LongWord; var Range:LongWord; var Address:PtrUInt; var Size:UInt64):Boolean;
Index | The index of the memory block to return (The first block is 0) |
---|---|
Range | Used to return the page range value (If applicable) |
Address | Used to return the address value |
Size | Used to return the size value |
Return | True if the memory block requested was found in the device tree, False if not. |
Note | Intended primarily for use by early boot stage processing which must limit the use of strings and other memory allocations
For normal use see DeviceTreeGetNode and DeviceTreeGetProperty |
function DeviceTreeGetReservation(Index:LongWord; var Address:PtrUInt; var Size:UInt64):Boolean;
Index | The index of the memory reservation to return (The first reservation is 0) |
---|---|
Address | Used to return the address value |
Size | Used to return the size value |
Return | True if the memory reservation requested was found in the device tree, False if not. |
function DeviceTreeLogTree:LongWord;
Return | ERROR_SUCCESS if completed or another error code on failure |
---|
function DeviceTreeLogTreeEx(Node:THandle; Output:TDTBLogOutput; Decode:TDTBDecodeValue; Data:Pointer):LongWord;
Node | The node to print information about (INVALID_HANDLE_VALUE for all nodes) |
---|---|
Output | The log output callback to print information to (nil to use the default output) |
Decode | The callback to decode a value into a string (nil to use the default decode) |
Data | A pointer to call specific data which should be passed to the callbacks (Optional) |
Return | ERROR_SUCCESS if completed or another error code on failure |
Return to Unit Reference