[U-Boot] [PATCH] spl: add size check including devicetree

Simon Goldschmidt simon.k.r.goldschmidt at gmail.com
Fri Mar 1 21:34:17 UTC 2019


Current linker based size checks do not account for the devicetree,
as this is added after linker stage.

This patch moves the logic behind U-Boot proper BOARD_SIZE_CHECK
into a common function that is called for SPL, too.

For SPL, CONFIG_SPL_MAX_SIZE is used to check u-boot-spl-dtb.bin.

This is RFC for two reasons:
- scripts/Kbuild.include might not be the perfect place for this
  new function but was the only place I found included by both
  /Makefile and /scripts/Makefile.spl
- CONFIG_SPL_MAX_SIZE at least for some boards defines the size
  of the initially available SRAM. However, this check checks the
  SPL binary only. Initial SRAM must hold gd, heap and stack in
  addition to that.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt at gmail.com>
---

 Makefile               | 11 +----------
 scripts/Kbuild.include | 16 ++++++++++++++++
 scripts/Makefile.spl   |  6 ++++++
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index 75a5c7d171..7e1241cf9f 100644
--- a/Makefile
+++ b/Makefile
@@ -771,16 +771,7 @@ LDPPFLAGS += \
 #########################################################################
 
 ifneq ($(CONFIG_BOARD_SIZE_LIMIT),)
-BOARD_SIZE_CHECK = \
-	@actual=`wc -c $@ | awk '{print $$1}'`; \
-	limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \
-	if test $$actual -gt $$limit; then \
-		echo "$@ exceeds file size limit:" >&2 ; \
-		echo "  limit:  $$limit bytes" >&2 ; \
-		echo "  actual: $$actual bytes" >&2 ; \
-		echo "  excess: $$((actual - limit)) bytes" >&2; \
-		exit 1; \
-	fi
+BOARD_SIZE_CHECK = $(call board_size_check,$(CONFIG_BOARD_SIZE_LIMIT))
 else
 BOARD_SIZE_CHECK =
 endif
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index b8969e2a75..e3e0aead3f 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -332,3 +332,19 @@ else
 SPL_ :=
 SPL_TPL_ :=
 endif
+
+# added for U-Boot
+# board size check
+# ---------------------------------------------------------------------------
+# This checks binaries created in makefiles ($@) for size constraints ($(1)).
+define board_size_check
+	@actual=`wc -c $@ | awk '{print $$1}'`; \
+	limit=`printf "%d" $(1)`; \
+	if test $$actual -gt $$limit; then \
+		echo "$@ exceeds file size limit:" >&2 ; \
+		echo "  limit:  $$limit bytes" >&2 ; \
+		echo "  actual: $$actual bytes" >&2 ; \
+		echo "  excess: $$((actual - limit)) bytes" >&2; \
+		exit 1; \
+	fi
+endef
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 9d5921606e..31339ab9e6 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -253,12 +253,18 @@ else
 FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit
 endif
 
+ifneq ($(CONFIG_SPL_MAX_SIZE),)
+SPL_BOARD_SIZE_CHECK = $(call board_size_check,$(CONFIG_SPL_MAX_SIZE))
+else
+SPL_BOARD_SIZE_CHECK =
+endif
 
 ifeq ($(CONFIG_$(SPL_TPL_)OF_CONTROL)$(CONFIG_OF_SEPARATE)$(CONFIG_$(SPL_TPL_)OF_PLATDATA),yy)
 $(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin \
 		$(if $(CONFIG_SPL_SEPARATE_BSS),,$(obj)/$(SPL_BIN)-pad.bin) \
 		$(FINAL_DTB_CONTAINER)  FORCE
 	$(call if_changed,cat)
+	$(SPL_BOARD_SIZE_CHECK)
 
 $(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-dtb.bin FORCE
 	$(call if_changed,copy)
-- 
2.17.1



More information about the U-Boot mailing list