summaryrefslogtreecommitdiffstats
path: root/pbl
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-02-20 13:47:13 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2022-02-23 11:14:45 +0100
commit4c8f76ccf3d15d153893962196d1ff548accddc2 (patch)
treee0c797d2b195606844e7e4ee0a099aaa1c847dc6 /pbl
parent729ad0c2e8c0b1c4af34174338bbd593bd70050d (diff)
downloadbarebox-4c8f76ccf3d15d153893962196d1ff548accddc2.tar.gz
barebox-4c8f76ccf3d15d153893962196d1ff548accddc2.tar.xz
PBL: fdt: factor reg property parsing into helper
Instead of duplicating the loop for each of base and size, move it into a helper function. This may come in handy later when extending the function, e.g. to have the generic-dt-2nd image take /reserved-memory entries into account and not rely on CONFIG_OPTEE_SIZE. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220220124736.3052502-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'pbl')
-rw-r--r--pbl/fdt.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/pbl/fdt.c b/pbl/fdt.c
index 7a913c546a..51719698f2 100644
--- a/pbl/fdt.c
+++ b/pbl/fdt.c
@@ -3,12 +3,24 @@
#include <pbl.h>
#include <linux/printk.h>
+static const __be32 *fdt_parse_reg(const __be32 *reg, uint32_t n,
+ uint64_t *val)
+{
+ int i;
+
+ *val = 0;
+ for (i = 0; i < n; i++)
+ *val = (*val << 32) | fdt32_to_cpu(*reg++);
+
+ return reg;
+}
+
void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsize)
{
const __be32 *nap, *nsp, *reg;
uint32_t na, ns;
uint64_t memsize64, membase64;
- int node, size, i;
+ int node, size;
/* Make sure FDT blob is sane */
if (fdt_check_header(fdt) != 0) {
@@ -51,14 +63,9 @@ void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsiz
goto err;
}
- membase64 = 0;
- for (i = 0; i < na; i++)
- membase64 = (membase64 << 32) | fdt32_to_cpu(*reg++);
-
/* get the memsize and truncate it to under 4G on 32 bit machines */
- memsize64 = 0;
- for (i = 0; i < ns; i++)
- memsize64 = (memsize64 << 32) | fdt32_to_cpu(*reg++);
+ reg = fdt_parse_reg(reg, na, &membase64);
+ reg = fdt_parse_reg(reg, ns, &memsize64);
*membase = membase64;
*memsize = memsize64;