[PATCH v2 01/25] dtoc: Make GetArgs() more flexible

Simon Glass sjg at chromium.org
Thu Feb 24 00:00:16 CET 2022


At present it is not possible to have arguments whic include spaces.
Update the function to only split the args if the property is a single
string. This is a bit inconsistent, but might still be useful.

Signed-off-by: Simon Glass <sjg at chromium.org>
Suggested-by: Alper Nebi Yasak <alpernebiyasak at gmail.com>
---

Changes in v2:
- Add new patch to make GetArgs() more flexible

 tools/dtoc/fdt_util.py               | 8 ++++++--
 tools/dtoc/test/dtoc_test_simple.dts | 2 ++
 tools/dtoc/test_fdt.py               | 6 +++++-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py
index c82e7747aa..57550624bb 100644
--- a/tools/dtoc/fdt_util.py
+++ b/tools/dtoc/fdt_util.py
@@ -192,8 +192,12 @@ def GetArgs(node, propname):
         value = GetStringList(node, propname)
     else:
         value = []
-    lists = [v.split() for v in value]
-    args = [x for l in lists for x in l]
+    if not value:
+        args = []
+    elif len(value) == 1:
+        args = value[0].split()
+    else:
+        args = value
     return args
 
 def GetBool(node, propname, default=False):
diff --git a/tools/dtoc/test/dtoc_test_simple.dts b/tools/dtoc/test/dtoc_test_simple.dts
index 2d321fb034..aef07efeae 100644
--- a/tools/dtoc/test/dtoc_test_simple.dts
+++ b/tools/dtoc/test/dtoc_test_simple.dts
@@ -63,5 +63,7 @@
 	orig-node {
 		orig = <1 23 4>;
 		args = "-n first", "second", "-p", "123,456", "-x";
+		args2 = "a space", "there";
+		args3 = "-n first second -p 123,456 -x";
 	};
 };
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index 576d65b97e..c2013b9289 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -659,8 +659,12 @@ class TestFdtUtil(unittest.TestCase):
             ['multi-word', 'message'],
             fdt_util.GetArgs(self.node, 'stringarray'))
         self.assertEqual([], fdt_util.GetArgs(self.node, 'boolval'))
-        self.assertEqual(['-n', 'first', 'second', '-p', '123,456', '-x'],
+        self.assertEqual(['-n first', 'second', '-p', '123,456', '-x'],
                          fdt_util.GetArgs(node, 'args'))
+        self.assertEqual(['a space', 'there'],
+                         fdt_util.GetArgs(node, 'args2'))
+        self.assertEqual(['-n', 'first', 'second', '-p', '123,456', '-x'],
+                         fdt_util.GetArgs(node, 'args3'))
         with self.assertRaises(ValueError) as exc:
             fdt_util.GetArgs(self.node, 'missing')
         self.assertIn(
-- 
2.35.1.574.g5d30c73bfb-goog



More information about the U-Boot mailing list