Re: [PATCH 6/8] dtoc: Detect unexpected suffix on .of_match

2021-07-11 Thread Simon Glass
Some rockchip drivers use a suffix on the of_match line which is not
strictly valid. At present this causes the parsing to fail. Fix this
and offer a warning.

Signed-off-by: Simon Glass 
---

 tools/dtoc/src_scan.py  | 12 +++--
 tools/dtoc/test_src_scan.py | 92 +
 2 files changed, 101 insertions(+), 3 deletions(-)

Applied to u-boot-dm, thanks!


[PATCH 6/8] dtoc: Detect unexpected suffix on .of_match

2021-07-04 Thread Simon Glass
Some rockchip drivers use a suffix on the of_match line which is not
strictly valid. At present this causes the parsing to fail. Fix this
and offer a warning.

Signed-off-by: Simon Glass 
---

 tools/dtoc/src_scan.py  | 12 +++--
 tools/dtoc/test_src_scan.py | 92 +
 2 files changed, 101 insertions(+), 3 deletions(-)

diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 6e8e1ba51a0..847677757d9 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -468,7 +468,7 @@ class Scanner:
 
 # Matches the references to the udevice_id list
 re_of_match = re.compile(
-r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)(\))?,')
+r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)([^,]*),')
 
 re_phase = re.compile('^\s*DM_PHASE\((.*)\).*$')
 re_hdr = re.compile('^\s*DM_HEADER\((.*)\).*$')
@@ -514,6 +514,11 @@ class Scanner:
 driver.uclass_id = m_id.group(1)
 elif m_of_match:
 compat = m_of_match.group(2)
+suffix = m_of_match.group(3)
+if suffix and suffix != ')':
+self._warnings[driver.name].add(
+"%s: Warning: unexpected suffix '%s' on .of_match 
line for compat '%s'" %
+(fname, suffix, compat))
 elif m_phase:
 driver.phase = m_phase.group(1)
 elif m_hdr:
@@ -586,13 +591,14 @@ class Scanner:
 def show_warnings(self):
 """Show any warnings that have been collected"""
 used_drivers = [drv.name for drv in self._drivers.values() if drv.used]
-missing = self._missing_drivers
+missing = self._missing_drivers.copy()
 for name in sorted(self._warnings.keys()):
 if name in missing or name in used_drivers:
 warns = sorted(list(self._warnings[name]))
-# For now there is only ever one warning
 print('%s: %s' % (name, warns[0]))
 indent = ' ' * len(name)
+for warn in warns[1:]:
+print('%-s: %s' % (indent, warn))
 if name in missing:
 missing.remove(name)
 print()
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index 4e38b25a2f8..62500e80fe7 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -20,6 +20,9 @@ from patman import tools
 
 OUR_PATH = os.path.dirname(os.path.realpath(__file__))
 
+EXPECT_WARN = {'rockchip_rk3288_grf':
+   {'WARNING: the driver rockchip_rk3288_grf was not found in 
the driver list'}}
+
 class FakeNode:
 """Fake Node object for testing"""
 def __init__(self):
@@ -152,6 +155,7 @@ class TestSrcScan(unittest.TestCase):
  'nvidia,tegra20-i2c-dvc': 'TYPE_DVC'}, drv.compat)
 self.assertEqual('i2c_bus', drv.priv)
 self.assertEqual(1, len(scan._drivers))
+self.assertEqual({}, scan._warnings)
 
 def test_normalized_name(self):
 """Test operation of get_normalized_compat_name()"""
@@ -172,6 +176,7 @@ class TestSrcScan(unittest.TestCase):
 self.assertEqual(1, len(scan._missing_drivers))
 self.assertEqual({'rockchip_rk3288_grf'}, scan._missing_drivers)
 self.assertEqual('', stdout.getvalue().strip())
+self.assertEqual(EXPECT_WARN, scan._warnings)
 
 i2c = 'I2C_UCLASS'
 compat = {'rockchip,rk3288-grf': 'ROCKCHIP_SYSCON_GRF',
@@ -188,6 +193,7 @@ class TestSrcScan(unittest.TestCase):
 self.assertEqual('', stdout.getvalue().strip())
 self.assertEqual('rockchip_rk3288_grf', name)
 self.assertEqual([], aliases)
+self.assertEqual(EXPECT_WARN, scan._warnings)
 
 prop.value = 'rockchip,rk3288-srf'
 with test_util.capture_sys_output() as (stdout, _):
@@ -195,6 +201,7 @@ class TestSrcScan(unittest.TestCase):
 self.assertEqual('', stdout.getvalue().strip())
 self.assertEqual('rockchip_rk3288_grf', name)
 self.assertEqual(['rockchip_rk3288_srf'], aliases)
+self.assertEqual(EXPECT_WARN, scan._warnings)
 
 def test_scan_errors(self):
 """Test detection of scanning errors"""
@@ -489,3 +496,88 @@ U_BOOT_DRIVER(%s) = {
 self.assertEqual(3, seq)
 self.assertEqual({'mypath': 3}, uc.alias_path_to_num)
 self.assertEqual({2: node, 3: node}, uc.alias_num_to_node)
+
+def test_scan_warnings(self):
+"""Test detection of scanning warnings"""
+buff = '''
+static const struct udevice_id tegra_i2c_ids[] = {
+   { .compatible = "nvidia,tegra114-i2c", .data = TYPE_114 },
+   { }
+};
+
+U_BOOT_DRIVER(i2c_tegra) = {
+   .name   = "i2c_tegra",
+   .id = UCLASS_I2C,
+   .of_match = tegra_i2c_ids + 1,
+};
+'''
+# The '+ 1' above should generate a warning
+
+prop = FakeProp()