Skip to contentSkip to conversation

dtoc: improve compatible string aliases support

PATCH Superseded Walter Lozano 1 participant 3 messages Jul 16, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover dtoc: improve compatible string aliases support

This series adds additional improvements to dtoc, which are focused in compatible string aliases.

First, enhance dtoc to use not only the first but all the compatible strings in a dtb node in order to find a valid driver name.

Second, remove compatible string aliases from dtoc which were used to generate mappings between struct names. This is not longer needed since now a valid driver name is used.

Walter Lozano (2):
dtoc: look for compatible string aliases in driver list
dtoc: remove compatible string aliases support

 tools/dtoc/dtb_platdata.py       | 58 +++++++++++++-------------------
 tools/dtoc/dtoc_test_aliases.dts |  5 +++
 tools/dtoc/test_dtoc.py          | 39 +++------------------
 3 files changed, 32 insertions(+), 70 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 dtoc: look for compatible string aliases in driver list

Currently dtoc checks if the first compatible string in a dtb node matches either a driver o driver alias name, without taking into account any other compatible string in the list. In the case that no driver matches the first compatible string a warning is printed and the U_BOOT_DEVICE is not being declared correctly.

This patch adds dtoc's support for try all the compatible strings in the dtb node, in an effort to find the correct driver.

---

 tools/dtoc/dtb_platdata.py       | 45 ++++++++++++++++----------------
 tools/dtoc/dtoc_test_aliases.dts |  5 ++++
 tools/dtoc/test_dtoc.py          | 20 +++++++++++---
 3 files changed, 44 insertions(+), 26 deletions(-)
tools/dtoc/dtb_platdata.py +23 -22
index c148c49625..b1b082e508 100644
@@ -111,21 +111,17 @@ def get_value(ftype, value):
         return '%#x' % value
 
 def get_compat_name(node):
-    """Get a node's first compatible string as a C identifier
+    """Get the node's list of compatible string as a C identifiers
 
     Args:
         node: Node object to check
     Return:
-        Tuple:
-            C identifier for the first compatible string
-            List of C identifiers for all the other compatible strings
-                (possibly empty)
+        List of C identifiers for all the compatible strings
     """
     compat = node.props['compatible'].value
-    aliases = []
-    if isinstance(compat, list):
-        compat, aliases = compat[0], compat[1:]
-    return conv_name_to_c(compat), [conv_name_to_c(a) for a in aliases]
+    if not isinstance(compat, list):
+        compat = [compat]
+    return [conv_name_to_c(c) for c in compat]
 
 
 class DtbPlatdata(object):
@@ -169,7 +165,7 @@ class DtbPlatdata(object):
     def get_normalized_compat_name(self, node):
         """Get a node's normalized compat name
 
-        Returns a valid driver name by retrieving node's first compatible
+        Returns a valid driver name by retrieving node's list of compatible
         string as a C identifier and performing a check against _drivers
         and a lookup in driver_aliases printing a warning in case of failure.
 
@@ -183,19 +179,24 @@ class DtbPlatdata(object):
                 In case of no match found, the return will be the same as
                 get_compat_name()
         """
-        compat_c, aliases_c = get_compat_name(node)
-        if compat_c not in self._drivers:
-            compat_c_old = compat_c
-            compat_c = self._driver_aliases.get(compat_c)
-            if not compat_c:
-                if not self._warning_disabled:
-                    print('WARNING: the driver %s was not found in the driver list'
-                          % (compat_c_old))
-                compat_c = compat_c_old
-            else:
-                aliases_c = [compat_c_old] + aliases_c
+        compat_list_c = get_compat_name(node)
+
+        for compat_c in compat_list_c:
+            if not compat_c in self._drivers:
+                compat_c = self._driver_aliases.get(compat_c)
+                if not compat_c:
+                    continue
+
+            aliases_c = compat_list_c
+            if compat_c in aliases_c:
+                aliases_c.remove(compat_c)
+            return compat_c, aliases_c
+
+        if not self._warning_disabled:
+            print('WARNING: the driver %s was not found in the driver list'
+                  % (compat_list_c[0]))
 
-        return compat_c, aliases_c
+        return compat_list_c[0], compat_list_c[1:]
 
     def setup_output(self, fname):
         """Set up the output destination
tools/dtoc/dtoc_test_aliases.dts +5 -0
index e545816f4e..ae33716863 100644
@@ -14,4 +14,9 @@
 		intval = <1>;
 	};
 
