edtsdb API¶
edtsdb is a Python module with the primary class: EDTSDb
.
The basis for the edtsb module is the edtlib
library.
EDTSDb
¶
-
class
EDTSDb
¶ Extended DTS database.
Database schema:
_edts dict( 'aliases': dict(alias) : sorted list(device-id)), 'chosen': dict(chosen), 'devices': dict(device-id : device-struct), 'compatibles': dict(compatible : sorted list(device-id)), ... ) device-struct dict( 'device-id' : device-id, 'compatible' : list(compatible) or compatible, 'label' : label, '<property-name>' : property-value ) property-value for "boolean", "string", "int" -> string for 'array', "string-array", "uint8-array" -> dict(index : string) for "phandle-array" -> dict(index : device-id)
Database types:
device-id: opaque id for a device (do not use for other purposes),
compatible: any of [‘st,stm32-spi-fifo’, …] - ‘compatibe’ from <binding>.yaml
label: any of [‘UART_0’, ‘SPI_11’, …] - label directive from DTS
Subclassed by cogeno.modules.edtsdatabase.EDTSDatabase
The EDTSDb
class includes (sub-classes) several mixin classes:
-
class
EDTSConsumerMixin
¶ ETDS Database consumer.
Methods for ETDS database usage.
Subclassed by cogeno.modules.edtsdb.database.EDTSDb
Public Functions
-
info
(self self)¶ Get info.
- Return
edts ‘info’ dict
- Parameters
None
:
-
compatibles
(self self)¶ Get compatibles.
- Return
edts ‘compatibles’ dict
- Parameters
None
:
-
aliases
(self self)¶ Get aliases.
- Return
edts ‘aliases’ dict
- Parameters
None
:
-
chosen
(self self)¶ Get chosen.
- Return
edts ‘chosen’ dict
- Parameters
None
:
-
device_ids_by_compatible
(self self, compatibles compatibles)¶ Get device ids of all activated compatible devices.
- Return
list of device ids of activated devices that are compatible
- Parameters
compatibles
: compatible(s)
-
device_id_by_name
(self self, name name)¶ Get device id of activated device with given name.
- Return
device id
- Parameters
name
:
-
device_name_by_id
(self self, device_id device_id)¶ Get label/ name of a device by device id.
If the label is omitted, the name is taken from the node name (including unit address).
- Return
name
- Parameters
device_id
:
-
device_property
(self self, device_id device_id, property_path property_path, default default = "<unset>")¶ Get device tree property value of a device.
- Return
property value
- Parameters
device_id
:property_path
: Path of the property to access (e.g. ‘reg/0’, ‘interrupts/prio’, ‘device_id’, …)
-
device_properties
(self self, device_id device_id)¶
-
device_properties_flattened
(self self, device_id device_id, path_prefix path_prefix = "")¶ Device properties flattened to property path : value.
- Return
dictionary of property_path and property_value
- Parameters
device_id
:path_prefix
:
-
device_template_substitute
(self self, device_id device_id, template template, presets presets = {}, aliases aliases = {})¶ Substitude device property value placeholders in template.
Local placeholders may be defined with direct and indirect path resolution:
${<property_path>}
${path/${<property_path>}}
${path/${<device-id>:<property_path>}}
Global placeholders may also be defined with direct and indirect path resolution:
${<device-id>:<property_path>}
${${<property_path>}:<property_path>}
${${path/${<property_path>}}:<property_path>}
${${path/${<device-id>:<property_path>}}:<property_path>}
${${<device-id>:<property_path>}:<property_path>}
${${<device-id>:path/${<property_path>}}:<property_path>}
${${<device-id>:path/${<device-id>:<property_path>}}:<property_path>}
- Parameters
device_id
:template
:presets
: dict of preset property-path : property value items either of the local form “<property_path>” : value or the global form “<device-id>:<property_path>” : valuealiases
: dict of property path alias : property path items.
-
load
(self self, file_path file_path)¶ Load extended device tree database from JSON file.
- Parameters
file_path
: Path of JSON file
-
class
_DeviceGlobalTemplate
¶ Public Static Attributes
-
string cogeno.modules.edtsdb.consumer.EDTSConsumerMixin._DeviceGlobalTemplate.idpattern = r'/[_a-z0-9-/,@:]*'
-
-
class
_DeviceLocalTemplate
¶ Public Static Attributes
-
string cogeno.modules.edtsdb.consumer.EDTSConsumerMixin._DeviceLocalTemplate.idpattern = r'[_a-z][_a-z0-9-/,]*'
-
-
-
class
EDTSExtractorMixin
¶ ETDS Database extractor.
Methods for ETDS database extraction from DTS.
Subclassed by cogeno.modules.edtsdb.database.EDTSDb
Public Functions
-
extract
(self self, dts_path dts_path, bindings_dirs bindings_dirs)¶ Extract DTS info to database.
- Parameters
dts_path
: DTS filebindings_dirs
: YAML file directories, we allow multiple
-
dts_path
(self self)¶ Device tree file path.
- Return
Device tree file path
-
bindings_dirs
(self self)¶ Bindings directories paths.
- Return
List of binding directories
-
dts_source
(self self)¶ DTS source code.
DTS source code of the loaded devicetree after merging nodes and processing /delete-node/ and /delete-property/.
- Return
DTS source code as string
-
-
class
EDTSProviderMixin
¶ ETDS Database provider.
Methods for ETDS database creation.
Subclassed by cogeno.modules.edtsdb.database.EDTSDb
Public Functions
-
insert_alias
(self self, alias_path alias_path, alias_value alias_value)¶ Insert an alias.
- Parameters
alias_path
: Aliasalias_value
: The value the alias aliases.
-
insert_chosen
(self self, chosen_path chosen_path, chosen_value chosen_value)¶
-
insert_child_property
(self self, device_id device_id, child_name child_name, property_path property_path, property_value property_value)¶ Insert property value for the child of a device id.
- Parameters
device_id
:child_name
:property_path
: Path of the property to access (e.g. ‘reg/0’, ‘interrupts/prio’, ‘label’, …)property_value
: value
-
insert_device_property
(self self, device_id device_id, property_path property_path, property_value property_value)¶ Insert property value for the device of the given device id.
- Parameters
device_id
:property_path
: Path of the property to access (e.g. ‘reg/0’, ‘interrupts/prio’, ‘label’, …)property_value
: value
-
save
(self self, file_path file_path)¶ Write json file.
- Parameters
file_path
: Path of the file to write
-
edtlib
¶
-
class
EDT
¶ Represents a devicetree augmented with information from bindings. These attributes are available on EDT objects: nodes: A list of Node objects for the nodes that appear in the devicetree compat2enabled: A collections.defaultdict that maps each 'compatible' string that appears on some enabled Node to a list of enabled Nodes. For example, edt.compat2enabled["bar"] would include the 'foo' and 'bar' nodes below. foo { compatible = "bar"; status = "okay"; ... }; bar { compatible = "foo", "bar", "baz"; status = "okay"; ... }; dts_path: The .dts path passed to __init__() dts_source: The final DTS source code of the loaded devicetree after merging nodes and processing /delete-node/ and /delete-property/, as a string bindings_dirs: The bindings directory paths passed to __init__()
Public Functions
-
__init__
(self self, dts dts, bindings_dirs bindings_dirs, warn_file warn_file = None)¶ EDT constructor. This is the top-level entry point to the library. dts: Path to devicetree .dts file bindings_dirs: List of paths to directories containing bindings, in YAML format. These directories are recursively searched for .yaml files. warn_file: 'file' object to write warnings to. If None, sys.stderr is used.
-
get_node
(self self, path path)¶ Returns the Node at the DT path or alias 'path'. Raises EDTError if the path or alias doesn't exist.
-
chosen_node
(self self, name name)¶ Returns the Node pointed at by the property named 'name' in /chosen, or None if the property is missing
-
dts_source
(self self)¶
-
__repr__
(self self)¶
-
scc_order
(self self)¶ Returns a list of lists of Nodes where all elements of each list depend on each other, and the Nodes in any list do not depend on any Node in a subsequent list. Each list defines a Strongly Connected Component (SCC) of the graph. For an acyclic graph each list will be a singleton. Cycles will be represented by lists with multiple nodes. Cycles are not expected to be present in devicetree graphs.
-
-
class
Node
¶ Represents a devicetree node, augmented with information from bindings, and with some interpretation of devicetree properties. There's a one-to-one correspondence between devicetree nodes and Nodes. These attributes are available on Node objects: edt: The EDT instance this node is from name: The name of the node unit_addr: An integer with the ...@<unit-address> portion of the node name, translated through any 'ranges' properties on parent nodes, or None if the node name has no unit-address portion description: The description string from the binding for the node, or None if the node has no binding. Leading and trailing whitespace (including newlines) is removed. path: The devicetree path of the node label: The text from the 'label' property on the node, or None if the node has no 'label' labels: A list of all of the devicetree labels for the node, in the same order as the labels appear, but with duplicates removed. This corresponds to the actual devicetree source labels, unlike the "label" attribute, which is the value of a devicetree property named "label". parent: The Node instance for the devicetree parent of the Node, or None if the node is the root node children: A dictionary with the Node instances for the devicetree children of the node, indexed by name dep_ordinal: A non-negative integer value such that the value for a Node is less than the value for all Nodes that depend on it. The ordinal is defined for all Nodes including those that are not 'enabled', and is unique among nodes in its EDT 'nodes' list. required_by: A list with the nodes that directly depend on the node depends_on: A list with the nodes that the node directly depends on enabled: True unless the node has 'status = "disabled"' read_only: True if the node has a 'read-only' property, and False otherwise matching_compat: The 'compatible' string for the binding that matched the node, or None if the node has no binding binding_path: The path to the binding file for the node, or None if the node has no binding compats: A list of 'compatible' strings for the node, in the same order that they're listed in the .dts file regs: A list of Register objects for the node's registers props: A collections.OrderedDict that maps property names to Property objects. Property objects are created for all devicetree properties on the node that are mentioned in 'properties:' in the binding. aliases: A list of aliases for the node. This is fetched from the /aliases node. clocks: A list of ControllerAndData objects for the clock inputs on the node, sorted by index. The list is empty if the node does not have a clocks property. clock_outputs: A list of ControllerAndData objects for the clock outputs on the node, sorted by index. The list is empty if the node does not have a #clock-cells property. gpio_leds: A list of ControllerAndData objects of the leds a gpio leds controller controls. The list is empty if the node is not a gpio leds controller or it does not have and gpio led children. interrupts: A list of ControllerAndData objects for the interrupts generated by the node. The list is empty if the node does not generate interrupts. pinctrls: A list of PinCtrl objects for the pinctrl-<index> properties on the node, sorted by index. The list is empty if the node does not have any pinctrl-<index> properties. pinctrl_states: A list with the Node instances for the 'pinctrl-state' children of a pin controller node. The list is empty if the node does not have any pinctrl state children. pinctrl_gpio_ranges: A list of ControllerAndData objects of the gpio ranges a pin controller controls. The list is empty if the node is not a pin controller or no 'gpio-ranges' are defined by the gpio nodes. pincfgs: A list of PinCfg objects for the 'pinctrl-state' node. The list is empty if the node is not a 'pinctrl-state' node. pin_controller: The pin controller for the node. Only meaningful for nodes representing pinctrl states. bus: If the node is a bus node (has a 'bus:' key in its binding), then this attribute holds the bus type, e.g. "i2c" or "spi". If the node is not a bus node, then this attribute is None. on_bus: The bus the node appears on, e.g. "i2c" or "spi". The bus is determined by searching upwards for a parent node whose binding has a 'bus:' key, returning the value of the first 'bus:' key found. If none of the node's parents has a 'bus:' key, this attribute is None. bus_node: Like on_bus, but contains the Node for the bus controller, or None if the node is not on a bus. flash_controller: The flash controller for the node. Only meaningful for nodes representing flash partitions. partitions: A list of Partition objects of the partitions of the 'partitions' node of a flash. Only meaningful for nodes representing a flash - otherwise an empty list.
Public Functions
-
name
(self self)
-
unit_addr
(self self)¶
-
description
(self self)¶
-
path
(self self)¶
-
label
(self self)¶
-
labels
(self self)¶
-
parent
(self self)¶
-
children
(self self)¶
-
required_by
(self self)¶
-
depends_on
(self self)¶
-
enabled
(self self)¶
-
read_only
(self self)¶
-
aliases
(self self)¶
-
bus
(self self)¶
-
clocks
(self self)¶
-
on_bus
(self self)¶
-
flash_controller
(self self)¶
-
__repr__
(self self)¶
-
-
class
Register
¶ Represents a register on a node. These attributes are available on Register objects: node: The Node instance this register is from name: The name of the register as given in the 'reg-names' property, or None if there is no 'reg-names' property addr: The starting address of the register, in the parent address space. Any 'ranges' properties are taken into account. size: The length of the register in bytes
Public Functions
-
__repr__
(self self)¶
-
-
class
ControllerAndData
¶ Represents an entry in an 'interrupts' or 'type: phandle-array' property value, e.g. <&ctrl-1 4 0> in cs-gpios = <&ctrl-1 4 0 &ctrl-2 3 4>; These attributes are available on ControllerAndData objects: node: The Node instance the property appears on controller: The Node instance for the controller (e.g. the controller the interrupt gets sent to for interrupts) data: A dictionary that maps names from the *-cells key in the binding for the controller to data values, e.g. {"pin": 4, "flags": 0} for the example above. 'interrupts = <1 2>' might give {"irq": 1, "level": 2}. name: The name of the entry as given in 'interrupt-names'/'gpio-names'/'pwm-names'/etc., or None if there is no *-names property
Public Functions
-
__repr__
(self self)¶
-