All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v2 21/33] dtoc: Assign a sequence number to each node
Date: Wed,  3 Feb 2021 06:01:09 -0700	[thread overview]
Message-ID: <20210203130121.2478810-22-sjg@chromium.org> (raw)
In-Reply-To: <20210203130121.2478810-1-sjg@chromium.org>

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

(no changes since v1)

 drivers/misc/test_drv.c    |  6 +++--
 test/dm/test-fdt.c         |  6 ++---
 tools/dtoc/dtb_platdata.py | 55 +++++++++++++++++++++++++++-----------
 tools/dtoc/test_dtoc.py    |  6 +++++
 4 files changed, 53 insertions(+), 20 deletions(-)

diff --git a/drivers/misc/test_drv.c b/drivers/misc/test_drv.c
index 7dd3de34c99..ac762fd9fea 100644
--- a/drivers/misc/test_drv.c
+++ b/drivers/misc/test_drv.c
@@ -85,7 +85,7 @@ static const struct udevice_id testbus_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(testbus_drv) = {
+U_BOOT_DRIVER(denx_u_boot_test_bus) = {
 	.name	= "testbus_drv",
 	.of_match	= testbus_ids,
 	.id	= UCLASS_TEST_BUS,
@@ -159,7 +159,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",
 	.of_match	= testfdt_ids,
 	.id	= UCLASS_TEST_FDT,
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index b5ac9bba24e..64f7fb0ccb2 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -329,7 +329,7 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
 
 	/* Check creating a device with an alias */
 	node = ofnode_path("/some-bus/c-test at 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 at 1", NULL, node, &dev));
 	ut_asserteq(12, dev_seq(dev));
 	ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 12, &dev));
@@ -349,11 +349,11 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
 	 *
 	 * 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));
 	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));
 	ut_asserteq(20, dev_seq(dev));
 
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index f6dcf47d490..9e99c63ae70 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -136,8 +136,10 @@ class DtbPlatdata():
             from the U-Boot source code
         _fdt: Fdt object, referencing the device tree
         _dtb_fname: Filename of the input device tree binary file
-        _valid_nodes: A list of Node object with compatible strings. The list
-            is ordered by conv_name_to_c(node.name)
+        _valid_nodes_unsorted: A list of Node object with compatible strings,
+            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"
         _outfile: The current output file (sys.stdout or a real file)
         _lines: Stashed list of output lines for outputting in the future
@@ -155,6 +157,7 @@ class DtbPlatdata():
         self._fdt = None
         self._dtb_fname = dtb_fname
         self._valid_nodes = None
+        self._valid_nodes_unsorted = None
         self._include_disabled = include_disabled
         self._outfile = None
         self._lines = []
@@ -324,34 +327,38 @@ class DtbPlatdata():
         """
         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
 
-        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:
-            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
         """
-        for node in root.subnodes:
-            if 'compatible' in node.props:
-                status = node.props.get('status')
+        for subnode in node.subnodes:
+            if 'compatible' in subnode.props:
+                status = subnode.props.get('status')
                 if (not self._include_disabled and not status or
                         status.value != 'disabled'):
-                    valid_nodes.append(node)
+                    valid_nodes.append(subnode)
 
             # recurse to handle any subnodes
-            self.scan_node(node, valid_nodes)
+            self.scan_node(subnode, valid_nodes)
 
     def scan_tree(self):
         """Scan the device tree for useful information
 
         This fills in the following properties:
-            _valid_nodes: A list of nodes we wish to consider include in the
-                platform data
+            _valid_nodes_unsorted: A list of nodes we wish to consider include
+                in the platform data (in devicetree node order)
+            _valid_nodes: Sorted version of _valid_nodes_unsorted
         """
+        root = self._fdt.GetRoot()
         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,
                                    key=lambda x: conv_name_to_c(x.name))
 
@@ -670,6 +677,24 @@ class DtbPlatdata():
             elif result is False:
                 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):
         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.scan_structs()
     plat.scan_phandles()
-    if do_process:
-        plat.process_nodes(False)
+    plat.process_nodes(False)
     plat.read_aliases()
