dtoc: Add support for reading string-list properties
Add a function to read a list of strings from the devicetree. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -163,6 +163,27 @@ def GetString(node, propname, default=None):
|
|||||||
"a single string" % (node.name, propname))
|
"a single string" % (node.name, propname))
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def GetStringList(node, propname, default=None):
|
||||||
|
"""Get a string list from a property
|
||||||
|
|
||||||
|
Args:
|
||||||
|
node (Node): Node object to read from
|
||||||
|
propname (str): property name to read
|
||||||
|
default (list of str): Default value to use if the node/property do not
|
||||||
|
exist, or None
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
String value read, or default if none
|
||||||
|
"""
|
||||||
|
prop = node.props.get(propname)
|
||||||
|
if not prop:
|
||||||
|
return default
|
||||||
|
value = prop.value
|
||||||
|
if not isinstance(value, list):
|
||||||
|
strval = GetString(node, propname)
|
||||||
|
return [strval]
|
||||||
|
return value
|
||||||
|
|
||||||
def GetBool(node, propname, default=False):
|
def GetBool(node, propname, default=False):
|
||||||
"""Get an boolean from a property
|
"""Get an boolean from a property
|
||||||
|
|
||||||
|
@@ -615,6 +615,15 @@ class TestFdtUtil(unittest.TestCase):
|
|||||||
self.assertIn("property 'stringarray' has list value: expecting a "
|
self.assertIn("property 'stringarray' has list value: expecting a "
|
||||||
'single string', str(e.exception))
|
'single string', str(e.exception))
|
||||||
|
|
||||||
|
def testGetStringList(self):
|
||||||
|
self.assertEqual(['message'],
|
||||||
|
fdt_util.GetStringList(self.node, 'stringval'))
|
||||||
|
self.assertEqual(
|
||||||
|
['multi-word', 'message'],
|
||||||
|
fdt_util.GetStringList(self.node, 'stringarray'))
|
||||||
|
self.assertEqual(['test'],
|
||||||
|
fdt_util.GetStringList(self.node, 'missing', ['test']))
|
||||||
|
|
||||||
def testGetBool(self):
|
def testGetBool(self):
|
||||||
self.assertEqual(True, fdt_util.GetBool(self.node, 'boolval'))
|
self.assertEqual(True, fdt_util.GetBool(self.node, 'boolval'))
|
||||||
self.assertEqual(False, fdt_util.GetBool(self.node, 'missing'))
|
self.assertEqual(False, fdt_util.GetBool(self.node, 'missing'))
|
||||||
|
Reference in New Issue
Block a user