diff options
author | Simon Glass | 2022-02-08 11:49:53 -0700 |
---|---|---|
committer | Simon Glass | 2022-02-22 10:05:44 -0700 |
commit | 7e4b66aa8743aca134883d0ebc42535ce43ecf25 (patch) | |
tree | faaab66a3d2a9c78335b929e24dc8b39101974f8 | |
parent | dd857ee7614fea27de3eb6dbd87749a9640c69b1 (diff) |
dtoc: Support reading a list of arguments
It is helpful to support a string or stringlist containing a list of
space-separated arguments, for example:
args = "-n fred", "-a", "123";
This resolves to the list:
-n fred -a 123
which can be passed to a program as arguments.
Add a helper to do the required processing.
Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | tools/dtoc/fdt_util.py | 12 | ||||
-rw-r--r-- | tools/dtoc/test/dtoc_test_simple.dts | 1 | ||||
-rwxr-xr-x | tools/dtoc/test_fdt.py | 15 |
3 files changed, 28 insertions, 0 deletions
diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py index d59ea2fe62a..c82e7747aa3 100644 --- a/tools/dtoc/fdt_util.py +++ b/tools/dtoc/fdt_util.py @@ -184,6 +184,18 @@ def GetStringList(node, propname, default=None): return [strval] return value +def GetArgs(node, propname): + prop = node.props.get(propname) + if not prop: + raise ValueError(f"Node '{node.path}': Expected property '{propname}'") + if prop.bytes: + value = GetStringList(node, propname) + else: + value = [] + lists = [v.split() for v in value] + args = [x for l in lists for x in l] + return args + def GetBool(node, propname, default=False): """Get an boolean from a property diff --git a/tools/dtoc/test/dtoc_test_simple.dts b/tools/dtoc/test/dtoc_test_simple.dts index 4c2c70af222..2d321fb0345 100644 --- a/tools/dtoc/test/dtoc_test_simple.dts +++ b/tools/dtoc/test/dtoc_test_simple.dts @@ -62,5 +62,6 @@ orig-node { orig = <1 23 4>; + args = "-n first", "second", "-p", "123,456", "-x"; }; }; diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index 5455759acf0..576d65b97e8 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -652,6 +652,21 @@ class TestFdtUtil(unittest.TestCase): self.assertEqual(['test'], fdt_util.GetStringList(self.node, 'missing', ['test'])) + def testGetArgs(self): + node = self.dtb.GetNode('/orig-node') + self.assertEqual(['message'], fdt_util.GetArgs(self.node, 'stringval')) + self.assertEqual( + ['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'], + fdt_util.GetArgs(node, 'args')) + with self.assertRaises(ValueError) as exc: + fdt_util.GetArgs(self.node, 'missing') + self.assertIn( + "Node '/spl-test': Expected property 'missing'", + str(exc.exception)) + def testGetBool(self): self.assertEqual(True, fdt_util.GetBool(self.node, 'boolval')) self.assertEqual(False, fdt_util.GetBool(self.node, 'missing')) |