]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dtoc: Convert _drivers to a dict
authorSimon Glass <sjg@chromium.org>
Wed, 23 Dec 2020 15:11:23 +0000 (08:11 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 5 Jan 2021 19:24:41 +0000 (12:24 -0700)
At present this member holds a simple list of driver names. Update it to
be a dict of DriverInfo, with the name being the key. This will allow more
information to be added about each driver, in future patches.

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

index 1d89f77a00bd49baf6c11c47d6bd2971b1fb61da..5b1bb7e5fd9ea82115cdbd34f1a50e4682784b0c 100644 (file)
@@ -64,6 +64,22 @@ PhandleInfo = collections.namedtuple('PhandleInfo', ['max_args', 'args'])
 PhandleLink = collections.namedtuple('PhandleLink', ['var_node', 'dev_name'])
 
 
+class Driver:
+    """Information about a driver in U-Boot
+
+    Attributes:
+        name: Name of driver. For U_BOOT_DRIVER(x) this is 'x'
+    """
+    def __init__(self, name):
+        self.name = name
+
+    def __eq__(self, other):
+        return self.name == other.name
+
+    def __repr__(self):
+        return "Driver(name='%s')" % self.name
+
+
 def conv_name_to_c(name):
     """Convert a device-tree name to a C identifier
 
@@ -156,7 +172,9 @@ class DtbPlatdata():
         _outfile: The current output file (sys.stdout or a real file)
         _warning_disabled: true to disable warnings about driver names not found
         _lines: Stashed list of output lines for outputting in the future
-        _drivers: List of valid driver names found in drivers/
+        _drivers: Dict of valid driver names found in drivers/
+            key: Driver name
+            value: Driver for that driver
         _driver_aliases: Dict that holds aliases for driver names
             key: Driver alias declared with
                 U_BOOT_DRIVER_ALIAS(driver_alias, driver_name)
@@ -172,7 +190,7 @@ class DtbPlatdata():
         self._outfile = None
         self._warning_disabled = warning_disabled
         self._lines = []
-        self._drivers = []
+        self._drivers = {}
         self._driver_aliases = {}
         self._drivers_additional = drivers_additional or []
 
@@ -196,7 +214,7 @@ class DtbPlatdata():
         compat_list_c = get_compat_name(node)
 
         for compat_c in compat_list_c:
-            if not compat_c in self._drivers:
+            if not compat_c in self._drivers.keys():
                 compat_c = self._driver_aliases.get(compat_c)
                 if not compat_c:
                     continue
@@ -334,7 +352,7 @@ class DtbPlatdata():
             drivers = re.findall(r'U_BOOT_DRIVER\((.*)\)', buff)
 
             for driver in drivers:
-                self._drivers.append(driver)
+                self._drivers[driver] = Driver(driver)
 
             # The following re will search for driver aliases declared as
             # U_BOOT_DRIVER_ALIAS(alias, driver_name)
index 49ab75b85dab79b8842e4bf3614c6fb8e15fd513..c76942c9e2d49d888de98f4845c9b8b14172a47b 100755 (executable)
@@ -906,3 +906,13 @@ U_BOOT_DEVICE(spl_test2) = {
         with test_util.capture_sys_output() as (stdout, stderr):
             dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
                                [driver_fn])
+
+    def testDriver(self):
+        """Test the Driver class"""
+        drv1 = dtb_platdata.Driver('fred')
+        drv2 = dtb_platdata.Driver('mary')
+        drv3 = dtb_platdata.Driver('fred')
+        self.assertEqual("Driver(name='fred')", str(drv1))
+        self.assertEqual(drv1, drv3)
+        self.assertNotEqual(drv1, drv2)
+        self.assertNotEqual(drv2, drv3)