summaryrefslogtreecommitdiff
path: root/tools/dtoc/src_scan.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-02-03 06:01:06 -0700
committerSimon Glass <sjg@chromium.org>2021-03-22 19:23:27 +1300
commit1d97269756a60945e3b9690074d1814198ce5a4e (patch)
tree4e0e496dcb78cda515653739788a6fa5658e1d76 /tools/dtoc/src_scan.py
parent8d6f2d359e7cf5a6960d55281ee378fac7db0bbb (diff)
dtoc: Warn of duplicate drivers
If drivers have the same name then we cannot distinguish them. This only matters if the driver is actually used by dtoc, but in that case, issue a warning. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/dtoc/src_scan.py')
-rw-r--r--tools/dtoc/src_scan.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 9d161a2cbc7..fb78536e003 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -70,6 +70,10 @@ class Driver:
phase (str): Which phase of U-Boot to use this driver
headers (list): List of header files needed for this driver (each a str)
e.g. ['<asm/cpu.h>']
+ dups (list): Driver objects with the same name as this one, that were
+ found after this one
+ warn_dups (bool): True if the duplicates are not distinguisble using
+ the phase
"""
def __init__(self, name, fname):
self.name = name
@@ -83,6 +87,8 @@ class Driver:
self.used = False
self.phase = ''
self.headers = []
+ self.dups = []
+ self.warn_dups = False
def __eq__(self, other):
return (self.name == other.name and
@@ -531,7 +537,21 @@ class Scanner:
self._driver_aliases[m_alias[2]] = m_alias[1]
# Make the updates based on what we found
- self._drivers.update(drivers)
+ for driver in drivers.values():
+ if driver.name in self._drivers:
+ orig = self._drivers[driver.name]
+ if self._phase:
+ # If the original driver matches our phase, use it
+ if orig.phase == self._phase:
+ orig.dups.append(driver)
+ continue
+
+ # Otherwise use the new driver, which is assumed to match
+ else:
+ # We have no way of distinguishing them
+ driver.warn_dups = True
+ driver.dups.append(orig)
+ self._drivers[driver.name] = driver
self._of_match.update(of_match)
def scan_driver(self, fname):
@@ -617,6 +637,8 @@ class Scanner:
This takes a list of nodes, finds the driver for each one and marks it
as used.
+ If two used drivers have the same name, issue a warning.
+
Args:
nodes (list of None): Nodes that are in use
"""
@@ -626,3 +648,7 @@ class Scanner:
driver = self._drivers.get(struct_name)
if driver:
driver.used = True
+ if driver.dups and driver.warn_dups:
+ print("Warning: Duplicate driver name '%s' (orig=%s, dups=%s)" %
+ (driver.name, driver.fname,
+ ', '.join([drv.fname for drv in driver.dups])))