+	spl-test2 {
+		u-boot,dm-pre-reloc;
+		compatible = "compat1", "simple_bus";
+		intval = <1>;
+	};
 };
tools/dtoc/test_dtoc.py +16 -4
index 3c8e343b1f..edb3912e94 100755
@@ -144,18 +144,18 @@ class TestDtoc(unittest.TestCase):
 
         prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1'])
         node = Node({'compatible': prop})
-        self.assertEqual(('rockchip_rk3399_sdhci_5_1', ['arasan_sdhci_5_1']),
+        self.assertEqual((['rockchip_rk3399_sdhci_5_1', 'arasan_sdhci_5_1']),
                          get_compat_name(node))
 
         prop = Prop(['rockchip,rk3399-sdhci-5.1'])
         node = Node({'compatible': prop})
-        self.assertEqual(('rockchip_rk3399_sdhci_5_1', []),
+        self.assertEqual((['rockchip_rk3399_sdhci_5_1']),
                          get_compat_name(node))
 
         prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third'])
         node = Node({'compatible': prop})
-        self.assertEqual(('rockchip_rk3399_sdhci_5_1',
-                          ['arasan_sdhci_5_1', 'third']),
+        self.assertEqual((['rockchip_rk3399_sdhci_5_1',
+                          'arasan_sdhci_5_1', 'third']),
                          get_compat_name(node))
 
     def test_empty_file(self):
@@ -566,6 +566,9 @@ void dm_populate_phandle_data(void) {
 struct dtd_compat1 {
 \tfdt32_t\t\tintval;
 };
+struct dtd_simple_bus {
+\tfdt32_t\t\tintval;
+};
 #define dtd_compat2_1_fred dtd_compat1
 #define dtd_compat3 dtd_compat1
 ''', data)
@@ -583,6 +586,15 @@ U_BOOT_DEVICE(spl_test) = {
 \t.platdata_size\t= sizeof(dtv_spl_test),
 };
 
+static struct dtd_simple_bus dtv_spl_test2 = {
+\t.intval\t\t\t= 0x1,
+};
+U_BOOT_DEVICE(spl_test2) = {
+\t.name\t\t= "simple_bus",
+\t.platdata\t= &dtv_spl_test2,
+\t.platdata_size\t= sizeof(dtv_spl_test2),
+};
+
 ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
 
     def test_addresses64(self):
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/2 dtoc: remove compatible string aliases support

In reply to Walter Lozano

After latest improvements in dtoc, compatible strings are checked against driver and driver alias list to get a valid driver name. With this new feature the list of compatible string aliases seems not useful any more.

---

 tools/dtoc/dtb_platdata.py | 13 ------------
 tools/dtoc/test_dtoc.py    | 43 --------------------------------------
 2 files changed, 56 deletions(-)
tools/dtoc/dtb_platdata.py +0 -13
index b1b082e508..c28768f4a2 100644
@@ -139,9 +139,6 @@ class DtbPlatdata(object):
         _outfile: The current output file (sys.stdout or a real file)
         _warning_disabled: true to disable warnings about driver names not found
         _lines: Stashed list of output lines for outputting in the future
-        _aliases: Dict that hold aliases for compatible strings
-            key: First compatible string declared in a node
-            value: List of additional compatible strings declared in a node
         _drivers: List of valid driver names found in drivers/
         _driver_aliases: Dict that holds aliases for driver names
             key: Driver alias declared with
@@ -157,7 +154,6 @@ class DtbPlatdata(object):
         self._outfile = None
         self._warning_disabled = warning_disabled
         self._lines = []
-        self._aliases = {}
         self._drivers = []
         self._driver_aliases = {}
         self._links = []
@@ -483,10 +479,6 @@ class DtbPlatdata(object):
                     prop.Widen(struct[name])
             upto += 1
 
-            struct_name, aliases = self.get_normalized_compat_name(node)
-            for alias in aliases:
-                self._aliases[alias] = struct_name
-
         return structs
 
     def scan_phandles(self):
@@ -549,11 +541,6 @@ class DtbPlatdata(object):
                 self.out(';\n')
             self.out('};\n')
 
-        for alias, struct_name in self._aliases.items():
-            if alias not in sorted(structs):
-                self.out('#define %s%s %s%s\n'% (STRUCT_PREFIX, alias,
-                                                 STRUCT_PREFIX, struct_name))
-
     def output_node(self, node):
         """Output the C code for a node
 
tools/dtoc/test_dtoc.py +0 -43

55 lines not on this page · raw message

Signature · 1 line
2.20.1