]> git.baikalelectronics.ru Git - uboot.git/commitdiff
dtoc: Track nodes which are actually used
authorSimon Glass <sjg@chromium.org>
Wed, 3 Feb 2021 13:01:01 +0000 (06:01 -0700)
committerSimon Glass <sjg@chromium.org>
Mon, 22 Mar 2021 06:23:27 +0000 (19:23 +1300)
Mark all nodes that are actually used, so we can perform extra checks on
them.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/dtoc/dtb_platdata.py
tools/dtoc/src_scan.py
tools/dtoc/test_dtoc.py
tools/dtoc/test_src_scan.py

index ad71f703e52af70f28a94f9a796d8c6c105f7b8a..28669f3121784e7e270efce5a4ad05be1c7122b9 100644 (file)
@@ -650,6 +650,9 @@ class DtbPlatdata():
     def process_nodes(self, need_drivers):
         nodes_to_output = list(self._valid_nodes)
 
+        # Figure out which drivers we actually use
+        self._scan.mark_used(nodes_to_output)
+
         for node in nodes_to_output:
             node.dev_ref = 'DM_DEVICE_REF(%s)' % node.var_name
             driver = self._scan.get_driver(node.struct_name)
index 504dac008d6109d8ed9bac5f88d6a223eb5341d9..1a02d41063f4c2f1a08de3b3527d4d85a788de0f 100644 (file)
@@ -66,6 +66,7 @@ class Driver:
             e.g. 'pci_child_priv'
         child_plat (str): struct name of the per_child_plat_auto member,
             e.g. 'pci_child_plat'
+        used (bool): True if the driver is used by the structs being output
     """
     def __init__(self, name, fname):
         self.name = name
@@ -76,17 +77,19 @@ class Driver:
         self.plat = ''
         self.child_priv = ''
         self.child_plat = ''
+        self.used = False
 
     def __eq__(self, other):
         return (self.name == other.name and
                 self.uclass_id == other.uclass_id and
                 self.compat == other.compat and
                 self.priv == other.priv and
-                self.plat == other.plat)
+                self.plat == other.plat and
+                self.used == other.used)
 
     def __repr__(self):
-        return ("Driver(name='%s', uclass_id='%s', compat=%s, priv=%s)" %
-                (self.name, self.uclass_id, self.compat, self.priv))
+        return ("Driver(name='%s', used=%s, uclass_id='%s', compat=%s, priv=%s)" %
+                (self.name, self.used, self.uclass_id, self.compat, self.priv))
 
 
 class UclassDriver:
@@ -596,3 +599,19 @@ class Scanner:
                 self.scan_driver(fname)
             else:
                 self.scan_driver(self._basedir + '/' + fname)
+
+    def mark_used(self, nodes):
+        """Mark the drivers associated with a list of nodes as 'used'
+
+        This takes a list of nodes, finds the driver for each one and marks it
+        as used.
+
+        Args:
+            nodes (list of None): Nodes that are in use
+        """
+        # Figure out which drivers we actually use
+        for node in nodes:
+            struct_name, _ = self.get_normalized_compat_name(node)
+            driver = self._drivers.get(struct_name)
+            if driver:
+                driver.used = True
index 3e98e363125b5bc172a93adc3286ec28c2c46ff1..d90ece205d7cde01dadecd228c969f84a2b8a80d 100755 (executable)
@@ -1029,3 +1029,14 @@ U_BOOT_DRVINFO(spl_test2) = {
             plat.process_nodes(True)
         self.assertIn("Cannot parse/find driver for 'sandbox_pmic",
                       str(exc.exception))
+
+    def test_process_nodes_used(self):
+        """Test processing nodes to add various info"""
+        plat, scan = self.setup_process_test()
+        plat.process_nodes(True)
+
+        pmic = scan._drivers['sandbox_pmic']
+        self.assertTrue(pmic.used)
+
+        gpio = scan._drivers['sandbox_gpio']
+        self.assertFalse(gpio.used)
index a7eba3005e5ffb11473b274d1f858e9ac79640d5..ebdc12abc87c46b0d804d2ff13823c2ac85e640b 100644 (file)
@@ -98,7 +98,7 @@ class TestSrcScan(unittest.TestCase):
         drv3.uclass_id = i2c
         drv3.compat = compat
         self.assertEqual(
-            "Driver(name='fred', uclass_id='I2C_UCLASS', "
+            "Driver(name='fred', used=False, uclass_id='I2C_UCLASS', "
             "compat={'rockchip,rk3288-grf': 'ROCKCHIP_SYSCON_GRF', "
             "'rockchip,rk3288-srf': None}, priv=)", str(drv1))
         self.assertEqual(drv1, drv3)