1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-09-30 15:01:27 +02:00

dtoc: Assign a sequence number to each node

Now that we have the alias information we can assign a sequence number
to each device in the uclass. Store this in the node associated with each
device.

This requires renaming the sandbox test drivers to have the right name.
Note that test coverage is broken with this patch, but fixed in the next
one.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2021-02-03 06:01:09 -07:00
parent 1712f8b2b7
commit 074197aadf
4 changed files with 53 additions and 20 deletions

View File

@@ -86,7 +86,7 @@ static const struct udevice_id testbus_ids[] = {
{ } { }
}; };
U_BOOT_DRIVER(testbus_drv) = { U_BOOT_DRIVER(denx_u_boot_test_bus) = {
.name = "testbus_drv", .name = "testbus_drv",
.of_match = testbus_ids, .of_match = testbus_ids,
.id = UCLASS_TEST_BUS, .id = UCLASS_TEST_BUS,
@@ -160,7 +160,9 @@ static const struct udevice_id testfdt_ids[] = {
{ } { }
}; };
U_BOOT_DRIVER(testfdt_drv) = { DM_DRIVER_ALIAS(denx_u_boot_fdt_test, google_another_fdt_test)
U_BOOT_DRIVER(denx_u_boot_fdt_test) = {
.name = "testfdt_drv", .name = "testfdt_drv",
.of_match = testfdt_ids, .of_match = testfdt_ids,
.id = UCLASS_TEST_FDT, .id = UCLASS_TEST_FDT,

View File

@@ -330,7 +330,7 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
/* Check creating a device with an alias */ /* Check creating a device with an alias */
node = ofnode_path("/some-bus/c-test@1"); node = ofnode_path("/some-bus/c-test@1");
ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv), ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test),
"c-test@1", NULL, node, &dev)); "c-test@1", NULL, node, &dev));
ut_asserteq(12, dev_seq(dev)); ut_asserteq(12, dev_seq(dev));
ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 12, &dev)); ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 12, &dev));
@@ -350,11 +350,11 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
* *
* So next available is 19 * So next available is 19
*/ */
ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv), ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test),
"fred", NULL, ofnode_null(), &dev)); "fred", NULL, ofnode_null(), &dev));
ut_asserteq(19, dev_seq(dev)); ut_asserteq(19, dev_seq(dev));
ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv), ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(denx_u_boot_fdt_test),
"fred2", NULL, ofnode_null(), &dev)); "fred2", NULL, ofnode_null(), &dev));
ut_asserteq(20, dev_seq(dev)); ut_asserteq(20, dev_seq(dev));

View File

