ar71xx: image: fix size verification in the CatFiles macro
authorGabor Juhos <juhosg@openwrt.org>
Fri, 24 Jan 2014 11:59:32 +0000 (11:59 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Fri, 24 Jan 2014 11:59:32 +0000 (11:59 +0000)
The macro checks the size of the rootfs image even if
the second parameter of the macro contains the size of
an eraseblock. It is wrong because the size of the
kernel image will be adjusted to the next eraseblock
and the resulting image might be too large.

Fix the macro to check the size of the final image
instead of the rootfs image.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
SVN-Revision: 39383

target/linux/ar71xx/image/Makefile

index 2a003a82b3c80431c5b3b5d8da8d7e79e823bedb..39e935d11b77b5bac96c08e4af7f90fa8ab09a1b 100644 (file)
@@ -141,13 +141,21 @@ define CatFiles
                        echo "Warning: $(5) is too big (> $(4) bytes)" >&2; \
                        rm -f $(5); \
                fi; \
-       else if [ $(2) -gt 262144 -a `stat -c%s "$(1)"` -gt $(2) ]; then \
-               echo "Warning: $(1) is too big (> $(2) bytes)" >&2; \
-       else if [ `stat -c%s $(3)` -gt $(4) ]; then \
-               echo "Warning: $(3) is too big (> $(4) bytes)" >&2; \
+       else if [ $(2) -gt 262144 ]; then \
+               if [ `stat -c%s "$(1)"` -gt $(2) ]; then \
+                       echo "Warning: $(1) is too big (> $(2) bytes)" >&2; \
+               else if [ `stat -c%s $(3)` -gt $(4) ]; then \
+                       echo "Warning: $(3) is too big (> $(4) bytes)" >&2; \
+               else \
+                       ( dd if=$(1) bs=$(2) conv=sync; dd if=$(3) ) > $(5); \
+               fi; fi; \
        else \
                ( dd if=$(1) bs=$(2) conv=sync; dd if=$(3) ) > $(5); \
-       fi; fi; fi
+               if [ `stat -c%s $(5)` -gt $(4) ]; then \
+                       echo "Warning: $(5) is too big (> $(4) bytes)" >&2; \
+                       rm -f $(5); \
+               fi; \
+       fi; fi
 endef
 
 Sysupgrade/KR=$(call CatFiles,$(2),$(3),$(KDIR)/root.$(1),$(4),$(call sysupname,$(1),$(5)))