]> git.sur5r.net Git - u-boot/commitdiff
dtoc: Fix properties with a single zero-arg phandle
authorSimon Glass <sjg@chromium.org>
Fri, 6 Jul 2018 16:27:31 +0000 (10:27 -0600)
committerSimon Glass <sjg@chromium.org>
Mon, 9 Jul 2018 15:11:00 +0000 (09:11 -0600)
At present a property with a single phandle looks like an integer value
to dtoc. Correct this by adjusting it in the phandle-processing code.

Add a test for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/dtoc/dtb_platdata.py
tools/dtoc/dtoc_test_phandle.dts
tools/dtoc/test_dtoc.py
tools/dtoc/test_fdt.py

index 2f7302e52958ed46c217fc7c10499f90aa353a0a..b1323aef1982ac5509d9dc30db454e9c7e55ca12 100644 (file)
@@ -211,15 +211,21 @@ class DtbPlatdata(object):
             Number of argument cells is this is a phandle, else None
         """
         if prop.name in ['clocks']:
+            if not isinstance(prop.value, list):
+                prop.value = [prop.value]
             val = prop.value
-            if not isinstance(val, list):
-                val = [val]
             i = 0
 
             max_args = 0
             args = []
             while i < len(val):
                 phandle = fdt_util.fdt32_to_cpu(val[i])
+                # If we get to the end of the list, stop. This can happen
+                # since some nodes have more phandles in the list than others,
+                # but we allocate enough space for the largest list. So those
+                # nodes with shorter lists end up with zeroes at the end.
+                if not phandle:
+                    break
                 target = self._fdt.phandle_to_node.get(phandle)
                 if not target:
                     raise ValueError("Cannot parse '%s' in node '%s'" %
@@ -400,8 +406,6 @@ class DtbPlatdata(object):
                     continue
                 info = self.get_phandle_argc(prop, node.name)
                 if info:
-                    if not isinstance(prop.value, list):
-                        prop.value = [prop.value]
                     # Process the list as pairs of (phandle, id)
                     pos = 0
                     for args in info.args:
index 91dfec5c63fcf9f70c9b934ee26c06f01f313bfb..a71acffc698d3e590dead59a4f36c5e3c580d8c3 100644 (file)
                compatible = "source";
                clocks = <&phandle &phandle_1 11 &phandle_2 12 13 &phandle>;
        };
+
+       phandle-source2 {
+               u-boot,dm-pre-reloc;
+               compatible = "source";
+               clocks = <&phandle>;
+       };
 };
index 20fea522c4fdbe89f85fd07cf9bb4f56e095a336..11cac3fc7afa1388faba2dfe5648558dc2aa4f5e 100644 (file)
@@ -323,6 +323,16 @@ U_BOOT_DEVICE(phandle_source) = {
 \t.platdata_size\t= sizeof(dtv_phandle_source),
 };
 
+static struct dtd_source dtv_phandle_source2 = {
+\t.clocks\t\t\t= {
+\t\t\t{&dtv_phandle_target, {}},},
+};
+U_BOOT_DEVICE(phandle_source2) = {
+\t.name\t\t= "source",
+\t.platdata\t= &dtv_phandle_source2,
+\t.platdata_size\t= sizeof(dtv_phandle_source2),
+};
+
 ''', data)
 
     def test_aliases(self):
index 9fef8ed5496ec0bcae2ab8732eac531d6265623f..49d188b1c124f3f9f97cf2a023e04eac2460b002 100755 (executable)
@@ -210,7 +210,9 @@ class TestProp(unittest.TestCase):
 
     def testPhandle(self):
         dtb = fdt.FdtScan('tools/dtoc/dtoc_test_phandle.dts')
-        node = dtb.GetNode('/phandle-source')
+        node = dtb.GetNode('/phandle-source2')
+        prop = node.props['clocks']
+        self.assertTrue(fdt32_to_cpu(prop.value) > 0)
 
     def _ConvertProp(self, prop_name):
         """Helper function to look up a property in self.node and return it