]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dtoc: Add a way to read a phandle with params
authorSimon Glass <sjg@chromium.org>
Wed, 11 Jan 2023 23:10:18 +0000 (16:10 -0700)
committerSimon Glass <sjg@chromium.org>
Wed, 18 Jan 2023 21:55:41 +0000 (14:55 -0700)
Add a function to read a phandle and associated name and offset. This is
useful for binman.

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

index d7c38ad1e039f655962248997585e89bef0c0eb5..f34316632a749124d7029ea01fd5e394a6795b44 100644 (file)
@@ -281,6 +281,34 @@ def GetPhandleList(node, propname):
         value = [value]
     return [fdt32_to_cpu(v) for v in value]
 
+def GetPhandleNameOffset(node, propname):
+    """Get a <&phandle>, "string", <offset> value from a property
+
+    Args:
+        node: Node object to read from
+        propname: property name to read
+
+    Returns:
+        tuple:
+            Node object
+            str
+            int
+        or None if the property does not exist
+    """
+    prop = node.props.get(propname)
+    if not prop:
+        return None
+    value = prop.bytes
+    phandle = fdt32_to_cpu(value[:4])
+    node = node.GetFdt().LookupPhandle(phandle)
+    name = ''
+    for byte in value[4:]:
+        if not byte:
+            break
+        name += chr(byte)
+    val = fdt32_to_cpu(value[4 + len(name) + 1:])
+    return node, name, val
+
 def GetDatatype(node, propname, datatype):
     """Get a value of a given type from a property
 
index a71acffc698d3e590dead59a4f36c5e3c580d8c3..d9aa433503d7317c94d461ad1a465e604fa2481f 100644 (file)
@@ -32,6 +32,7 @@
                u-boot,dm-pre-reloc;
                compatible = "source";
                clocks = <&phandle &phandle_1 11 &phandle_2 12 13 &phandle>;
+               phandle-name-offset = <&phandle_2>, "fred", <123>;
        };
 
        phandle-source2 {
index 879ca2ab2bfc9b00780f2ee2069c45548d555b3a..c62fcbac83f68f6a696da99b2db37923cb55d129 100755 (executable)
@@ -929,6 +929,7 @@ U_BOOT_DRVINFO(spl_test) = {
         self._check_strings(HEADER + '''
 struct dtd_source {
 \tstruct phandle_2_arg clocks[4];
+\tunsigned char        phandle_name_offset[13];
 };
 struct dtd_target {
 \tfdt32_t\t\tintval;
@@ -981,6 +982,8 @@ static struct dtd_source dtv_phandle_source = {
 \t\t\t{0, {11}},
 \t\t\t{1, {12, 13}},
 \t\t\t{4, {}},},
+\t.phandle_name_offset = {0x0, 0x0, 0x0, 0x3, 0x66, 0x72, 0x65, 0x64,
+\t\t0x0, 0x0, 0x0, 0x0, 0x7b},
 };
 U_BOOT_DRVINFO(phandle_source) = {
 \t.name\t\t= "source",
index a3e36ea363f056c3768f6b9dcd847b104b37b070..3b8ee00d4e0bc947c62604d7c2f7a3a98e254b58 100755 (executable)
@@ -795,6 +795,17 @@ class TestFdtUtil(unittest.TestCase):
         finally:
             tools.outdir= old_outdir
 
+    def test_get_phandle_name_offset(self):
+        val = fdt_util.GetPhandleNameOffset(self.node, 'missing')
+        self.assertIsNone(val)
+
+        dtb = fdt.FdtScan(find_dtb_file('dtoc_test_phandle.dts'))
+        node = dtb.GetNode('/phandle-source')
+        node, name, offset = fdt_util.GetPhandleNameOffset(node,
+                                                           'phandle-name-offset')
+        self.assertEqual('phandle3-target', node.name)
+        self.assertEqual('fred', name)
+        self.assertEqual(123, offset)
 
 def run_test_coverage(build_dir):
     """Run the tests and check that we get 100% coverage