[PATCH v2 4/8] spl: binman: Split binman symbols support from enabling binman

Alper Nebi Yasak alpernebiyasak at gmail.com
Sat Jun 18 14:13:09 CEST 2022


Enabling CONFIG_BINMAN makes binman run after a build to package any
images specified in the device-tree. It also enables a mechanism for
SPL/TPL to declare and use special linker symbols that refer to other
entries in the same binman image. A similar feature that gets this info
from the device-tree exists for U-Boot proper, but it is gated behind a
CONFIG_BINMAN_FDT unlike the symbols.

Confusingly, CONFIG_SPL/TPL_BINMAN_SYMBOLS also exist. These configs
don't actually enable/disable the symbols mechanism as one would expect,
but declare some symbols for U-Boot using this mechanism.

Reuse the BINMAN_SYMBOLS configs to make them toggle the symbols
mechanism, and declare symbols for the U-Boot phases in a dependent
BINMAN_UBOOT_SYMBOLS config. Extend it to cover symbols of all phases.
Update the config prompt and help message to make it clearer about this.
Fix binman test binaries to work with CONFIG_IS_ENABLED(BINMAN_SYMBOLS).

Co-developed-by: Peng Fan <peng.fan at nxp.com>
[Alper: New config for phase symbols, update Kconfigs, commit message]
Signed-off-by: Alper Nebi Yasak <alpernebiyasak at gmail.com>
---
See Peng's patch [1] included in these changes.

[1] binman_sym: guard with CONFIG_IS_ENABLED(BINMAN_SYMBOLS)
https://lore.kernel.org/u-boot/20220603071715.15212-8-peng.fan@oss.nxp.com/

Changes in v2:
- Split binman symbols support from enabling binman
- Move U-Boot phase symbol declarations to BINMAN_UBOOT_SYMBOLS configs
- Merge in Peng's patch for binman_sym.h changes

 common/spl/Kconfig                          | 22 ++++++++++++++-----
 common/spl/Kconfig.tpl                      | 24 +++++++++++++++------
 common/spl/spl.c                            |  9 ++++----
 include/binman_sym.h                        |  6 +++---
 tools/binman/test/Makefile                  |  2 +-
 tools/binman/test/generated/autoconf.h      |  3 +++
 tools/binman/test/u_boot_binman_syms.c      |  2 +-
 tools/binman/test/u_boot_binman_syms_size.c |  2 +-
 8 files changed, 49 insertions(+), 21 deletions(-)
 create mode 100644 tools/binman/test/generated/autoconf.h

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 2ad2351c6eb3..46d9be73bb1f 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -190,12 +190,24 @@ config SPL_BINMAN_SYMBOLS
 	depends on SPL_FRAMEWORK && BINMAN
 	default y
 	help
-	  This enables use of symbols in SPL which refer to U-Boot, enabling SPL
-	  to obtain the location of U-Boot simply by calling spl_get_image_pos()
-	  and spl_get_image_size().
+	  This enables use of symbols in SPL which refer to other entries in
+	  the same binman image as the SPL. These can be declared with the
+	  binman_sym_declare(type, entry, prop) macro and accessed by the
+	  binman_sym(type, entry, prop) macro defined in binman_sym.h.
 
-	  For this to work, you must have a U-Boot image in the binman image, so
-	  binman can update SPL with the location of it.
+	  See tools/binman/binman.rst for a detailed explanation.
+
+config SPL_BINMAN_UBOOT_SYMBOLS
+	bool "Declare binman symbols for U-Boot phases in SPL"
+	depends on SPL_BINMAN_SYMBOLS
+	default y
+	help
+	  This enables use of symbols in SPL which refer to U-Boot phases,
+	  enabling SPL to obtain the location and size of its next phase simply
+	  by calling spl_get_image_pos() and spl_get_image_size().
+
+	  For this to work, you must have all U-Boot phases in the same binman
+	  image, so binman can update SPL with the locations of everything.
 
 source "common/spl/Kconfig.nxp"
 
diff --git a/common/spl/Kconfig.tpl b/common/spl/Kconfig.tpl
index 834cb6b6dd82..8c59c767302f 100644
--- a/common/spl/Kconfig.tpl
+++ b/common/spl/Kconfig.tpl
@@ -9,16 +9,28 @@ config TPL_SIZE_LIMIT
 	  If this value is zero, it is ignored.
 
 config TPL_BINMAN_SYMBOLS
-	bool "Declare binman symbols in TPL"
+	bool "Support binman symbols in TPL"
 	depends on TPL_FRAMEWORK && BINMAN
 	default y
 	help
-	  This enables use of symbols in TPL which refer to U-Boot, enabling TPL
-	  to obtain the location of U-Boot simply by calling spl_get_image_pos()
-	  and spl_get_image_size().
+	  This enables use of symbols in TPL which refer to other entries in
+	  the same binman image as the TPL. These can be declared with the
+	  binman_sym_declare(type, entry, prop) macro and accessed by the
+	  binman_sym(type, entry, prop) macro defined in binman_sym.h.
 
-	  For this to work, you must have a U-Boot image in the binman image, so
-	  binman can update TPL with the location of it.
+	  See tools/binman/binman.rst for a detailed explanation.
+
+config TPL_BINMAN_UBOOT_SYMBOLS
+	bool "Declare binman symbols for U-Boot phases in TPL"
+	depends on TPL_BINMAN_SYMBOLS
+	default y
+	help
+	  This enables use of symbols in TPL which refer to U-Boot phases,
+	  enabling TPL to obtain the location and size of its next phase simply
+	  by calling spl_get_image_pos() and spl_get_image_size().
+
+	  For this to work, you must have all U-Boot phases in the same binman
+	  image, so binman can update TPL with the locations of everything.
 
 config TPL_FRAMEWORK
 	bool "Support TPL based upon the common SPL framework"
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 5630dcdb5c1e..89b875d0e017 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -51,11 +51,10 @@ DECLARE_GLOBAL_DATA_PTR;
 
 u32 *boot_params_ptr = NULL;
 
-#if CONFIG_IS_ENABLED(BINMAN_SYMBOLS)
+#if CONFIG_IS_ENABLED(BINMAN_UBOOT_SYMBOLS)
 /* See spl.h for information about this */
 binman_sym_declare(ulong, u_boot_any, image_pos);
 binman_sym_declare(ulong, u_boot_any, size);
-#endif
 
 #ifdef CONFIG_TPL
 binman_sym_declare(ulong, u_boot_spl, image_pos);
@@ -67,6 +66,8 @@ binman_sym_declare(ulong, u_boot_vpl, image_pos);
 binman_sym_declare(ulong, u_boot_vpl, size);
 #endif
 
+#endif /* BINMAN_UBOOT_SYMBOLS */
+
 /* Define board data structure */
 static struct bd_info bdata __attribute__ ((section(".data")));
 
@@ -151,7 +152,7 @@ void spl_fixup_fdt(void *fdt_blob)
 
 ulong spl_get_image_pos(void)
 {
-	if (!CONFIG_IS_ENABLED(BINMAN_SYMBOLS))
+	if (!CONFIG_IS_ENABLED(BINMAN_UBOOT_SYMBOLS))
 		return BINMAN_SYM_MISSING;
 
 #ifdef CONFIG_VPL
@@ -165,7 +166,7 @@ ulong spl_get_image_pos(void)
 
 ulong spl_get_image_size(void)
 {
-	if (!CONFIG_IS_ENABLED(BINMAN_SYMBOLS))
+	if (!CONFIG_IS_ENABLED(BINMAN_UBOOT_SYMBOLS))
 		return BINMAN_SYM_MISSING;
 
 #ifdef CONFIG_VPL
diff --git a/include/binman_sym.h b/include/binman_sym.h
index 72e6765fe520..8586ef8731b6 100644
--- a/include/binman_sym.h
+++ b/include/binman_sym.h
@@ -13,7 +13,7 @@
 
 #define BINMAN_SYM_MISSING	(-1UL)
 
-#ifdef CONFIG_BINMAN
+#if CONFIG_IS_ENABLED(BINMAN_SYMBOLS)
 
 /**
  * binman_symname() - Internal function to get a binman symbol name
@@ -77,7 +77,7 @@
 #define binman_sym(_type, _entry_name, _prop_name) \
 	(*(_type *)&binman_symname(_entry_name, _prop_name))
 
-#else /* !BINMAN */
+#else /* !CONFIG_IS_ENABLED(BINMAN_SYMBOLS) */
 
 #define binman_sym_declare(_type, _entry_name, _prop_name)
 
@@ -87,6 +87,6 @@
 
 #define binman_sym(_type, _entry_name, _prop_name) BINMAN_SYM_MISSING
 
-#endif /* BINMAN */
+#endif /* CONFIG_IS_ENABLED(BINMAN_SYMBOLS) */
 
 #endif
diff --git a/tools/binman/test/Makefile b/tools/binman/test/Makefile
index 57057e2d588f..bea8567c9b45 100644
--- a/tools/binman/test/Makefile
+++ b/tools/binman/test/Makefile
@@ -21,7 +21,7 @@ CC		= $(CROSS_COMPILE)gcc
 OBJCOPY		= $(CROSS_COMPILE)objcopy
 
 VPATH := $(SRC)
-CFLAGS := -march=i386 -m32 -nostdlib -I $(SRC)../../../include \
+CFLAGS := -march=i386 -m32 -nostdlib -I $(SRC)../../../include -I $(SRC) \
 	-Wl,--no-dynamic-linker
 
 LDS_UCODE := -T $(SRC)u_boot_ucode_ptr.lds
diff --git a/tools/binman/test/generated/autoconf.h b/tools/binman/test/generated/autoconf.h
new file mode 100644
index 000000000000..6a23039f4699
--- /dev/null
+++ b/tools/binman/test/generated/autoconf.h
@@ -0,0 +1,3 @@
+#define CONFIG_BINMAN 1
+#define CONFIG_SPL_BUILD 1
+#define CONFIG_SPL_BINMAN_SYMBOLS 1
diff --git a/tools/binman/test/u_boot_binman_syms.c b/tools/binman/test/u_boot_binman_syms.c
index 37fc339ce84b..89fee5567e1d 100644
--- a/tools/binman/test/u_boot_binman_syms.c
+++ b/tools/binman/test/u_boot_binman_syms.c
@@ -5,7 +5,7 @@
  * Simple program to create some binman symbols. This is used by binman tests.
  */
 
-#define CONFIG_BINMAN
+#include <linux/kconfig.h>
 #include <binman_sym.h>
 
 binman_sym_declare(unsigned long, u_boot_spl_any, offset);
diff --git a/tools/binman/test/u_boot_binman_syms_size.c b/tools/binman/test/u_boot_binman_syms_size.c
index 7224bc1863c7..c4a053f96f1a 100644
--- a/tools/binman/test/u_boot_binman_syms_size.c
+++ b/tools/binman/test/u_boot_binman_syms_size.c
@@ -5,7 +5,7 @@
  * Simple program to create some binman symbols. This is used by binman tests.
  */
 
-#define CONFIG_BINMAN
+#include <linux/kconfig.h>
 #include <binman_sym.h>
 
 binman_sym_declare(char, u_boot_spl, pos);
-- 
2.36.1



More information about the U-Boot mailing list