@@ -136,8 +136,10 @@ class DtbPlatdata():
from the U-Boot source code from the U-Boot source code
_fdt: Fdt object, referencing the device tree _fdt: Fdt object, referencing the device tree
_dtb_fname: Filename of the input device tree binary file _dtb_fname: Filename of the input device tree binary file
_valid_nodes: A list of Node object with compatible strings. The list _valid_nodes_unsorted: A list of Node object with compatible strings,
is ordered by conv_name_to_c(node.name) ordered by devicetree node order
_valid_nodes: A list of Node object with compatible strings, ordered by
conv_name_to_c(node.name)
_include_disabled: true to include nodes marked status = "disabled" _include_disabled: true to include nodes marked status = "disabled"
_outfile: The current output file (sys.stdout or a real file) _outfile: The current output file (sys.stdout or a real file)
_lines: Stashed list of output lines for outputting in the future _lines: Stashed list of output lines for outputting in the future
@@ -155,6 +157,7 @@ class DtbPlatdata():
self._fdt = None self._fdt = None
self._dtb_fname = dtb_fname self._dtb_fname = dtb_fname
self._valid_nodes = None self._valid_nodes = None
self._valid_nodes_unsorted = None
self._include_disabled = include_disabled self._include_disabled = include_disabled
self._outfile = None self._outfile = None
self._lines = [] self._lines = []
@@ -324,34 +327,38 @@ class DtbPlatdata():
""" """
self._fdt = fdt.FdtScan(self._dtb_fname) self._fdt = fdt.FdtScan(self._dtb_fname)
def scan_node(self, root, valid_nodes): def scan_node(self, node, valid_nodes):
"""Scan a node and subnodes to build a tree of node and phandle info """Scan a node and subnodes to build a tree of node and phandle info
This adds each node to self._valid_nodes. This adds each subnode to self._valid_nodes if it is enabled and has a
compatible string.
Args: Args:
root (Node): Root node for scan node (Node): Node for scan for subnodes
valid_nodes (list of Node): List of Node objects to add to valid_nodes (list of Node): List of Node objects to add to
""" """
for node in root.subnodes: for subnode in node.subnodes:
if 'compatible' in node.props: if 'compatible' in subnode.props:
status = node.props.get('status') status = subnode.props.get('status')
if (not self._include_disabled and not status or if (not self._include_disabled and not status or
status.value != 'disabled'): status.value != 'disabled'):
valid_nodes.append(node) valid_nodes.append(subnode)
# recurse to handle any subnodes # recurse to handle any subnodes
self.scan_node(node, valid_nodes) self.scan_node(subnode, valid_nodes)
def scan_tree(self): def scan_tree(self):
"""Scan the device tree for useful information """Scan the device tree for useful information
This fills in the following properties: This fills in the following properties:
_valid_nodes: A list of nodes we wish to consider include in the _valid_nodes_unsorted: A list of nodes we wish to consider include
platform data in the platform data (in devicetree node order)
_valid_nodes: Sorted version of _valid_nodes_unsorted
""" """
root = self._fdt.GetRoot()
valid_nodes = [] valid_nodes = []
self.scan_node(self._fdt.GetRoot(), valid_nodes) self.scan_node(root, valid_nodes)
self._valid_nodes_unsorted = valid_nodes
self._valid_nodes = sorted(valid_nodes, self._valid_nodes = sorted(valid_nodes,
key=lambda x: conv_name_to_c(x.name)) key=lambda x: conv_name_to_c(x.name))
@@ -670,6 +677,24 @@ class DtbPlatdata():
elif result is False: elif result is False:
print("Could not find uclass for alias '%s'" % prop.name) print("Could not find uclass for alias '%s'" % prop.name)
def assign_seq(self):
"""Assign a sequence number to each node"""
for node in self._valid_nodes_unsorted:
if node.driver and node.seq == -1 and node.uclass:
uclass = node.uclass
num = uclass.alias_path_to_num.get(node.path)
if num is not None:
node.seq = num
else:
# Dynamically allocate the next available value after all
# existing ones
for seq in range(1000):
if seq not in uclass.alias_num_to_node:
break
node.seq = seq
uclass.alias_path_to_num[node.path] = seq
uclass.alias_num_to_node[seq] = node
def process_nodes(self, need_drivers): def process_nodes(self, need_drivers):
nodes_to_output = list(self._valid_nodes) nodes_to_output = list(self._valid_nodes)
@@ -806,9 +831,9 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
plat.setup_output_dirs(output_dirs) plat.setup_output_dirs(output_dirs)
plat.scan_structs() plat.scan_structs()
plat.scan_phandles() plat.scan_phandles()
if do_process: plat.process_nodes(False)
plat.process_nodes(False)
plat.read_aliases() plat.read_aliases()
plat.assign_seq()
cmds = args[0].split(',') cmds = args[0].split(',')
if 'all' in cmds: if 'all' in cmds:

View File

@@ -1092,3 +1092,9 @@ U_BOOT_DRVINFO(spl_test2) = {
plat = self.run_test(['struct'], dtb_file, output) plat = self.run_test(['struct'], dtb_file, output)
self.assertEqual("Could not find uclass for alias 'other1'", self.assertEqual("Could not find uclass for alias 'other1'",
stdout.getvalue().strip()) stdout.getvalue().strip())
def test_sequence(self):
"""Test assignment of sequence numnbers"""
dtb_file = get_dtb_file('dtoc_test_inst.dts')
output = tools.GetOutputFilename('output')
plat = self.run_test(['struct'], dtb_file, output)