[PATCH v2 05/33] dtoc: Collect priv/plat struct info from drivers

Simon Glass sjg at chromium.org
Wed Feb 3 14:00:53 CET 2021


In order to output variables to hold the priv/plat information used by
each device, dtoc needs to know the struct for each. With this, it can
declare this at build time:

   u8 xxx_priv [sizeof(struct <name>)];

Collect the various struct names from the drivers.

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

(no changes since v1)

 tools/dtoc/src_scan.py      | 25 +++++++++++++++++++++++--
 tools/dtoc/test_src_scan.py | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py
index 761164a9c9a..ff3ab409e4b 100644
--- a/tools/dtoc/src_scan.py
+++ b/tools/dtoc/src_scan.py
@@ -61,6 +61,11 @@ class Driver:
             value: Driver data, e,g, 'ROCKCHIP_SYSCON_GRF', or None
         fname: Filename where the driver was found
         priv (str): struct name of the priv_auto member, e.g. 'serial_priv'
+        plat (str): struct name of the plat_auto member, e.g. 'serial_plat'
+        child_priv (str): struct name of the per_child_auto member,
+            e.g. 'pci_child_priv'
+        child_plat (str): struct name of the per_child_plat_auto member,
+            e.g. 'pci_child_plat'
     """
     def __init__(self, name, fname):
         self.name = name
@@ -68,12 +73,16 @@ class Driver:
         self.uclass_id = None
         self.compat = None
         self.priv = ''
+        self.plat = ''
+        self.child_priv = ''
+        self.child_plat = ''
 
     def __eq__(self, other):
         return (self.name == other.name and
                 self.uclass_id == other.uclass_id and
                 self.compat == other.compat and
-                self.priv == other.priv)
+                self.priv == other.priv and
+                self.plat == other.plat)
 
     def __repr__(self):
         return ("Driver(name='%s', uclass_id='%s', compat=%s, priv=%s)" %
@@ -230,8 +239,11 @@ class Scanner:
         re_of_match = re.compile(
             r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)(\))?,')
 
-        # Matches the struct name for priv
+        # Matches the struct name for priv, plat
         re_priv = self._get_re_for_member('priv_auto')
+        re_plat = self._get_re_for_member('plat_auto')
+        re_child_priv = self._get_re_for_member('per_child_auto')
+        re_child_plat = self._get_re_for_member('per_child_plat_auto')
 
         prefix = ''
         for line in buff.splitlines():
@@ -250,8 +262,17 @@ class Scanner:
                 m_id = re_id.search(line)
                 m_of_match = re_of_match.search(line)
                 m_priv = re_priv.match(line)
+                m_plat = re_plat.match(line)
+                m_cplat = re_child_plat.match(line)
+                m_cpriv = re_child_priv.match(line)
                 if m_priv:
                     driver.priv = m_priv.group(1)
+                elif m_plat:
+                    driver.plat = m_plat.group(1)
+                elif m_cplat:
+                    driver.child_plat = m_cplat.group(1)
+                elif m_cpriv:
+                    driver.child_priv = m_cpriv.group(1)
                 elif m_id:
                     driver.uclass_id = m_id.group(1)
                 elif m_of_match:
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index ada49fb7042..62dea2a9612 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -231,3 +231,35 @@ U_BOOT_DRIVER(i2c_tegra) = {
         self.assertIn('i2c_tegra', scan._drivers)
         drv = scan._drivers['i2c_tegra']
         self.assertEqual('i2c_tegra', drv.name)
+
+    def test_priv(self):
+        """Test collection of struct info from drivers"""
+        buff = '''
+static const struct udevice_id test_ids[] = {
+	{ .compatible = "nvidia,tegra114-i2c", .data = TYPE_114 },
+	{ }
+};
+
+U_BOOT_DRIVER(testing) = {
+	.name	= "testing",
+	.id	= UCLASS_I2C,
+	.of_match = test_ids,
+	.priv_auto	= sizeof(struct some_priv),
+	.plat_auto = sizeof(struct some_plat),
+	.per_child_auto	= sizeof(struct some_cpriv),
+	.per_child_plat_auto = sizeof(struct some_cplat),
+};
+'''
+        scan = src_scan.Scanner(None, False, None)
+        scan._parse_driver('file.c', buff)
+        self.assertIn('testing', scan._drivers)
+        drv = scan._drivers['testing']
+        self.assertEqual('testing', drv.name)
+        self.assertEqual('UCLASS_I2C', drv.uclass_id)
+        self.assertEqual(
+            {'nvidia,tegra114-i2c': 'TYPE_114'}, drv.compat)
+        self.assertEqual('some_priv', drv.priv)
+        self.assertEqual('some_plat', drv.plat)
+        self.assertEqual('some_cpriv', drv.child_priv)
+        self.assertEqual('some_cplat', drv.child_plat)
+        self.assertEqual(1, len(scan._drivers))
-- 
2.30.0.365.g02bc693789-goog



More information about the U-Boot mailing list