[PATCH 4/9] PBL: fdt: refactor helper for reading nr of cells
Michael Tretter
m.tretter at pengutronix.de
Mon May 26 07:38:10 PDT 2025
Since libfdt now contains fdt_addresses, the fdt_find_mem function can
use the already existing helpers to read #size-cells and #address-cells.
Signed-off-by: Michael Tretter <m.tretter at pengutronix.de>
---
pbl/fdt.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/pbl/fdt.c b/pbl/fdt.c
index 8e4d1295074a6b8dc4ad07ad2ada5882148c9ce6..3b1783152a8cb81f3eda1187b2f7bf998c4addf4 100644
--- a/pbl/fdt.c
+++ b/pbl/fdt.c
@@ -17,8 +17,8 @@ static const __be32 *fdt_parse_reg(const __be32 *reg, uint32_t n,
void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsize)
{
- const __be32 *nap, *nsp, *reg;
- uint32_t na, ns;
+ const __be32 *reg;
+ int na, ns;
uint64_t memsize64, membase64;
int node, size;
@@ -28,26 +28,23 @@ void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsiz
goto err;
}
- /* Find the #address-cells and #size-cells properties */
node = fdt_path_offset(fdt, "/");
if (node < 0) {
pr_err("Cannot find root node\n");
goto err;
}
- nap = fdt_getprop(fdt, node, "#address-cells", &size);
- if (!nap || (size != 4)) {
+ na = fdt_address_cells(fdt, node);
+ if (na < 0) {
pr_err("Cannot find #address-cells property");
goto err;
}
- na = fdt32_to_cpu(*nap);
- nsp = fdt_getprop(fdt, node, "#size-cells", &size);
- if (!nsp || (size != 4)) {
+ ns = fdt_size_cells(fdt, node);
+ if (ns < 0) {
pr_err("Cannot find #size-cells property");
goto err;
}
- ns = fdt32_to_cpu(*nsp);
/* Find the memory range */
node = fdt_node_offset_by_prop_value(fdt, -1, "device_type",
--
2.39.5
More information about the barebox
mailing list