]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dtoc: Detect drivers which do not parse correctly
authorSimon Glass <sjg@chromium.org>
Sun, 4 Jul 2021 18:19:49 +0000 (12:19 -0600)
committerSimon Glass <sjg@chromium.org>
Wed, 21 Jul 2021 16:27:34 +0000 (10:27 -0600)
At present if a driver is missing a uclass or compatible stirng, this
is silently ignored. This makes sense in most cases, particularly for
the compatible string, since it is not required except when the driver
is used with of-platdata.

But it is also not very helpful. When there is some sort of problem
with a driver, the missing compatible string (for example) may be the
cause.

Add a warning in this case, showing it only for drivers which are used
by the build.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Walter Lozano <walter.lozano@collabora.com>
tools/dtoc/src_scan.py
tools/dtoc/test_src_scan.py

index 847677757d93d59c337097327f38d194c6836a51..3bef59d616ed9e1069051d26b70f16098b01c59a 100644 (file)
@@ -546,7 +546,12 @@ class Scanner:
                         # The driver does not have a uclass or compat string.
                         # The first is required but the second is not, so just
                         # ignore this.
-                        pass
+                        if not driver.uclass_id:
+                            warn = 'Missing .uclass'
+                        else:
+                            warn = 'Missing .compatible'
+                        self._warnings[driver.name].add('%s in %s' %
+                                                        (warn, fname))
                     driver = None
                     ids_name = None
                     compat = None
index 62500e80fe77f0fe4c32643f4134279aad60b768..f03cf8ed7c7110b7827990b5957384560e658d8e 100644 (file)
@@ -581,3 +581,41 @@ rockchip_rk3288_grf: WARNING: the driver rockchip_rk3288_grf was not found in th
 ''',
             stdout.getvalue())
         self.assertIn('tegra_i2c_ids', stdout.getvalue())
+
+    def scan_uclass_warning(self):
+        """Test a missing .uclass in the driver"""
+        buff = '''
+static const struct udevice_id tegra_i2c_ids[] = {
+       { .compatible = "nvidia,tegra114-i2c", .data = TYPE_114 },
+       { }
+};
+
+U_BOOT_DRIVER(i2c_tegra) = {
+       .name   = "i2c_tegra",
+       .of_match = tegra_i2c_ids,
+};
+'''
+        scan = src_scan.Scanner(None, None)
+        scan._parse_driver('file.c', buff)
+        self.assertEqual(
+            {'i2c_tegra': {'Missing .uclass in file.c'}},
+            scan._warnings)
+
+    def scan_compat_warning(self):
+        """Test a missing .compatible in the driver"""
+        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,
+};
+'''
+        scan = src_scan.Scanner(None, None)
+        scan._parse_driver('file.c', buff)
+        self.assertEqual(
+            {'i2c_tegra': {'Missing .compatible in file.c'}},
+            scan._warnings)