]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
spl: add overall SPL size check
authorSimon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Fri, 24 May 2019 20:07:04 +0000 (22:07 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 7 Jun 2019 15:03:39 +0000 (11:03 -0400)
This adds a size check for SPL that can dynamically check generated
SPL binaries (including devicetree) for a size limit that ensures
this image plus global data, heap and stack fit in initial SRAM.

Since some of these sizes are not available to make, a new host tool
'spl_size_limit' is added that dumps the resulting maximum size for
an SPL binary to stdout. This tool is used in toplevel Makefile to
implement the size check on SPL binaries.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Kconfig
Makefile
common/spl/Kconfig
tools/Makefile
tools/spl_size_limit.c [new file with mode: 0644]

diff --git a/Kconfig b/Kconfig
index 709912e1340129db922ea414a0653f332b397bbb..a02168690f5b19e060ccfe9b3e7751b38bd71fe4 100644 (file)
--- a/Kconfig
+++ b/Kconfig
@@ -173,14 +173,6 @@ config TPL_SYS_MALLOC_F_LEN
          particular needs this to operate, so that it can allocate the
          initial serial device and any others that are needed.
 
-config SPL_SIZE_LIMIT
-       int "Maximum size of SPL image"
-       depends on SPL
-       default 0
-       help
-         Specifies the maximum length of the U-Boot SPL image.
-         If this value is zero, it is ignored.
-
 menuconfig EXPERT
        bool "Configure standard U-Boot features (expert users)"
        default y
index da8a38da63c2cc40c6cced3f93d51e760f53d763..8de3d4120aff8c5e5db6d996c66a9c7abed4d874 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -797,7 +797,7 @@ BOARD_SIZE_CHECK =
 endif
 
 ifneq ($(CONFIG_SPL_SIZE_LIMIT),0)
-SPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_SPL_SIZE_LIMIT))
+SPL_SIZE_CHECK = @$(call size_check,$@,$$(tools/spl_size_limit))
 else
 SPL_SIZE_CHECK =
 endif
@@ -1782,6 +1782,7 @@ checkarmreloc: u-boot
 envtools: scripts_basic $(version_h) $(timestamp_h)
        $(Q)$(MAKE) $(build)=tools/env
 
+tools-only: export TOOLS_ONLY=y
 tools-only: scripts_basic $(version_h) $(timestamp_h)
        $(Q)$(MAKE) $(build)=tools
 
index c7cd34449a525fc0bec0300e589023c3460b476b..6a98536f2083d2eecf8da75287497e1e701f4430 100644 (file)
@@ -25,6 +25,42 @@ config SPL_FRAMEWORK
          supports MMC, NAND and YMODEM and other methods loading of U-Boot
          and the Linux Kernel.  If unsure, say Y.
 
+config SPL_SIZE_LIMIT
+       hex "Maximum size of SPL image"
+       depends on SPL
+       default 0
+       help
+         Specifies the maximum length of the U-Boot SPL image.
+         If this value is zero, it is ignored.
+
+config SPL_SIZE_LIMIT_SUBTRACT_GD
+       bool "SPL image size check: provide space for global data"
+       depends on SPL_SIZE_LIMIT > 0
+       help
+         If enabled, aligned size of global data is reserved in
+         SPL_SIZE_LIMIT check to ensure such an image does not overflow SRAM
+         if SPL_SIZE_LIMIT describes the size of SRAM available for SPL when
+         pre-reloc global data is put into this SRAM, too.
+
+config SPL_SIZE_LIMIT_SUBTRACT_MALLOC
+       bool "SPL image size check: provide space for malloc() pool before relocation"
+       depends on SPL_SIZE_LIMIT > 0
+       help
+         If enabled, SPL_SYS_MALLOC_F_LEN is reserved in SPL_SIZE_LIMIT check
+         to ensure such an image does not overflow SRAM if SPL_SIZE_LIMIT
+         describes the size of SRAM available for SPL when pre-reloc malloc
+         pool is put into this SRAM, too.
+
+config SPL_SIZE_LIMIT_PROVIDE_STACK
+       hex "SPL image size check: provide stack space before relocation"
+       depends on SPL_SIZE_LIMIT > 0
+       default 0
+       help
+         If set, this size is reserved in SPL_SIZE_LIMIT check to ensure such
+         an image does not overflow SRAM if SPL_SIZE_LIMIT describes the size
+         of SRAM available for SPL when the stack required before reolcation
+         uses this SRAM, too.
+
 config HANDOFF
        bool "Pass hand-off information from SPL to U-Boot proper"
        depends on BLOBLIST
index e2f572cae1b478cb72fa73effab35b54e7a02de1..33e90a8025a738945c4906e3ea725e8db9381dc3 100644 (file)
@@ -199,6 +199,10 @@ hostprogs-$(CONFIG_RISCV) += prelink-riscv
 hostprogs-y += fdtgrep
 fdtgrep-objs += $(LIBFDT_OBJS) fdtgrep.o
 
+ifneq ($(TOOLS_ONLY),y)
+hostprogs-y += spl_size_limit
+endif
+
 hostprogs-$(CONFIG_MIPS) += mips-relocs
 
 # We build some files with extra pedantic flags to try to minimize things
diff --git a/tools/spl_size_limit.c b/tools/spl_size_limit.c
new file mode 100644 (file)
index 0000000..98ff491
--- /dev/null
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2019, Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
+ *
+ * This tool helps to return the size available for SPL image during build
+ */
+
+#include <generated/autoconf.h>
+#include <generated/generic-asm-offsets.h>
+
+int main(int argc, char *argv[])
+{
+       int spl_size_limit = 0;
+
+#ifdef CONFIG_SPL_SIZE_LIMIT
+       spl_size_limit = CONFIG_SPL_SIZE_LIMIT;
+#ifdef CONFIG_SPL_SIZE_LIMIT_SUBTRACT_GD
+       spl_size_limit -= GENERATED_GBL_DATA_SIZE;
+#endif
+#ifdef CONFIG_SPL_SIZE_LIMIT_SUBTRACT_MALLOC
+       spl_size_limit -= CONFIG_SPL_SYS_MALLOC_F_LEN;
+#endif
+#ifdef CONFIG_SPL_SIZE_LIMIT_PROVIDE_STACK
+       spl_size_limit -= CONFIG_SPL_SIZE_LIMIT_PROVIDE_STACK;
+#endif
+#endif
+
+       printf("%d", spl_size_limit);
+       return 0;
+}