[PATCH 17/35] board_f: Add a new struct to hold pre-relocation info

Simon Glass sjg at chromium.org
Wed Jul 24 17:09:04 CEST 2024


Quite a few of the members of struct global_data are only used before
reloction, or have little meaning afterwards, yet they hang around in
struct global_data for the lifetime of U-Boot. This uses up precious
pre-relocation SRAM on many boards.

To help with this, start a new struct which exists only before
relocation. Move new_fdt into this new struct. Drop the display of it
in the 'bdinfo' command as it is probably not very useful.

Note that the field does not exist in SPL builds.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 cmd/bdinfo.c                      |  1 -
 common/board_f.c                  | 11 +++++++----
 include/asm-generic/global_data.h | 11 +++++++----
 include/board_f.h                 | 23 +++++++++++++++++++++++
 test/cmd/bdinfo.c                 |  2 --
 5 files changed, 37 insertions(+), 11 deletions(-)
 create mode 100644 include/board_f.h

diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index 437ac4e8630..b53b51acca4 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -154,7 +154,6 @@ static int bdinfo_print_all(struct bd_info *bd)
 	if (IS_ENABLED(CONFIG_CMD_NET))
 		print_eth();
 	bdinfo_print_num_l("fdt_blob", (ulong)map_to_sysmem(gd->fdt_blob));
-	bdinfo_print_num_l("new_fdt", (ulong)map_to_sysmem(gd->new_fdt));
 	bdinfo_print_num_l("fdt_size", (ulong)gd->fdt_size);
 	if (IS_ENABLED(CONFIG_VIDEO))
 		show_video_info();
diff --git a/common/board_f.c b/common/board_f.c
index 1935b1dd11b..2125eb5ca50 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -577,7 +577,7 @@ static int reserve_fdt(void)
 			gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob), 32);
 
 			gd->start_addr_sp = reserve_stack_aligned(gd->fdt_size);
-			gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
+			gd->boardf->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
 			debug("Reserving %lu Bytes for FDT at: %08lx\n",
 			      gd->fdt_size, gd->start_addr_sp);
 		}
@@ -667,10 +667,10 @@ static int init_post(void)
 static int reloc_fdt(void)
 {
 	if (!IS_ENABLED(CONFIG_OF_EMBED)) {
-		if (gd->new_fdt) {
-			memcpy(gd->new_fdt, gd->fdt_blob,
+		if (gd->boardf->new_fdt) {
+			memcpy(gd->boardf->new_fdt, gd->fdt_blob,
 			       fdt_totalsize(gd->fdt_blob));
-			gd->fdt_blob = gd->new_fdt;
+			gd->fdt_blob = gd->boardf->new_fdt;
 		}
 	}
 
@@ -1005,8 +1005,11 @@ static const init_fnc_t init_sequence_f[] = {
 
 void board_init_f(ulong boot_flags)
 {
+	struct board_f boardf;
+
 	gd->flags = boot_flags;
 	gd->flags &= ~GD_FLG_HAVE_CONSOLE;
+	gd->boardf = &boardf;
 
 	if (initcall_run_list(init_sequence_f))
 		hang();
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 0904fcf77fc..bd053f77f6c 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -20,6 +20,7 @@
  */
 
 #ifndef __ASSEMBLY__
+#include <board_f.h>
 #include <cyclic.h>
 #include <event_internal.h>
 #include <fdtdec.h>
@@ -41,6 +42,12 @@ struct global_data {
 	 * @bd: board information
 	 */
 	struct bd_info *bd;
+#ifndef CONFIG_SPL_BUILD
+	/**
+	 * @boardf: information only used before relocation
+	 */
+	struct board_f *boardf;
+#endif
 	/**
 	 * @flags: global data flags
 	 *
@@ -218,10 +225,6 @@ struct global_data {
 	 * @fdt_blob: U-Boot's own device tree, NULL if none
 	 */
 	const void *fdt_blob;
-	/**
-	 * @new_fdt: relocated device tree
-	 */
-	void *new_fdt;
 	/**
 	 * @fdt_size: space reserved for relocated device space
 	 */
diff --git a/include/board_f.h b/include/board_f.h
new file mode 100644
index 00000000000..74fca6df75c
--- /dev/null
+++ b/include/board_f.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2024 Google LLC
+ * Written by: Simon Glass <sjg at chromeium.org>
+ */
+
+#ifndef __BOARD_F
+#define __BOARD_F
+
+/**
+ * struct board_f: Information used only before relocation
+ *
+ * This struct is set up in board_init_f() and used to deal with relocation. It
+ * is not available after relocation.
+ */
+struct board_f {
+	/**
+	 * @new_fdt: relocated device tree
+	 */
+	void *new_fdt;
+};
+
+#endif
diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c
index 027848c3e24..60adc4aa960 100644
--- a/test/cmd/bdinfo.c
+++ b/test/cmd/bdinfo.c
@@ -185,8 +185,6 @@ static int bdinfo_test_all(struct unit_test_state *uts)
 	ut_assert(map_to_sysmem(gd->fdt_blob) == env_get_hex("fdtcontroladdr", 0x1234));
 	ut_assertok(test_num_l(uts, "fdt_blob",
 			       (ulong)map_to_sysmem(gd->fdt_blob)));
-	ut_assertok(test_num_l(uts, "new_fdt",
-			       (ulong)map_to_sysmem(gd->new_fdt)));
 	ut_assertok(test_num_l(uts, "fdt_size", (ulong)gd->fdt_size));
 
 	if (IS_ENABLED(CONFIG_VIDEO))
-- 
2.34.1



More information about the U-Boot mailing list