dts: edtlib: Improve error for wrong reg/ranges/interrupts size
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 https://github.com/zephyrproject-rtos/zephyr/issues/21607 (though it seems the comment disappeared). Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This commit is contained in:
parent
7a3f7e02d2
commit
57b2d2749c
1 changed files with 18 additions and 6 deletions
|
@ -1157,7 +1157,9 @@ class Node:
|
|||
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)
|
||||
|
@ -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:]
|
||||
|
||||
|
@ -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 []
|
||||
|
||||
|
@ -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)]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue