diff mbox series

[2/2] build: image: return sizes if check-size fails

Message ID 20200729190012.31535-2-freifunk@adrianschmutzler.de
State Accepted
Delegated to: Adrian Schmutzler
Headers show
Series [1/2] build: image: drop unused check-kernel-size recipe | expand

Commit Message

Adrian Schmutzler July 29, 2020, 7 p.m. UTC
Instead of just printing a warning that an image is too big, also
print both actual size and limit in the string:

WARNING: Image file somename.bin is too big: 2096101 > 1048576

Since the kernel size is checked via the same function (if
KERNEL_SIZE is specified), this will also apply to the kernel
image size check.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
---
 include/image-commands.mk | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Paul Spooren July 29, 2020, 7:04 p.m. UTC | #1
Is there an easy way to test this? As in, how do I force the Kernel to 
be to big?

On 29.07.20 09:00, Adrian Schmutzler wrote:
> Instead of just printing a warning that an image is too big, also
> print both actual size and limit in the string:
>
> WARNING: Image file somename.bin is too big: 2096101 > 1048576
>
> Since the kernel size is checked via the same function (if
> KERNEL_SIZE is specified), this will also apply to the kernel
> image size check.
>
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> ---
>   include/image-commands.mk | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/include/image-commands.mk b/include/image-commands.mk
> index 97a66dce30..811edba994 100644
> --- a/include/image-commands.mk
> +++ b/include/image-commands.mk
> @@ -269,8 +269,10 @@ define Build/xor-image
>   endef
>   
>   define Build/check-size
> -	@[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE)))))) -ge "$$(stat -c%s $@)" ] || { \
> -		echo "WARNING: Image file $@ is too big" >&2; \
> +	@imagesize="$$(stat -c%s $@)"; \
> +	limitsize="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
> +	[ $$limitsize -ge $$imagesize ] || { \
> +		echo "WARNING: Image file $@ is too big: $$imagesize > $$limitsize" >&2; \
>   		rm -f $@; \
>   	}
>   endef
Adrian Schmutzler July 29, 2020, 7:06 p.m. UTC | #2
> -----Original Message-----
> From: Paul Spooren [mailto:mail@aparcar.org]
> Sent: Mittwoch, 29. Juli 2020 21:05
> To: Adrian Schmutzler <freifunk@adrianschmutzler.de>; openwrt-
> devel@lists.openwrt.org
> Subject: Re: [PATCH 2/2] build: image: return sizes if check-size fails
> 
> Is there an easy way to test this? As in, how do I force the Kernel to be to
> big?

Just pick a device and set KERNEL_SIZE to a smaller value than what the kernel image gets, e.g. 1024k.

Same can be done with IMAGE_SIZE to check explizit use of check-size in image/Makefile...

Best

Adrian
diff mbox series

Patch

diff --git a/include/image-commands.mk b/include/image-commands.mk
index 97a66dce30..811edba994 100644
--- a/include/image-commands.mk
+++ b/include/image-commands.mk
@@ -269,8 +269,10 @@  define Build/xor-image
 endef
 
 define Build/check-size
-	@[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE)))))) -ge "$$(stat -c%s $@)" ] || { \
-		echo "WARNING: Image file $@ is too big" >&2; \
+	@imagesize="$$(stat -c%s $@)"; \
+	limitsize="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
+	[ $$limitsize -ge $$imagesize ] || { \
+		echo "WARNING: Image file $@ is too big: $$imagesize > $$limitsize" >&2; \
 		rm -f $@; \
 	}
 endef