[PATCH v2 13/21] dtoc: Allow use of the of_match_ptr() macro

Simon Glass sjg at chromium.org
Wed Dec 23 16:11:25 CET 2020


Update the regex for the of_match member to allow of_match_ptr() so it
matches both:

	.of_match	= apl_hostbridge_ids,
and
	.of_match	= of_match_ptr(apl_hostbridge_ids),

Without this, dtoc emits warnings and cannot find the drivers.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py |  5 +++--
 tools/dtoc/test_dtoc.py    | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 51c4d1cae00..9c2bd18f5a4 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -408,7 +408,8 @@ class DtbPlatdata():
         re_ids = re.compile(r'struct udevice_id (.*)\[\]\s*=')
 
         # Matches the references to the udevice_id list
-        re_of_match = re.compile(r'\.of_match\s*=\s*([a-z0-9_]+),')
+        re_of_match = re.compile(
+            r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)(\))?,')
 
         # Matches the header/size information for priv
         re_priv = re.compile(r'^\s*DM_PRIV\((.*)\)$')
@@ -431,7 +432,7 @@ class DtbPlatdata():
                 if id_m:
                     uclass_id = id_m.group(1)
                 elif id_of_match:
-                    compat = id_of_match.group(1)
+                    compat = id_of_match.group(2)
                 elif '};' in line:
                     if uclass_id and compat:
                         if compat not in of_match:
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 89192797781..1fd981f51e1 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -1009,3 +1009,23 @@ U_BOOT_DRIVER(i2c_tegra) = {
         self.assertIn(
             "file.c: Unknown compatible var 'tegra_i2c_ids' (found: tegra_i2c_ids2)",
             str(e.exception))
+
+    def testOfmatch(self):
+        """Test detection of of_match_ptr() member"""
+        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 = of_match_ptr(tegra_i2c_ids),
+};
+'''
+        dpd = dtb_platdata.DtbPlatdata(None, False, False)
+        dpd._parse_driver('file.c', buff)
+        self.assertIn('i2c_tegra', dpd._drivers)
+        drv = dpd._drivers['i2c_tegra']
+        self.assertEqual('i2c_tegra', drv.name)
-- 
2.29.2.729.g45daf8777d-goog



More information about the U-Boot mailing list