Skip to content

Commit

Permalink
dts: edtlib: Improve error for wrong reg/ranges/interrupts size
Browse files Browse the repository at this point in the history
Show how the element size was calculated in the error message when a
'reg', 'ranges', or 'interrupts' property has the wrong size. This
should help with debugging. Also mention that #*-cells properties come
from the parent node, which can be subtle.

Came up in #21607
(though it seems the comment disappeared).

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
  • Loading branch information
ulfalizer authored and carlescufi committed Jan 13, 2020
1 parent 7a3f7e0 commit 57b2d27
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions scripts/dts/edtlib.py
Expand Up @@ -1157,7 +1157,9 @@ def _init_regs(self):
address_cells = _address_cells(node)
size_cells = _size_cells(node)

for raw_reg in _slice(node, "reg", 4*(address_cells + size_cells)):
for raw_reg in _slice(node, "reg", 4*(address_cells + size_cells),
"4*(<#address-cells> (= {}) + <#size-cells> (= {}))"
.format(address_cells, size_cells)):
reg = Register()
reg.node = self
reg.addr = _translate(to_num(raw_reg[:4*address_cells]), node)
Expand Down Expand Up @@ -1735,7 +1737,12 @@ def _translate(addr, node):
# Number of cells for one translation 3-tuple in 'ranges'
entry_cells = child_address_cells + parent_address_cells + child_size_cells

for raw_range in _slice(node.parent, "ranges", 4*entry_cells):
for raw_range in _slice(node.parent, "ranges", 4*entry_cells,
"4*(<#address-cells> (= {}) + "
"<#address-cells for parent> (= {}) + "
"<#size-cells> (= {}))"
.format(child_address_cells, parent_address_cells,
child_size_cells)):
child_addr = to_num(raw_range[:4*child_address_cells])
raw_range = raw_range[4*child_address_cells:]

Expand Down Expand Up @@ -1815,7 +1822,8 @@ def _interrupts(node):
interrupt_cells = _interrupt_cells(iparent)

return [_map_interrupt(node, iparent, raw)
for raw in _slice(node, "interrupts", 4*interrupt_cells)]
for raw in _slice(node, "interrupts", 4*interrupt_cells,
"4*<#interrupt-cells>")]

return []

Expand Down Expand Up @@ -2104,15 +2112,19 @@ def _interrupt_cells(node):
return node.props["#interrupt-cells"].to_num()


def _slice(node, prop_name, size):
def _slice(node, prop_name, size, size_hint):
# Splits node.props[prop_name].value into 'size'-sized chunks, returning a
# list of chunks. Raises EDTError if the length of the property is not
# evenly divisible by 'size'.
# evenly divisible by 'size'. 'size_hint' is a string shown on errors that
# gives a hint on how 'size' was calculated.

raw = node.props[prop_name].value
if len(raw) % size:
_err("'{}' property in {!r} has length {}, which is not evenly "
"divisible by {}".format(prop_name, node, len(raw), size))
"divisible by {} (= {}). Note that #*-cells "
"properties come either from the parent node or from the "
"controller (in the case of 'interrupts')."
.format(prop_name, node, len(raw), size, size_hint))

return [raw[i:i + size] for i in range(0, len(raw), size)]

Expand Down

0 comments on commit 57b2d27

Please sign in to comment.