[PATCH 2/5] dtoc: Improve handling of reg properties
Simon Glass
sjg at chromium.org
Mon Mar 22 06:13:08 CET 2021
This existing code assumes that a reg property is larger than one cell,
but this is not always the case. Fix this assumption.
Also if a node's parent is missing the #address-cells and #size-cells
properties we use 2 as a default for each. But this should not happen in
practice. More likely the properties were removed for SPL due to there
being no 'u-boot,dm-pre-reloc' property, or similar. Add a warning for
this as the failure can be very confusing.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
tools/dtoc/dtb_platdata.py | 14 ++++++++++----
tools/dtoc/test_dtoc.py | 2 +-
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 27e88e75173..57a45170a26 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -440,6 +440,9 @@ class DtbPlatdata():
Number of size cells for this node
"""
parent = node.parent
+ if parent and not parent.props:
+ raise ValueError("Parent node '%s' has no properties - do you need u-boot,dm-spl or similar?" %
+ parent.path)
num_addr, num_size = 2, 2
if parent:
addr_prop = parent.props.get('#address-cells')
@@ -467,18 +470,21 @@ class DtbPlatdata():
if reg.type != fdt.Type.INT:
raise ValueError("Node '%s' reg property is not an int" %
node.name)
- if len(reg.value) % total:
+ reg_val = reg.value
+ if not isinstance(reg_val, list):
+ reg_val = [reg_val]
+ if len(reg_val) % total:
raise ValueError(
- "Node '%s' reg property has %d cells "
+ "Node '%s' (parent '%s') reg property has %d cells "
'which is not a multiple of na + ns = %d + %d)' %
- (node.name, len(reg.value), num_addr, num_size))
+ (node.name, node.parent.name, len(reg_val), num_addr, num_size))
reg.num_addr = num_addr
reg.num_size = num_size
if num_addr != 1 or num_size != 1:
reg.type = fdt.Type.INT64
i = 0
new_value = []
- val = reg.value
+ val = reg_val
if not isinstance(val, list):
val = [val]
while i < len(val):
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 62fcab74178..c856ea41681 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -1462,7 +1462,7 @@ U_BOOT_DRVINFO(test3) = {
with self.assertRaises(ValueError) as exc:
self.run_test(['struct'], dtb_file, output)
self.assertIn(
- "Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)",
+ "Node 'spl-test' (parent '/') reg property has 3 cells which is not a multiple of na + ns = 1 + 1)",
str(exc.exception))
def test_add_prop(self):
--
2.31.0.rc2.261.g7f71774620-goog
More information about the U-Boot
mailing list