[PATCH 10/20] dtoc: Convert _drivers to a dict

Simon Glass sjg at chromium.org
Thu Dec 17 21:57:24 CET 2020


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 at chromium.org>
---

 tools/dtoc/dtb_platdata.py | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index aef28ac8a9d..3a04bf134eb 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -64,6 +64,17 @@ PhandleInfo = collections.namedtuple('PhandleInfo', ['max_args', 'args'])
 PhandleLink = collections.namedtuple('PhandleLink', ['var_node', 'dev_name'])
 
 
+class DriverInfo:
+    def __init__(self, name):
+        self.name = name
+
+    def __eq__(self, other):
+        return self.name == other.name
+
+    def __repr__(self):
+        return ("DriverInfo(name='%s')" % self.name)
+
+
 def conv_name_to_c(name):
     """Convert a device-tree name to a C identifier
 
@@ -155,7 +166,9 @@ class DtbPlatdata(object):
         _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: DriverInfo 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)
@@ -171,7 +184,7 @@ class DtbPlatdata(object):
         self._outfile = None
         self._warning_disabled = warning_disabled
         self._lines = []
-        self._drivers = []
+        self._drivers = {}
         self._driver_aliases = {}
         self._drivers_additional = drivers_additional or []
 
@@ -195,7 +208,7 @@ class DtbPlatdata(object):
         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
@@ -333,7 +346,7 @@ class DtbPlatdata(object):
             drivers = re.findall('U_BOOT_DRIVER\((.*)\)', buff)
 
             for driver in drivers:
-                self._drivers.append(driver)
+                self._drivers[driver] = DriverInfo(driver)
 
             # The following re will search for driver aliases declared as
             # U_BOOT_DRIVER_ALIAS(alias, driver_name)
-- 
2.29.2.684.gfbc64c5ab5-goog



More information about the U-Boot mailing list