[U-Boot] [PATCH] Enable expression support for CONFIG_BOARD_SIZE_LIMIT
Wolfgang Denk
wd at denx.de
Tue Dec 4 15:40:35 UTC 2018
So far, the use of CONFIG_BOARD_SIZE_LIMIT would only work with
plain numeric constants. Extend it to allow for expressions, so one
can for example use
#define CONFIG_BOARD_SIZE_LIMIT (768 << 10)
in the board configuration.
Signed-off-by: Wolfgang Denk <wd at denx.de>
Cc: Fabio Estevam <festevam at gmail.com>
Cc: Stefano Babic <sbabic at denx.de>
Cc: Vanessa Maegima <vanessa.maegima at nxp.com>
Cc: Otavio Salvador <otavio at ossystems.com.br>
Cc: John Weber <john.weber at technexion.com>
Cc: Stefan Roese <sr at denx.de>
---
Note 1: As gawk lacks an eval function, we use bash's $((...))
mechanism to evaluate the expression. This has the
additional benefit that it supports expressions like "<<"
which awk does not understand. OK, one could replace awk by
something better...
Note 2: This patch focusses on enabling this new feature. It does
not addres another issue that should be solved in a lter
commit: the duplication of the same code in Makefile and
arch/arm/mach-imx/Makefile
Makefile | 17 ++++++++---------
arch/arm/mach-imx/Makefile | 17 ++++++++---------
2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
index 0d11ff9797..d4c8f697cf 100644
--- a/Makefile
+++ b/Makefile
@@ -774,15 +774,14 @@ 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
+ @(echo $$(($(CONFIG_BOARD_SIZE_LIMIT))); wc -c $@ ) | \
+ awk 'BEGIN { getline limit } \
+ { if ($$1 > limit) { \
+ printf "%s exceeds file size limit:\n", $$2; \
+ printf " limit: %d bytes\n", limit; \
+ printf " actual: %d bytes\n", $$1; \
+ printf " excess: %d bytes\n", $$1 - limit; \
+ exit 1; } }'
else
BOARD_SIZE_CHECK =
endif
diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 53d9e5f42b..230a5c73aa 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -60,15 +60,14 @@ endif
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
+ @(echo $$(($(CONFIG_BOARD_SIZE_LIMIT))); wc -c $@ ) | \
+ awk 'BEGIN { getline limit } \
+ { if ($$1 > limit) { \
+ printf "%s exceeds file size limit:\n", $$2; \
+ printf " limit: %d bytes\n", limit; \
+ printf " actual: %d bytes\n", $$1; \
+ printf " excess: %d bytes\n", $$1 - limit; \
+ exit 1; } }'
else
BOARD_SIZE_CHECK =
endif
--
2.19.1
More information about the U-Boot
mailing list