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>
This commit is contained in:
@@ -64,6 +64,22 @@ PhandleInfo = collections.namedtuple('PhandleInfo', ['max_args', 'args'])
|
|||||||
PhandleLink = collections.namedtuple('PhandleLink', ['var_node', 'dev_name'])
|
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):
|
def conv_name_to_c(name):
|
||||||
"""Convert a device-tree name to a C identifier
|
"""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)
|
_outfile: The current output file (sys.stdout or a real file)
|
||||||
_warning_disabled: true to disable warnings about driver names not found
|
_warning_disabled: true to disable warnings about driver names not found
|
||||||
_lines: Stashed list of output lines for outputting in the future
|
_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
|
_driver_aliases: Dict that holds aliases for driver names
|
||||||
key: Driver alias declared with
|
key: Driver alias declared with
|
||||||
U_BOOT_DRIVER_ALIAS(driver_alias, driver_name)
|
U_BOOT_DRIVER_ALIAS(driver_alias, driver_name)
|
||||||
@@ -172,7 +190,7 @@ class DtbPlatdata():
|
|||||||
self._outfile = None
|
self._outfile = None
|
||||||
self._warning_disabled = warning_disabled
|
self._warning_disabled = warning_disabled
|
||||||
self._lines = []
|
self._lines = []
|
||||||
self._drivers = []
|
self._drivers = {}
|
||||||
self._driver_aliases = {}
|
self._driver_aliases = {}
|
||||||
self._drivers_additional = drivers_additional or []
|
self._drivers_additional = drivers_additional or []
|
||||||
|
|
||||||
@@ -196,7 +214,7 @@ class DtbPlatdata():
|
|||||||
compat_list_c = get_compat_name(node)
|
compat_list_c = get_compat_name(node)
|
||||||
|
|
||||||
for compat_c in compat_list_c:
|
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)
|
compat_c = self._driver_aliases.get(compat_c)
|
||||||
if not compat_c:
|
if not compat_c:
|
||||||
continue
|
continue
|
||||||
@@ -334,7 +352,7 @@ class DtbPlatdata():
|
|||||||
drivers = re.findall(r'U_BOOT_DRIVER\((.*)\)', buff)
|
drivers = re.findall(r'U_BOOT_DRIVER\((.*)\)', buff)
|
||||||
|
|
||||||
for driver in drivers:
|
for driver in drivers:
|
||||||
self._drivers.append(driver)
|
self._drivers[driver] = Driver(driver)
|
||||||
|
|
||||||
# The following re will search for driver aliases declared as
|
# The following re will search for driver aliases declared as
|
||||||
# U_BOOT_DRIVER_ALIAS(alias, driver_name)
|
# U_BOOT_DRIVER_ALIAS(alias, driver_name)
|
||||||
|
@@ -906,3 +906,13 @@ U_BOOT_DEVICE(spl_test2) = {
|
|||||||
with test_util.capture_sys_output() as (stdout, stderr):
|
with test_util.capture_sys_output() as (stdout, stderr):
|
||||||
dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
|
dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
|
||||||
[driver_fn])
|
[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)
|
||||||
|
Reference in New Issue
Block a user