From: Philip Oberfichtner <pro@denx.de>
To: u-boot@lists.denx.de
Cc: Philip Oberfichtner <pro@denx.de>,
Andre Przywara <andre.przywara@arm.com>,
Anshul Dalal <anshuld@ti.com>,
Dario Binacchi <dario.binacchi@amarulasolutions.com>,
Greg Malysa <malysagreg@gmail.com>,
Heinrich Schuchardt <heinrich.schuchardt@canonical.com>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Jerome Forissier <jerome.forissier@linaro.org>,
Marek Vasut <marek.vasut@mailbox.org>,
Nathan Barrett-Morrison <nathan.morrison@timesys.com>,
Peng Fan <peng.fan@nxp.com>, Simon Glass <sjg@chromium.org>,
Tom Rini <trini@konsulko.com>,
Trevor Woerner <twoerner@gmail.com>, Ye Li <ye.li@nxp.com>
Subject: [PATCH v4 3/3] Image size checks: Deduplicate Makefile
Date: Wed, 15 Oct 2025 03:23:20 +0200 [thread overview]
Message-ID: <20251015012320.2331007-4-pro@denx.de> (raw)
In-Reply-To: <20251015012320.2331007-1-pro@denx.de>
Deduplicate some redundancies within the SIZE_CHECK code in the toplevel
Makefile. No functional changes.
Signed-off-by: Philip Oberfichtner <pro@denx.de>
---
Notes:
Changes in v4:
- Pass CONFIG_HAS_XXX_SIZE_LIMIT as an argument to size_check()
Makefile | 48 +++++++++++++-----------------------------------
1 file changed, 13 insertions(+), 35 deletions(-)
diff --git a/Makefile b/Makefile
index e68dce2c1d5..7b19610335f 100644
--- a/Makefile
+++ b/Makefile
@@ -428,10 +428,12 @@ KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
# Check ths size of a binary:
# Args:
# $1: File to check
-# #2: Size limit in bytes (decimal or 0xhex)
+# $2: Always return OK if this is not "y".
+# $3: Size limit in bytes (decimal or 0xhex)
define size_check
+ test "$2" = "y" || exit 0; \
actual=$$( wc -c $1 | awk '{print $$1}'); \
- limit=$$( printf "%d" $2 ); \
+ limit=$$( printf "%d" $3 ); \
if test $$actual -gt $$limit; then \
echo "$1 exceeds file size limit:" >&2; \
echo " limit: $$(printf %#x $$limit) bytes" >&2; \
@@ -1103,30 +1105,6 @@ LDPPFLAGS += \
#########################################################################
#########################################################################
-ifneq ($(CONFIG_BOARD_SIZE_LIMIT),)
-BOARD_SIZE_CHECK= @ $(call size_check,$@,$(CONFIG_BOARD_SIZE_LIMIT))
-else
-BOARD_SIZE_CHECK =
-endif
-
-ifneq ($(CONFIG_SPL_SIZE_LIMIT),)
-SPL_SIZE_CHECK = @$(call size_check,$@,$$(tools/spl_size_limit))
-else
-SPL_SIZE_CHECK =
-endif
-
-ifneq ($(CONFIG_TPL_SIZE_LIMIT),)
-TPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_TPL_SIZE_LIMIT))
-else
-TPL_SIZE_CHECK =
-endif
-
-ifneq ($(CONFIG_VPL_SIZE_LIMIT),)
-VPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_VPL_SIZE_LIMIT))
-else
-VPL_SIZE_CHECK =
-endif
-
# Statically apply RELA-style relocations (currently arm64 only)
# This is useful for arm64 where static relocation needs to be performed on
# the raw binary, but certain simulators only accept an ELF file (but don't
@@ -1470,7 +1448,7 @@ endif
%.imx: $(IMX_DEPS) %.bin
$(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
- $(BOARD_SIZE_CHECK)
+ @$(call size_check,$@,$(CONFIG_HAS_BOARD_SIZE_LIMIT),$(CONFIG_BOARD_SIZE_LIMIT))
%.vyb: %.imx
$(Q)$(MAKE) $(build)=arch/arm/cpu/armv7/vf610 $@
@@ -1571,11 +1549,11 @@ endif
u-boot-nodtb.bin: u-boot FORCE
$(call if_changed,objcopy_uboot)
- $(BOARD_SIZE_CHECK)
+ @$(call size_check,$@,$(CONFIG_HAS_BOARD_SIZE_LIMIT),$(CONFIG_BOARD_SIZE_LIMIT))
u-boot.ldr: u-boot
$(LDR) -T $(CONFIG_LDR_CPU) -c $@ $< $(LDR_FLAGS)
- $(BOARD_SIZE_CHECK)
+ @$(call size_check,$@,$(CONFIG_HAS_BOARD_SIZE_LIMIT),$(CONFIG_BOARD_SIZE_LIMIT))
# binman
# ---------------------------------------------------------------------------
@@ -1702,7 +1680,7 @@ u-boot-dtb.img u-boot.img u-boot.kwb u-boot.pbl u-boot-ivt.img: \
$(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SANDBOX),dts/dt.dtb) \
,$(UBOOT_BIN)) FORCE
$(call if_changed,mkimage)
- $(BOARD_SIZE_CHECK)
+ @$(call size_check,$@,$(CONFIG_HAS_BOARD_SIZE_LIMIT),$(CONFIG_BOARD_SIZE_LIMIT))
ifeq ($(CONFIG_SPL_LOAD_FIT_FULL),y)
MKIMAGEFLAGS_u-boot.itb =
@@ -1717,12 +1695,12 @@ u-boot.itb: u-boot-nodtb.bin \
$(if $(CONFIG_MULTI_DTB_FIT),$(FINAL_DTB_CONTAINER)) \
$(U_BOOT_ITS) FORCE
$(call if_changed,mkfitimage)
- $(BOARD_SIZE_CHECK)
+ @$(call size_check,$@,$(CONFIG_HAS_BOARD_SIZE_LIMIT),$(CONFIG_BOARD_SIZE_LIMIT))
endif
u-boot-with-spl.kwb: u-boot.bin spl/u-boot-spl.bin FORCE
$(call if_changed,mkimage)
- $(BOARD_SIZE_CHECK)
+ @$(call size_check,$@,$(CONFIG_HAS_BOARD_SIZE_LIMIT),$(CONFIG_BOARD_SIZE_LIMIT))
u-boot.dis: u-boot
$(OBJDUMP) -d $< > $@
@@ -2346,7 +2324,7 @@ u-boot.lds: $(LDSCRIPT) prepare FORCE
spl/u-boot-spl.bin: spl/u-boot-spl
@:
- $(SPL_SIZE_CHECK)
+ @$(call size_check,$@,$(CONFIG_HAS_SPL_SIZE_LIMIT),$$(tools/spl_size_limit))
spl/u-boot-spl-dtb.bin: spl/u-boot-spl
@:
@@ -2371,14 +2349,14 @@ spl/boot.bin: spl/u-boot-spl
tpl/u-boot-tpl.bin: tpl/u-boot-tpl
@:
- $(TPL_SIZE_CHECK)
+ @$(call size_check,$@,$(CONFIG_HAS_TPL_SIZE_LIMIT),$(CONFIG_TPL_SIZE_LIMIT))
tpl/u-boot-tpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.xpl all
vpl/u-boot-vpl.bin: vpl/u-boot-vpl
@:
- $(VPL_SIZE_CHECK)
+ @$(call size_check,$@,$(CONFIG_HAS_VPL_SIZE_LIMIT),$(CONFIG_VPL_SIZE_LIMIT))
vpl/u-boot-vpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
$(Q)$(MAKE) obj=vpl -f $(srctree)/scripts/Makefile.xpl all
--
2.39.5
next prev parent reply other threads:[~2025-10-15 1:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 1:23 [PATCH v4 0/3] Harmonize image size checks Philip Oberfichtner
2025-10-15 1:23 ` [PATCH v4 1/3] Image size checks: Use HAS_SIZE_LIMIT consistently Philip Oberfichtner
2025-11-09 18:41 ` Marek Vasut
2025-11-10 7:46 ` Philip Oberfichtner
2025-10-15 1:23 ` [PATCH v4 2/3] Image size checks: Clarify help texts Philip Oberfichtner
2025-11-09 18:55 ` Marek Vasut
2025-10-15 1:23 ` Philip Oberfichtner [this message]
2025-11-09 19:00 ` [PATCH v4 3/3] Image size checks: Deduplicate Makefile Marek Vasut
2025-11-04 11:28 ` [PATCH v4 0/3] Harmonize image size checks Philip Oberfichtner
2025-11-04 11:56 ` Marek Vasut
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251015012320.2331007-4-pro@denx.de \
--to=pro@denx.de \
--cc=andre.przywara@arm.com \
--cc=anshuld@ti.com \
--cc=dario.binacchi@amarulasolutions.com \
--cc=heinrich.schuchardt@canonical.com \
--cc=ilias.apalodimas@linaro.org \
--cc=jerome.forissier@linaro.org \
--cc=malysagreg@gmail.com \
--cc=marek.vasut@mailbox.org \
--cc=nathan.morrison@timesys.com \
--cc=peng.fan@nxp.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=twoerner@gmail.com \
--cc=u-boot@lists.denx.de \
--cc=ye.li@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.