Skip to content
Permalink
Browse files

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>
  • Loading branch information...
pabigot authored and galak committed Jul 8, 2019
1 parent 99e8710 commit 79765b8ad71426f5b1bd34d3225c0a7f9fc85080
Showing with 15 additions and 3 deletions.
  1. +4 −0 dts/bindings/device_node.yaml.template
  2. +1 −1 scripts/dts/devicetree.py
  3. +10 −2 scripts/dts/extract/default.py
@@ -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 @@ def extract(self, node_path, prop, prop_type, def_label):
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

0 comments on commit 79765b8

Please sign in to comment.
You can’t perform that action at this time.