diff options
author | Simon Glass <sjg@chromium.org> | 2020-12-23 18:11:23 +0300 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2021-01-05 22:24:41 +0300 |
commit | 7d637c122d772e472a211f6aa3f33cbe3c3e243c (patch) | |
tree | a6a2c95c4e97af74e48c73cf60d931cca31b9df7 /tools | |
parent | 161dac1dd86fdc4e819b32ab12f656d8d738f95a (diff) | |
download | u-boot-7d637c122d772e472a211f6aa3f33cbe3c3e243c.tar.xz |
dtoc: Convert _drivers to a dict
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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/dtoc/dtb_platdata.py | 26 | ||||
-rwxr-xr-x | tools/dtoc/test_dtoc.py | 10 |
2 files changed, 32 insertions, 4 deletions
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 1d89f77a00..5b1bb7e5fd 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -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) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 49ab75b85d..c76942c9e2 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -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) |