[PATCH 2/4] bootm: print memreserve map in verbose mode

Sascha Hauer s.hauer at pengutronix.de
Thu Oct 19 04:27:25 PDT 2023


There currently is no way to print the /memreserve/ map barebox boots
the kernel with. As this contains useful debugging information sometimes
print it along with the device tree when booting with -vv.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/bootm.c   |  4 +++-
 drivers/of/fdt.c | 23 +++++++++++++++++++++++
 include/of.h     |  1 +
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/common/bootm.c b/common/bootm.c
index 2469d43441..29ea13e28c 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -468,8 +468,10 @@ int bootm_load_devicetree(struct image_data *data, void *fdt,
 	memcpy((void *)data->oftree_res->start, fdt, fdt_size);
 
 	of_print_cmdline(data->of_root_node);
-	if (bootm_verbose(data) > 1)
+	if (bootm_verbose(data) > 1) {
 		of_print_nodes(data->of_root_node, 0, ~0);
+		fdt_print_reserve_map(fdt);
+	}
 
 	return 0;
 }
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 734dbfc92a..223abe9375 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -585,3 +585,26 @@ void fdt_add_reserve_map(void *__fdt)
 	of_write_number(&fdt_res->address, 0, 2);
 	of_write_number(&fdt_res->size, 0, 2);
 }
+
+void fdt_print_reserve_map(const void *__fdt)
+{
+	const struct fdt_header *fdt = __fdt;
+	const struct fdt_reserve_entry *fdt_res =
+		__fdt + be32_to_cpu(fdt->off_mem_rsvmap);
+	int n = 0;
+
+	while (1) {
+		uint64_t size = fdt64_to_cpu(fdt_res->size);
+		uint64_t address = fdt64_to_cpu(fdt_res->address);
+
+		if (!size)
+			break;
+
+		printf("/memreserve/ #%d: 0x%08llx - 0x%08llx\n", n, address, address + size - 1);
+
+		n++;
+		fdt_res++;
+		if (n == OF_MAX_RESERVE_MAP)
+			return;
+	}
+}
diff --git a/include/of.h b/include/of.h
index a7a1ce125f..5686709fcf 100644
--- a/include/of.h
+++ b/include/of.h
@@ -61,6 +61,7 @@ struct of_reserve_map {
 int of_add_reserve_entry(resource_size_t start, resource_size_t end);
 void of_clean_reserve_map(void);
 void fdt_add_reserve_map(void *fdt);
+void fdt_print_reserve_map(const void *fdt);
 
 struct device;
 struct driver;
-- 
2.39.2




More information about the barebox mailing list