+    plat.assign_seq()
 
     cmds = args[0].split(',')
     if 'all' in cmds:
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 706cc39b3d5..b4c0a042a9f 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -1092,3 +1092,9 @@ U_BOOT_DRVINFO(spl_test2) = {
             plat = self.run_test(['struct'], dtb_file, output)
         self.assertEqual("Could not find uclass for alias 'other1'",
                          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)
-- 
2.30.0.365.g02bc693789-goog

  parent reply	other threads:[~2021-02-03 13:01 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 13:00 [PATCH v2 00/33] dm: Add dtoc implementation of device instantiation (part D) Simon Glass
2021-02-03 13:00 ` [PATCH v2 01/33] bootstage: Fix dependency for BOOTSTAGE_RECORD_COUNT Simon Glass
2021-02-03 13:00 ` [PATCH v2 02/33] dtoc: Scan drivers for available information Simon Glass
2021-02-03 13:00 ` [PATCH v2 03/33] dtoc: Save scan information across test runs Simon Glass
2021-02-03 13:00 ` [PATCH v2 04/33] dtoc: Ignore unwanted files when scanning for drivers Simon Glass
2021-02-03 13:00 ` [PATCH v2 05/33] dtoc: Collect priv/plat struct info from drivers Simon Glass
2021-02-03 13:00 ` [PATCH v2 06/33] dtoc: Support scanning of uclasses Simon Glass
2021-02-03 13:00 ` [PATCH v2 07/33] dtoc: Support scanning of structs in header files Simon Glass
2021-02-03 13:00 ` [PATCH v2 08/33] dtoc: Move test files into a test/ directory Simon Glass
2021-02-03 13:00 ` [PATCH v2 09/33] dtoc: Rename sandbox_i2c_test and sandbox_pmic_test Simon Glass
2021-02-03 13:00 ` [PATCH v2 10/33] dtoc: Add some extra properties to nodes Simon Glass
2021-02-03 13:00 ` [PATCH v2 11/33] dtoc: Make use of node properties Simon Glass
2021-02-03 13:01 ` [PATCH v2 12/33] dtoc: Process nodes to set up required properties Simon Glass
2021-02-03 13:01 ` [PATCH v2 13/33] dtoc: Track nodes which are actually used Simon Glass
2021-02-03 13:01 ` [PATCH v2 14/33] dtoc: Support tracking the phase of U-Boot Simon Glass
2021-02-03 13:01 ` [PATCH v2 15/33] Makefile: Pass the U-Boot phase to dtoc Simon Glass
2021-02-03 13:01 ` [PATCH v2 16/33] dtoc: Support headers needed for drivers Simon Glass
2021-02-03 13:01 ` [PATCH v2 17/33] dtoc: Process driver aliases along with drivers Simon Glass
2021-06-21 18:39   ` Johan Jonker
2021-06-26 18:32     ` Simon Glass
2021-07-04 18:18       ` Simon Glass
2021-02-03 13:01 ` [PATCH v2 18/33] dtoc: Warn of duplicate drivers Simon Glass
2021-02-03 13:01 ` [PATCH v2 19/33] dtoc: Read aliases for uclasses Simon Glass
2021-02-03 13:01 ` [PATCH v2 20/33] dtoc: Detect drivers only at the start of start of line Simon Glass
2021-02-03 13:01 ` Simon Glass [this message]
2021-02-03 13:01 ` [PATCH v2 22/33] dtoc: Set up the uclasses that are used Simon Glass
2021-02-03 13:01 ` [PATCH v2 23/33] dtoc: Support processing the root node Simon Glass
2021-02-03 13:01 ` [PATCH v2 24/33] dtoc: Add an option for device instantiation Simon Glass
2021-02-03 13:01 ` [PATCH v2 25/33] dm: of-platadata: Add " Simon Glass
2021-02-03 13:01 ` [PATCH v2 26/33] dtoc: Add support for decl file Simon Glass
2021-02-03 13:01 ` [PATCH v2 27/33] dtoc: Don't generate platform data with instantiation Simon Glass
2021-02-03 13:01 ` [PATCH v2 28/33] sandbox: Make sandbox,emul more conventional Simon Glass
2021-02-03 13:01 ` [PATCH v2 29/33] sandbox: i2c: Rename driver names to work with of-platdata Simon Glass
2021-02-03 13:01 ` [PATCH v2 30/33] dtoc: Tidy up the list of supported phandle properties Simon Glass
2021-02-03 13:01 ` [PATCH v2 31/33] dtoc: Generate a summary in the dt-plat.c file Simon Glass
2021-02-03 13:01 ` [PATCH v2 32/33] dtoc: Generate uclass devices Simon Glass
2021-02-03 13:01 ` [PATCH v2 33/33] dtoc: Generate device instances Simon Glass
2021-02-07  0:16 ` Simon Glass
2021-02-07  0:16 ` [PATCH v2 32/33] dtoc: Generate uclass devices Simon Glass
2021-02-07  0:16 ` [PATCH v2 31/33] dtoc: Generate a summary in the dt-plat.c file Simon Glass
2021-02-07  0:16 ` [PATCH v2 30/33] dtoc: Tidy up the list of supported phandle properties Simon Glass
2021-02-07  0:16 ` [PATCH v2 29/33] sandbox: i2c: Rename driver names to work with of-platdata Simon Glass
2021-02-07  0:16 ` [PATCH v2 28/33] sandbox: Make sandbox,emul more conventional Simon Glass
2021-02-07  0:16 ` [PATCH v2 27/33] dtoc: Don't generate platform data with instantiation Simon Glass
2021-02-07  0:16 ` [PATCH v2 26/33] dtoc: Add support for decl file Simon Glass
2021-02-07  0:16 ` [PATCH v2 25/33] dm: of-platadata: Add option for device instantiation Simon Glass
2021-02-07  0:17 ` [PATCH v2 24/33] dtoc: Add an " Simon Glass
2021-02-07  0:17 ` [PATCH v2 23/33] dtoc: Support processing the root node Simon Glass
2021-02-07  0:17 ` [PATCH v2 22/33] dtoc: Set up the uclasses that are used Simon Glass
2021-02-07  0:17 ` [PATCH v2 21/33] dtoc: Assign a sequence number to each node Simon Glass
2021-02-07  0:17 ` [PATCH v2 20/33] dtoc: Detect drivers only at the start of start of line Simon Glass
2021-02-07  0:17 ` [PATCH v2 19/33] dtoc: Read aliases for uclasses Simon Glass
2021-02-07  0:17 ` [PATCH v2 18/33] dtoc: Warn of duplicate drivers Simon Glass
2021-02-07  0:17 ` [PATCH v2 17/33] dtoc: Process driver aliases along with drivers Simon Glass
2021-02-07  0:17 ` [PATCH v2 16/33] dtoc: Support headers needed for drivers Simon Glass
2021-02-07  0:17 ` [PATCH v2 15/33] Makefile: Pass the U-Boot phase to dtoc Simon Glass
2021-02-07  0:17 ` [PATCH v2 14/33] dtoc: Support tracking the phase of U-Boot Simon Glass
2021-02-07  0:17 ` [PATCH v2 13/33] dtoc: Track nodes which are actually used Simon Glass
2021-02-07  0:17 ` [PATCH v2 12/33] dtoc: Process nodes to set up required properties Simon Glass
2021-02-07  0:17 ` [PATCH v2 11/33] dtoc: Make use of node properties Simon Glass
2021-02-07  0:17 ` [PATCH v2 10/33] dtoc: Add some extra properties to nodes Simon Glass
2021-02-07  0:17 ` [PATCH v2 09/33] dtoc: Rename sandbox_i2c_test and sandbox_pmic_test Simon Glass
2021-02-07  0:17 ` [PATCH v2 08/33] dtoc: Move test files into a test/ directory Simon Glass
2021-02-07  0:17 ` [PATCH v2 07/33] dtoc: Support scanning of structs in header files Simon Glass
2021-02-07  0:17 ` [PATCH v2 06/33] dtoc: Support scanning of uclasses Simon Glass
2021-02-07  0:17 ` [PATCH v2 05/33] dtoc: Collect priv/plat struct info from drivers Simon Glass
2021-02-07  0:17 ` [PATCH v2 04/33] dtoc: Ignore unwanted files when scanning for drivers Simon Glass
2021-02-07  0:17 ` [PATCH v2 03/33] dtoc: Save scan information across test runs Simon Glass
2021-02-07  0:17 ` [PATCH v2 02/33] dtoc: Scan drivers for available information Simon Glass
2021-02-07  0:17 ` [PATCH v2 01/33] bootstage: Fix dependency for BOOTSTAGE_RECORD_COUNT Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210203130121.2478810-22-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.