]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dtoc: Support adding a string list to a device tree
authorSimon Glass <sjg@chromium.org>
Tue, 8 Feb 2022 18:49:50 +0000 (11:49 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 22 Feb 2022 17:05:44 +0000 (10:05 -0700)
Add a new function to add a string list.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/dtoc/fdt.py
tools/dtoc/test_fdt.py

index 7e13757a1be9ac2043a18bb773b618ce168c2092..026f7a273f9e97615914c721170f804810206a87 100644 (file)
@@ -501,6 +501,24 @@ class Node:
         val = bytes(val, 'utf-8')
         return self.AddData(prop_name, val + b'\0')
 
+    def AddStringList(self, prop_name, val):
+        """Add a new string-list property to a node
+
+        The device tree is marked dirty so that the value will be written to
+        the blob on the next sync.
+
+        Args:
+            prop_name: Name of property to add
+            val (list of str): List of strings to add
+
+        Returns:
+            Prop added
+        """
+        out = b''
+        for string in val:
+            out += bytes(string, 'utf-8') + b'\0'
+        return self.AddData(prop_name, out)
+
     def AddInt(self, prop_name, val):
         """Add a new integer property to a node
 
index c789822afae0d01ffaf576fae57f16af1f6ea6f1..5a5333b1342a5417f53287d4a584bda5a7a793b2 100755 (executable)
@@ -531,6 +531,14 @@ class TestProp(unittest.TestCase):
         self.node.AddData('data', tools.get_bytes(65, 20000))
         self.dtb.Sync(auto_resize=True)
 
+    def test_string_list(self):
+        """Test adding string-list property to a node"""
+        val = ['123', '456']
+        self.node.AddStringList('stringlist', val)
+        self.dtb.Sync(auto_resize=True)
+        data = self.fdt.getprop(self.node.Offset(), 'stringlist')
+        self.assertEqual(b'123\x00456\0', data)
+
     def testFromData(self):
         dtb2 = fdt.Fdt.FromData(self.dtb.GetContents())
         self.assertEqual(dtb2.GetContents(), self.dtb.GetContents())