public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits
@ 2010-10-14  2:58 Mike Frysinger
  2010-10-18 20:43 ` Wolfgang Denk
  2010-10-19 21:29 ` Wolfgang Denk
  0 siblings, 2 replies; 10+ messages in thread
From: Mike Frysinger @ 2010-10-14  2:58 UTC (permalink / raw)
  To: u-boot

Boards often have a reserved size limit on the flash where they're stored.
Sometimes during upgrades or config changes, those limits are exceeded,
but no one notices until they try to upgrade and the limit screws things
up.  Either not enough of U-Boot is written to flash (and so the reboot
fails), or too much is written (and so things after it get clobbered).

So allow boards to declare a size limit (in bytes) and have the build
system check it while building.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 Makefile |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index de4ceb9..ca12d78 100644
--- a/Makefile
+++ b/Makefile
@@ -304,6 +304,21 @@ __LIBS := $(subst $(obj),,$(LIBS)) $(subst $(obj),,$(LIBBOARD))
 #########################################################################
 #########################################################################
 
+ifneq ($(CONFIG_BOARD_SIZE_LIMIT),)
+BOARD_SIZE_CHECK = \
+	@actual=`wc -c $@ | awk '{print $$1}'`; \
+	limit=$(CONFIG_BOARD_SIZE_LIMIT); \
+	if test $$actual -gt $$limit; then \
+		echo "$@ exceeds file size limit:"; \
+		echo "  limit:  $$limit bytes"; \
+		echo "  actual: $$actual bytes"; \
+		echo "  excess: $$((actual - limit)) bytes"; \
+		exit 1; \
+	fi
+else
+BOARD_SIZE_CHECK =
+endif
+
 # Always append ALL so that arch config.mk's can add custom ones
 ALL += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND) $(U_BOOT_ONENAND)
 
@@ -317,10 +332,12 @@ $(obj)u-boot.srec:	$(obj)u-boot
 
 $(obj)u-boot.bin:	$(obj)u-boot
 		$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
+		$(BOARD_SIZE_CHECK)
 
 $(obj)u-boot.ldr:	$(obj)u-boot
 		$(CREATE_LDR_ENV)
 		$(LDR) -T $(CONFIG_BFIN_CPU) -c $@ $< $(LDR_FLAGS)
+		$(BOARD_SIZE_CHECK)
 
 $(obj)u-boot.ldr.hex:	$(obj)u-boot.ldr
 		$(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@ -I binary
-- 
1.7.3.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-10-20  7:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-14  2:58 [U-Boot] [RFC/PATCH] Makefile: allow boards to check file size limits Mike Frysinger
2010-10-18 20:43 ` Wolfgang Denk
2010-10-19  4:17   ` Mike Frysinger
2010-10-19  5:24     ` Wolfgang Denk
2010-10-19  5:38       ` Mike Frysinger
2010-10-19 21:29 ` Wolfgang Denk
2010-10-20  4:38   ` Vaibhav Bedia
2010-10-20  5:16     ` Mike Frysinger
2010-10-20  6:56       ` Vaibhav Bedia
2010-10-20  7:19         ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox