scripts/dts: fix support for uint8-array property values
uint8-array is the name for what the devicetree specification calls a bytestring. The original parsing code treated square brackets as equivalent to quotes or angle brackets, failing to interpret elements as hex-encoded. This was a bug, corrected in this patch by processing content as a sequence of hex-encoded bytes with arbitrary whitespace. The original generating code emitted the property as individual elements. Replace that with generation of a single structure initializer, which is more useful in cases where the length of a property value may vary between nodes. Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
parent
99e8710a50
commit
79765b8ad7
|
@ -47,6 +47,10 @@ properties:
|
|||
# The exact value of the 'generation' attribute is ignored otherwise. The
|
||||
# output is always #define's.
|
||||
#
|
||||
# Note that uint8-array is the name for what devicetree standard calls
|
||||
# bytestring: its value is hexadecimal text with whitespace ignored,
|
||||
# enclosed in square brackets.
|
||||
#
|
||||
# The 'type' attribute is currently ignored.
|
||||
|
||||
# At a minimum, an entry for the 'compatible' property is required, for
|
||||
|
|
|
@ -114,7 +114,7 @@ def parse_value(value):
|
|||
if value[0] == '"':
|
||||
return parse_values(value, '"', '"', ',')
|
||||
if value[0] == '[':
|
||||
return parse_values(value, '[', ']', ' ')
|
||||
return list(bytes.fromhex(value[1:value.find(']')]))
|
||||
|
||||
if value[0] == '&':
|
||||
return {'ref': value[1:]}
|
||||
|
|
|
@ -46,10 +46,18 @@ class DTDefault(DTDirective):
|
|||
else:
|
||||
prop_values = reduced[node_path]['props'][prop]
|
||||
|
||||
if prop_type == "string-array" or prop_type == "array":
|
||||
if prop_type == "string-array" or prop_type == "array" or prop_type == "uint8-array":
|
||||
if type(prop_values) is not list: prop_values = [ prop_values, ]
|
||||
|
||||
if isinstance(prop_values, list):
|
||||
if prop_type == "uint8-array":
|
||||
prop_name = str_to_label(prop)
|
||||
label = def_label + '_' + prop_name
|
||||
prop_value = ''.join(['{ ',
|
||||
', '.join(["0x%02x" % b for b in prop_values]),
|
||||
' }'])
|
||||
prop_def[label] = prop_value
|
||||
add_compat_alias(node_path, prop_name, label, prop_alias)
|
||||
elif isinstance(prop_values, list):
|
||||
for i, prop_value in enumerate(prop_values):
|
||||
prop_name = str_to_label(prop)
|
||||
label = def_label + '_' + prop_name
|
||||
|
|
Loading…
Reference in a new issue