diff mbox series

treewide: call check-size before append-metadata

Message ID 20210620165641.63731-1-freifunk@adrianschmutzler.de
State Accepted
Delegated to: Adrian Schmutzler
Headers show
Series treewide: call check-size before append-metadata | expand

Commit Message

Adrian Schmutzler June 20, 2021, 4:56 p.m. UTC
sysupgrade metadata is not flashed to the device, so check-size
should be called _before_ adding metadata to the image.

While at it, do some obvious wrapping improvements.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
---
 target/linux/ath79/image/Makefile           |  2 +-
 target/linux/ath79/image/common-mikrotik.mk |  2 +-
 target/linux/ath79/image/common-netgear.mk  | 10 +++---
 target/linux/ath79/image/common-tp-link.mk  |  5 ++-
 target/linux/ath79/image/generic-tp-link.mk |  2 +-
 target/linux/ath79/image/generic-ubnt.mk    |  4 +--
 target/linux/ath79/image/generic.mk         | 36 +++++++++------------
 target/linux/ath79/image/nand.mk            |  3 +-
 target/linux/ath79/image/tiny.mk            |  3 +-
 target/linux/ipq40xx/image/generic.mk       |  8 ++---
 target/linux/ipq40xx/image/mikrotik.mk      |  2 +-
 target/linux/ipq806x/image/Makefile         |  2 +-
 target/linux/lantiq/image/Makefile          |  4 +--
 target/linux/lantiq/image/ar9.mk            |  6 ++--
 target/linux/lantiq/image/tp-link.mk        |  2 +-
 target/linux/lantiq/image/vr9.mk            |  2 +-
 target/linux/ramips/image/Makefile          |  6 ++--
 target/linux/ramips/image/common-tp-link.mk | 10 +++---
 target/linux/ramips/image/mt7620.mk         | 10 +++---
 target/linux/ramips/image/mt7621.mk         | 10 +++---
 target/linux/ramips/image/rt305x.mk         |  6 ++--
 target/linux/ramips/image/rt3883.mk         |  2 +-
 target/linux/realtek/image/Makefile         |  2 +-
 23 files changed, 64 insertions(+), 75 deletions(-)

Comments

Paul Spooren June 20, 2021, 9:19 p.m. UTC | #1
On 6/20/21 6:56 AM, Adrian Schmutzler wrote:
> sysupgrade metadata is not flashed to the device, so check-size
> should be called _before_ adding metadata to the image.
>
> While at it, do some obvious wrapping improvements.
>
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> ---

Acked-by: Paul Spooren <mail@aparcar.org>

I'm wondering if the size is somewhere checked on devices, meaning a 
sysupgrade is refused because the "total" size (incl. metadata) is 
bigger than what the image would allow. In that case something like 
`stat` shouldn't be used for the file size but e.g. another field in the 
metadata?

>   target/linux/ath79/image/Makefile           |  2 +-
>   target/linux/ath79/image/common-mikrotik.mk |  2 +-
>   target/linux/ath79/image/common-netgear.mk  | 10 +++---
>   target/linux/ath79/image/common-tp-link.mk  |  5 ++-
>   target/linux/ath79/image/generic-tp-link.mk |  2 +-
>   target/linux/ath79/image/generic-ubnt.mk    |  4 +--
>   target/linux/ath79/image/generic.mk         | 36 +++++++++------------
>   target/linux/ath79/image/nand.mk            |  3 +-
>   target/linux/ath79/image/tiny.mk            |  3 +-
>   target/linux/ipq40xx/image/generic.mk       |  8 ++---
>   target/linux/ipq40xx/image/mikrotik.mk      |  2 +-
>   target/linux/ipq806x/image/Makefile         |  2 +-
>   target/linux/lantiq/image/Makefile          |  4 +--
>   target/linux/lantiq/image/ar9.mk            |  6 ++--
>   target/linux/lantiq/image/tp-link.mk        |  2 +-
>   target/linux/lantiq/image/vr9.mk            |  2 +-
>   target/linux/ramips/image/Makefile          |  6 ++--
>   target/linux/ramips/image/common-tp-link.mk | 10 +++---
>   target/linux/ramips/image/mt7620.mk         | 10 +++---
>   target/linux/ramips/image/mt7621.mk         | 10 +++---
>   target/linux/ramips/image/rt305x.mk         |  6 ++--
>   target/linux/ramips/image/rt3883.mk         |  2 +-
>   target/linux/realtek/image/Makefile         |  2 +-
>   23 files changed, 64 insertions(+), 75 deletions(-)
>
> diff --git a/target/linux/ath79/image/Makefile b/target/linux/ath79/image/Makefile
> index aa8665fbb2..aee4ddf963 100644
> --- a/target/linux/ath79/image/Makefile
> +++ b/target/linux/ath79/image/Makefile
> @@ -81,7 +81,7 @@ define Device/Default
>     COMPILE :=
>     IMAGES := sysupgrade.bin
>     IMAGE/sysupgrade.bin = append-kernel | pad-to $$$$(BLOCKSIZE) | \
> -	append-rootfs | pad-rootfs | append-metadata | check-size
> +	append-rootfs | pad-rootfs | check-size | append-metadata
>   endef
>   
>   include $(SUBTARGET).mk
> diff --git a/target/linux/ath79/image/common-mikrotik.mk b/target/linux/ath79/image/common-mikrotik.mk
> index 6e739f2d85..5f5fa7899a 100644
> --- a/target/linux/ath79/image/common-mikrotik.mk
> +++ b/target/linux/ath79/image/common-mikrotik.mk
> @@ -9,7 +9,7 @@ define Device/mikrotik_nor
>     $(Device/mikrotik)
>     IMAGE/sysupgrade.bin := append-kernel | kernel2minor -s 1024 -e | \
>   	pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>   endef
>   
>   define Device/mikrotik_nand
> diff --git a/target/linux/ath79/image/common-netgear.mk b/target/linux/ath79/image/common-netgear.mk
> index 8a74fdc0c9..5a61caf1f6 100644
> --- a/target/linux/ath79/image/common-netgear.mk
> +++ b/target/linux/ath79/image/common-netgear.mk
> @@ -32,10 +32,8 @@ define Device/netgear_generic
>     KERNEL := kernel-bin | append-dtb | lzma -d20 | uImage lzma
>     KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma -d20 | uImage lzma
>     IMAGES += factory.img
> -  IMAGE/default := append-kernel | pad-to $$$$(BLOCKSIZE) | netgear-squashfs | \
> -	append-rootfs | pad-rootfs
> -  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
> -	check-size
> -  IMAGE/factory.img := $$(IMAGE/default) | netgear-dni | \
> -	check-size
> +  IMAGE/default := append-kernel | pad-to $$$$(BLOCKSIZE) | \
> +	netgear-squashfs | append-rootfs | pad-rootfs
> +  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
> +  IMAGE/factory.img := $$(IMAGE/default) | netgear-dni | check-size
>   endef
> diff --git a/target/linux/ath79/image/common-tp-link.mk b/target/linux/ath79/image/common-tp-link.mk
> index 0b7b0e1935..f1d5614aa7 100644
> --- a/target/linux/ath79/image/common-tp-link.mk
> +++ b/target/linux/ath79/image/common-tp-link.mk
> @@ -22,8 +22,7 @@ define Device/tplink-v2
>     TPLINK_HVERSION := 3
>     KERNEL := kernel-bin | append-dtb | lzma
>     KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | tplink-v2-header
> -  IMAGE/sysupgrade.bin := tplink-v2-image -s | append-metadata | \
> -	check-size
> +  IMAGE/sysupgrade.bin := tplink-v2-image -s | check-size | append-metadata
>   endef
>   
>   define Device/tplink-nolzma
> @@ -74,7 +73,7 @@ define Device/tplink-safeloader
>     KERNEL := kernel-bin | append-dtb | lzma | tplink-v1-header -O
>     KERNEL_INITRAMFS := $$(KERNEL)
>     IMAGE/sysupgrade.bin := append-rootfs | tplink-safeloader sysupgrade | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     IMAGE/factory.bin := append-rootfs | tplink-safeloader factory
>   endef
>   
> diff --git a/target/linux/ath79/image/generic-tp-link.mk b/target/linux/ath79/image/generic-tp-link.mk
> index 8b228a73d2..99fe86f592 100644
> --- a/target/linux/ath79/image/generic-tp-link.mk
> +++ b/target/linux/ath79/image/generic-tp-link.mk
> @@ -692,7 +692,7 @@ define Device/tplink_tl-wr2543-v1
>     DEVICE_PACKAGES := kmod-usb2 kmod-usb-ledtrig-usbport
>     TPLINK_HWID := 0x25430001
>     IMAGE/sysupgrade.bin := tplink-v1-image sysupgrade -v 3.13.99 | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     IMAGE/factory.bin := tplink-v1-image factory -v 3.13.99
>     SUPPORTED_DEVICES += tl-wr2543n
>   endef
> diff --git a/target/linux/ath79/image/generic-ubnt.mk b/target/linux/ath79/image/generic-ubnt.mk
> index f8e1d1e432..29a1a710e4 100644
> --- a/target/linux/ath79/image/generic-ubnt.mk
> +++ b/target/linux/ath79/image/generic-ubnt.mk
> @@ -128,7 +128,7 @@ define Device/ubnt-unifi-jffs2
>     KERNEL := kernel-bin | append-dtb | lzma | uImage lzma | jffs2 kernel0
>     IMAGES := sysupgrade.bin factory.bin
>     IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-rootfs |\
> -	pad-rootfs | append-metadata | check-size
> +	pad-rootfs | check-size | append-metadata
>     IMAGE/factory.bin := $$(IMAGE/sysupgrade.bin) | mkubntimage2
>   endef
>   
> @@ -365,7 +365,7 @@ define Device/ubnt_routerstation_common
>     IMAGE/factory.bin := append-rootfs | pad-rootfs | mkubntimage | \
>   	check-size
>     IMAGE/sysupgrade.bin := append-rootfs | pad-rootfs | combined-image | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     KERNEL := kernel-bin | append-dtb | lzma | pad-to $$(BLOCKSIZE)
>     KERNEL_INITRAMFS := kernel-bin | append-dtb
>   endef
> diff --git a/target/linux/ath79/image/generic.mk b/target/linux/ath79/image/generic.mk
> index 9d0be2b86b..f4d266838e 100644
> --- a/target/linux/ath79/image/generic.mk
> +++ b/target/linux/ath79/image/generic.mk
> @@ -163,7 +163,7 @@ define Device/seama
>     # - 36 bytes of META data (4-bytes aligned)
>     IMAGE/default := append-kernel | pad-offset $$$$(BLOCKSIZE) 64 | append-rootfs
>     IMAGE/sysupgrade.bin := $$(IMAGE/default) | seama | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     IMAGE/factory.bin := $$(IMAGE/default) | pad-rootfs -x 64 | seama | \
>   	seama-seal | check-size
>     SEAMA_SIGNATURE :=
> @@ -327,7 +327,7 @@ define Device/avm
>     KERNEL_INITRAMFS := $$(KERNEL)
>     IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | \
>   	append-squashfs-fakeroot-be | pad-to 256 | append-rootfs | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_PACKAGES := fritz-tffs
>   endef
>   
> @@ -768,7 +768,7 @@ define Device/dlink_dap-2xxx
>     IMAGE/factory.img := append-kernel | pad-offset 6144k 160 | \
>   	append-rootfs | wrgg-pad-rootfs | mkwrggimg | check-size
>     IMAGE/sysupgrade.bin := append-kernel | mkwrggimg | \
> -	pad-to $$$$(BLOCKSIZE) | append-rootfs | append-metadata | check-size
> +	pad-to $$$$(BLOCKSIZE) | append-rootfs | check-size | append-metadata
>     KERNEL := kernel-bin | append-dtb | relocate-kernel | lzma
>     KERNEL_INITRAMFS := $$(KERNEL) | mkwrggimg
>   endef
> @@ -820,7 +820,7 @@ define Device/dlink_dap-2695-a1
>     IMAGE/factory.img := $$(IMAGE/default) | append-rootfs | wrgg-pad-rootfs | \
>   	mkwrggimg | check-size
>     IMAGE/sysupgrade.bin := $$(IMAGE/default) | mkwrggimg | append-rootfs | \
> -	wrgg-pad-rootfs | append-metadata |  check-size
> +	wrgg-pad-rootfs | check-size | append-metadata
>     KERNEL := kernel-bin | append-dtb | relocate-kernel | lzma
>     KERNEL_INITRAMFS := $$(KERNEL) | mkwrggimg
>     DAP_SIGNATURE := wapac02_dkbs_dap2695
> @@ -882,7 +882,7 @@ define Device/dlink_dir-825-b1
>     DEVICE_VARIANT := B1
>     IMAGE_SIZE := 6208k
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_PACKAGES := kmod-usb-ohci kmod-usb2 kmod-usb-ledtrig-usbport \
>   	kmod-leds-reset kmod-owl-loader
>     SUPPORTED_DEVICES += dir-825-b1
> @@ -903,8 +903,7 @@ define Device/dlink_dir-825-c1
>   	pad-rootfs
>     IMAGE/factory.bin := $$(IMAGE/default) | pad-offset $$$$(IMAGE_SIZE) 26 | \
>   	append-string 00DB120AR9344-RT-101214-00 | check-size
> -  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
> -	check-size
> +  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
>   endef
>   TARGET_DEVICES += dlink_dir-825-c1
>   
> @@ -921,8 +920,7 @@ define Device/dlink_dir-835-a1
>   	pad-rootfs
>     IMAGE/factory.bin := $$(IMAGE/default) | pad-offset $$$$(IMAGE_SIZE) 26 | \
>   	append-string 00DB120AR9344-RT-101214-00 | check-size
> -  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
> -	check-size
> +  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
>   endef
>   TARGET_DEVICES += dlink_dir-835-a1
>   
> @@ -941,7 +939,7 @@ define Device/dlink_dir-842-c
>     IMAGE/default := append-kernel | uImage lzma | \
>   	pad-offset $$$$(BLOCKSIZE) 64 | append-rootfs
>     IMAGE/sysupgrade.bin := $$(IMAGE/default) | seama | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     IMAGE/factory.bin := $$(IMAGE/default) | pad-rootfs -x 64 | seama | \
>   	seama-seal | check-size
>     IMAGE_SIZE := 15680k
> @@ -1354,7 +1352,7 @@ define Device/jjplus_ja76pf2
>     IMAGE/kernel.bin := append-kernel
>     IMAGE/rootfs.bin := append-rootfs | pad-rootfs
>     IMAGE/sysupgrade.bin := append-rootfs | pad-rootfs | combined-image | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     KERNEL := kernel-bin | append-dtb | lzma | pad-to $$(BLOCKSIZE)
>     KERNEL_INITRAMFS := kernel-bin | append-dtb
>     IMAGE_SIZE := 16000k
> @@ -1421,7 +1419,7 @@ define Device/nec_wx1200cr
>     DEVICE_VENDOR := NEC
>     IMAGE/default := append-kernel | pad-offset $$$$(BLOCKSIZE) 64 | append-rootfs
>     IMAGE/sysupgrade.bin := $$(IMAGE/default) | seama | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_PACKAGES := kmod-ath10k-ct ath10k-firmware-qca9888-ct
>   endef
>   
> @@ -1473,10 +1471,8 @@ define Device/netgear_ex6400_ex7300
>     IMAGE_SIZE := 15552k
>     IMAGE/default := append-kernel | pad-offset $$$$(BLOCKSIZE) 64 | \
>   	netgear-rootfs | pad-rootfs
> -  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
> -	check-size
> -  IMAGE/factory.img := $$(IMAGE/default) | netgear-dni | \
> -	check-size
> +  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
> +  IMAGE/factory.img := $$(IMAGE/default) | netgear-dni | check-size
>     DEVICE_PACKAGES := kmod-ath10k-ct ath10k-firmware-qca99x0-ct
>   endef
>   
> @@ -1859,7 +1855,7 @@ define Device/phicomm_k2t
>     DEVICE_MODEL := K2T
>     IMAGE_SIZE := 15744k
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_PACKAGES := kmod-leds-reset kmod-ath10k-ct-smallbuffers ath10k-firmware-qca9888-ct
>   endef
>   TARGET_DEVICES += phicomm_k2t
> @@ -2199,8 +2195,7 @@ define Device/teltonika_rut955
>   	pad-rootfs | teltonika-fw-fake-checksum | append-string master |\
>   	append-md5sum-bin | check-size
>     IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) |\
> -	append-rootfs | pad-rootfs | append-metadata |\
> -	check-size
> +	append-rootfs | pad-rootfs | check-size | append-metadata
>   endef
>   TARGET_DEVICES += teltonika_rut955
>   
> @@ -2223,8 +2218,7 @@ define Device/trendnet_tew-823dru
>   	pad-rootfs
>     IMAGE/factory.bin := $$(IMAGE/default) | pad-offset $$$$(IMAGE_SIZE) 26 | \
>   	append-string 00AP135AR9558-RT-131129-00 | check-size
> -  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
> -	check-size
> +  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
>   endef
>   TARGET_DEVICES += trendnet_tew-823dru
>   
> diff --git a/target/linux/ath79/image/nand.mk b/target/linux/ath79/image/nand.mk
> index caaa01c92d..20cb2f60fa 100644
> --- a/target/linux/ath79/image/nand.mk
> +++ b/target/linux/ath79/image/nand.mk
> @@ -166,8 +166,7 @@ define Device/netgear_ath79_nand
>     IMAGES := sysupgrade.bin factory.img
>     IMAGE/factory.img := append-kernel | append-ubi | netgear-dni | \
>   	check-size
> -  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata | \
> -	check-size
> +  IMAGE/sysupgrade.bin := sysupgrade-tar | check-size | append-metadata
>     UBINIZE_OPTS := -E 5
>   endef
>   
> diff --git a/target/linux/ath79/image/tiny.mk b/target/linux/ath79/image/tiny.mk
> index 29e411c058..f4a03e2840 100644
> --- a/target/linux/ath79/image/tiny.mk
> +++ b/target/linux/ath79/image/tiny.mk
> @@ -21,8 +21,7 @@ define Device/dlink_dir-615-e4
>     FACTORY_IMAGE_SIZE := 3456k
>     IMAGES += factory.bin
>     IMAGE/default := append-kernel | append-rootfs | pad-rootfs
> -  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
> -	check-size
> +  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
>     IMAGE/factory.bin := $$(IMAGE/default) | \
>   	check-size $$$$(FACTORY_IMAGE_SIZE) | pad-to $$$$(FACTORY_IMAGE_SIZE) | \
>   	append-string "AP99-AR7240-RT-091105-05"
> diff --git a/target/linux/ipq40xx/image/generic.mk b/target/linux/ipq40xx/image/generic.mk
> index 68e565594d..9dee742eb4 100644
> --- a/target/linux/ipq40xx/image/generic.mk
> +++ b/target/linux/ipq40xx/image/generic.mk
> @@ -35,7 +35,7 @@ define Device/DniImage
>   	IMAGES += factory.img
>   	IMAGE/factory.img := append-kernel | pad-offset 64k 64 | append-uImage-fakehdr filesystem | append-rootfs | pad-rootfs | netgear-dni
>   	IMAGE/sysupgrade.bin := append-kernel | pad-offset 64k 64 | append-uImage-fakehdr filesystem | \
> -		append-rootfs | pad-rootfs | append-metadata | check-size
> +		append-rootfs | pad-rootfs | check-size | append-metadata
>   endef
>   
>   define Build/append-rootfshdr
> @@ -106,7 +106,7 @@ define Device/8dev_habanero-dvk
>   	IMAGE_SIZE := 30976k
>   	SOC := qcom-ipq4019
>   	DEVICE_PACKAGES := ipq-wifi-8dev_habanero-dvk
> -	IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-rootfs | pad-rootfs | append-metadata | check-size
> +	IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-rootfs | pad-rootfs | check-size | append-metadata
>   endef
>   TARGET_DEVICES += 8dev_habanero-dvk
>   
> @@ -207,7 +207,7 @@ define Device/avm_fritzbox-4040
>   	UBOOT_PARTITION_SIZE := 524288
>   	IMAGES += eva.bin
>   	IMAGE/eva.bin := append-uboot | pad-to $$$$(UBOOT_PARTITION_SIZE) | append-kernel | append-rootfs | pad-rootfs
> -	IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
> +	IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size | append-metadata
>   	DEVICE_PACKAGES := fritz-tffs fritz-caldata
>   endef
>   TARGET_DEVICES += avm_fritzbox-4040
> @@ -822,7 +822,7 @@ define Device/zyxel_wre6606
>   	DEVICE_DTS_CONFIG := config@4
>   	SOC := qcom-ipq4018
>   	IMAGE_SIZE := 13184k
> -	IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
> +	IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size | append-metadata
>   	DEVICE_PACKAGES := -kmod-ath10k-ct kmod-ath10k-ct-smallbuffers
>   endef
>   TARGET_DEVICES += zyxel_wre6606
> diff --git a/target/linux/ipq40xx/image/mikrotik.mk b/target/linux/ipq40xx/image/mikrotik.mk
> index 7c2fa52738..31497608be 100644
> --- a/target/linux/ipq40xx/image/mikrotik.mk
> +++ b/target/linux/ipq40xx/image/mikrotik.mk
> @@ -7,7 +7,7 @@ define Device/mikrotik_nor
>   	IMAGES = sysupgrade.bin
>   	IMAGE/sysupgrade.bin := append-kernel | kernel2minor -s 1024 | \
>   		pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | \
> -		append-metadata | check-size
> +		check-size | append-metadata
>   endef
>   
>   define Device/mikrotik_hap-ac2
> diff --git a/target/linux/ipq806x/image/Makefile b/target/linux/ipq806x/image/Makefile
> index e53fba1e1d..93e7ba3151 100644
> --- a/target/linux/ipq806x/image/Makefile
> +++ b/target/linux/ipq806x/image/Makefile
> @@ -401,7 +401,7 @@ define Device/ubnt_unifi-ac-hd
>   	BLOCKSIZE := 64k
>   	IMAGE_SIZE := 14784k
>   	DEVICE_PACKAGES := ath10k-firmware-qca9984-ct
> -	IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | append-metadata | check-size
> +	IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | check-size | append-metadata
>   endef
>   TARGET_DEVICES += ubnt_unifi-ac-hd
>   
> diff --git a/target/linux/lantiq/image/Makefile b/target/linux/lantiq/image/Makefile
> index c90975d098..ec10cd882a 100644
> --- a/target/linux/lantiq/image/Makefile
> +++ b/target/linux/lantiq/image/Makefile
> @@ -63,7 +63,7 @@ define Device/Default
>     SOC := $(DEFAULT_SOC)
>     DEVICE_DTS = $$(SOC)_$(1)
>     IMAGES := sysupgrade.bin
> -  IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
> +  IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size | append-metadata
>   endef
>   
>   define Device/NAND/xway
> @@ -102,7 +102,7 @@ define Device/AVM
>     KERNEL := kernel-bin | append-dtb | lzma | eva-image
>     KERNEL_INITRAMFS := $$(KERNEL)
>     IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-avm-fakeroot | \
> -	append-rootfs | pad-rootfs | append-metadata | check-size
> +	append-rootfs | pad-rootfs | check-size | append-metadata
>   endef
>   
>   ifeq ($(SUBTARGET),ase)
> diff --git a/target/linux/lantiq/image/ar9.mk b/target/linux/lantiq/image/ar9.mk
> index a973c90beb..9ce36c91e6 100644
> --- a/target/linux/lantiq/image/ar9.mk
> +++ b/target/linux/lantiq/image/ar9.mk
> @@ -91,10 +91,10 @@ define Device/netgear_dgn3500
>   	factory-na.img factory.img
>     IMAGE/sysupgrade-na.bin := \
>   	append-kernel | append-rootfs | dgn3500-sercom-footer 0x0 "NA" | \
> -	pad-rootfs | append-metadata | check-size
> +	pad-rootfs | check-size | append-metadata
>     IMAGE/sysupgrade.bin := \
>   	append-kernel | append-rootfs | dgn3500-sercom-footer 0x0 "WW" | \
> -	pad-rootfs | append-metadata | check-size
> +	pad-rootfs | check-size | append-metadata
>     IMAGE/factory-na.img := \
>   	pad-extra $(DGN3500_KERNEL_OFFSET_DEC) | append-kernel | append-rootfs | \
>   	dgn3500-sercom-footer $(DGN3500_KERNEL_OFFSET_HEX) "NA" | pad-rootfs | \
> @@ -121,7 +121,7 @@ define Device/netgear_dgn3500b
>     IMAGES += factory.img
>     IMAGE/sysupgrade.bin := \
>   	append-kernel | append-rootfs | dgn3500-sercom-footer 0x0 "DE" | \
> -	pad-rootfs | append-metadata | check-size
> +	pad-rootfs | check-size | append-metadata
>     IMAGE/factory.img := \
>   	pad-extra $(DGN3500_KERNEL_OFFSET_DEC) | append-kernel | append-rootfs | \
>   	dgn3500-sercom-footer $(DGN3500_KERNEL_OFFSET_HEX) "DE" | pad-rootfs | \
> diff --git a/target/linux/lantiq/image/tp-link.mk b/target/linux/lantiq/image/tp-link.mk
> index cebdf46e12..4dc904d6c1 100644
> --- a/target/linux/lantiq/image/tp-link.mk
> +++ b/target/linux/lantiq/image/tp-link.mk
> @@ -9,7 +9,7 @@ define Device/lantiqTpLink
>   	tplink-v2-header -s -V "ver. 1.0"
>     IMAGES := sysupgrade.bin
>     IMAGE/sysupgrade.bin := tplink-v2-image -s -V "ver. 1.0" | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>   endef
>   
>   define Device/tplink_tdw8970
> diff --git a/target/linux/lantiq/image/vr9.mk b/target/linux/lantiq/image/vr9.mk
> index d8cabea972..910edd2fb3 100644
> --- a/target/linux/lantiq/image/vr9.mk
> +++ b/target/linux/lantiq/image/vr9.mk
> @@ -227,7 +227,7 @@ define Device/netgear_dm200
>     IMAGE/sysupgrade.bin := append-kernel | \
>   	pad-offset 64k 64 | append-uImage-fakehdr filesystem | \
>   	pad-offset 64k 64 | append-uImage-fakehdr filesystem | \
> -	append-rootfs | pad-rootfs | append-metadata | check-size
> +	append-rootfs | pad-rootfs | check-size | append-metadata
>     IMAGE/factory.img := $$(IMAGE/sysupgrade.bin) | netgear-dni
>     IMAGE_SIZE := 7872k
>     NETGEAR_BOARD_ID := DM200
> diff --git a/target/linux/ramips/image/Makefile b/target/linux/ramips/image/Makefile
> index fc5223f3a4..cd2c425cef 100644
> --- a/target/linux/ramips/image/Makefile
> +++ b/target/linux/ramips/image/Makefile
> @@ -166,7 +166,7 @@ define Device/Default
>     IMAGES := sysupgrade.bin
>     COMPILE :=
>     sysupgrade_bin := append-kernel | append-rootfs | pad-rootfs
> -  IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
> +  IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size | append-metadata
>   endef
>   
>   define Device/netgear_sercomm_nor
> @@ -175,7 +175,7 @@ define Device/netgear_sercomm_nor
>     IMAGES += factory.img
>     IMAGE/default := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | \
>   	pad-rootfs
> -  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | check-size
> +  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
>     IMAGE/factory.img := pad-extra $$$$(SERCOMM_PAD) | $$(IMAGE/default) | \
>   	pad-to $$$$(BLOCKSIZE) | sercom-footer | pad-to 128 | \
>   	zip $$$$(SERCOMM_HWNAME).bin | sercom-seal
> @@ -190,7 +190,7 @@ define Device/seama
>     # - 36 bytes of META data (4-bytes aligned)
>     IMAGE/default := append-kernel | pad-offset $$$$(BLOCKSIZE) 64 | append-rootfs
>     IMAGE/sysupgrade.bin := \
> -	$$(IMAGE/default) | seama | pad-rootfs | append-metadata | check-size
> +	$$(IMAGE/default) | seama | pad-rootfs | check-size | append-metadata
>     IMAGE/factory.bin := \
>   	$$(IMAGE/default) | pad-rootfs -x 64 | seama | seama-seal | check-size
>     SEAMA_SIGNATURE :=
> diff --git a/target/linux/ramips/image/common-tp-link.mk b/target/linux/ramips/image/common-tp-link.mk
> index 07ad1ea250..915a086f98 100644
> --- a/target/linux/ramips/image/common-tp-link.mk
> +++ b/target/linux/ramips/image/common-tp-link.mk
> @@ -11,8 +11,8 @@ define Device/tplink-v1
>     KERNEL_INITRAMFS := $(KERNEL_DTB) | tplink-v1-header -e -O
>     IMAGES += factory.bin
>     IMAGE/factory.bin := tplink-v1-image factory -e -O
> -  IMAGE/sysupgrade.bin := tplink-v1-image sysupgrade -e -O | append-metadata | \
> -	check-size
> +  IMAGE/sysupgrade.bin := tplink-v1-image sysupgrade -e -O | check-size | \
> +	append-metadata
>   endef
>   
>   define Device/tplink-v2
> @@ -26,8 +26,8 @@ define Device/tplink-v2
>     KERNEL_INITRAMFS := $(KERNEL_DTB) | tplink-v2-header -e
>     IMAGES += factory.bin
>     IMAGE/factory.bin := tplink-v2-image -e
> -  IMAGE/sysupgrade.bin := tplink-v2-image -s -e | append-metadata | \
> -	check-size
> +  IMAGE/sysupgrade.bin := tplink-v2-image -s -e | check-size | \
> +	append-metadata
>   endef
>   
>   define Device/tplink-safeloader
> @@ -39,6 +39,6 @@ define Device/tplink-safeloader
>     KERNEL := $(KERNEL_DTB) | tplink-v1-header -e -O
>     IMAGES += factory.bin
>     IMAGE/sysupgrade.bin := append-rootfs | tplink-safeloader sysupgrade | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     IMAGE/factory.bin := append-rootfs | tplink-safeloader factory
>   endef
> diff --git a/target/linux/ramips/image/mt7620.mk b/target/linux/ramips/image/mt7620.mk
> index 849bd31ef8..c3b9bc9f6b 100644
> --- a/target/linux/ramips/image/mt7620.mk
> +++ b/target/linux/ramips/image/mt7620.mk
> @@ -327,7 +327,7 @@ define Device/edimax_br-6478ac-v2
>     IMAGE_SIZE := 7744k
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
>   	edimax-header -s CSYS -m RN68 -f 0x70000 -S 0x01100000 | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci \
>   	kmod-usb-ledtrig-usbport
>   endef
> @@ -341,7 +341,7 @@ define Device/edimax_ew-7476rpc
>     IMAGE_SIZE := 7744k
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
>   	edimax-header -s CSYS -m RN79 -f 0x70000 -S 0x01100000 | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_PACKAGES := kmod-mt76x2 kmod-phy-realtek
>   endef
>   TARGET_DEVICES += edimax_ew-7476rpc
> @@ -354,7 +354,7 @@ define Device/edimax_ew-7478ac
>     IMAGE_SIZE := 7744k
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
>   	edimax-header -s CSYS -m RN70 -f 0x70000 -S 0x01100000 | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_PACKAGES := kmod-mt76x2 kmod-phy-realtek
>   endef
>   TARGET_DEVICES += edimax_ew-7478ac
> @@ -367,7 +367,7 @@ define Device/edimax_ew-7478apc
>     IMAGE_SIZE := 7744k
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
>   	edimax-header -s CSYS -m RN75 -f 0x70000 -S 0x01100000 | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci \
>   	kmod-usb-ledtrig-usbport
>   endef
> @@ -407,7 +407,7 @@ define Device/fon_fon2601
>     DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci
>     KERNEL_INITRAMFS := $$(KERNEL) | uimage-padhdr
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | uimage-padhdr | \
> -	pad-rootfs | append-metadata | check-size
> +	pad-rootfs | check-size | append-metadata
>   endef
>   TARGET_DEVICES += fon_fon2601
>   
> diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
> index ae9b4757de..bd3d336a89 100644
> --- a/target/linux/ramips/image/mt7621.mk
> +++ b/target/linux/ramips/image/mt7621.mk
> @@ -289,7 +289,7 @@ define Device/dlink_dir-8xx-a1
>     KERNEL_INITRAMFS := $$(KERNEL) | uimage-padhdr 96
>     IMAGES += factory.bin
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | uimage-padhdr 96 |\
> -	pad-rootfs | append-metadata | check-size
> +	pad-rootfs | check-size | append-metadata
>     IMAGE/factory.bin := append-kernel | append-rootfs | uimage-padhdr 96 |\
>   	check-size
>   endef
> @@ -440,7 +440,7 @@ define Device/edimax_re23s
>     DEVICE_ALT0_MODEL := Gemini RE23S
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
>   	edimax-header -s CSYS -m RN76 -f 0x70000 -S 0x01100000 | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     IMAGES += factory.bin
>     IMAGE/factory.bin := append-kernel | append-rootfs | \
>   	edimax-header -s CSYS -m RN76 -f 0x70000 -S 0x01100000 | pad-rootfs | \
> @@ -824,7 +824,7 @@ define Device/linksys_ea7xxx
>   	uboot-envtools
>     UBINIZE_OPTS := -E 5
>     IMAGES := sysupgrade.bin factory.bin
> -  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata | check-size
> +  IMAGE/sysupgrade.bin := sysupgrade-tar | check-size | append-metadata
>     IMAGE/factory.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | \
>   	append-ubi | check-size | linksys-image type=$$$$(LINKSYS_HWNAME)
>   endef
> @@ -901,8 +901,8 @@ define Device/MikroTik
>     KERNEL_NAME := vmlinuz
>     KERNEL := kernel-bin | append-dtb-elf
>     IMAGE/sysupgrade.bin := append-kernel | kernel2minor -s 1024 | \
> -	pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | append-metadata | \
> -	check-size
> +	pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | check-size | \
> +	append-metadata
>   endef
>   
>   define Device/mikrotik_routerboard-750gr3
> diff --git a/target/linux/ramips/image/rt305x.mk b/target/linux/ramips/image/rt305x.mk
> index 4edc2eb3c4..6c339dcba1 100644
> --- a/target/linux/ramips/image/rt305x.mk
> +++ b/target/linux/ramips/image/rt305x.mk
> @@ -500,7 +500,7 @@ define Device/edimax_3g-6200n
>     IMAGE_SIZE := 3648k
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
>   	edimax-header -s CSYS -m 3G62 -f 0x50000 -S 0x01100000 | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_VENDOR := Edimax
>     DEVICE_MODEL := 3g-6200n
>     SUPPORTED_DEVICES += 3g-6200n
> @@ -513,7 +513,7 @@ define Device/edimax_3g-6200nl
>     IMAGE_SIZE := 3648k
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
>   	edimax-header -s CSYS -m 3G62 -f 0x50000 -S 0x01100000 | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_VENDOR := Edimax
>     DEVICE_MODEL := 3g-6200nl
>     SUPPORTED_DEVICES += 3g-6200nl
> @@ -1047,7 +1047,7 @@ define Device/trendnet_tew-638apb-v2
>     BLOCKSIZE := 64k
>     IMAGE_SIZE := 3776k
>     IMAGE/sysupgrade.bin := $$(sysupgrade_bin) | umedia-header 0x026382 | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_VENDOR := TRENDnet
>     DEVICE_MODEL := TEW-638APB
>     DEVICE_VARIANT := v2
> diff --git a/target/linux/ramips/image/rt3883.mk b/target/linux/ramips/image/rt3883.mk
> index 1b46d570fd..148bfbbe44 100644
> --- a/target/linux/ramips/image/rt3883.mk
> +++ b/target/linux/ramips/image/rt3883.mk
> @@ -52,7 +52,7 @@ define Device/edimax_br-6475nd
>     IMAGE_SIZE := 7744k
>     IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
>   	edimax-header -s CSYS -m RN54 -f 0x70000 -S 0x01100000 | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>     DEVICE_VENDOR := Edimax
>     DEVICE_MODEL := BR-6475nD
>     SUPPORTED_DEVICES += br-6475nd
> diff --git a/target/linux/realtek/image/Makefile b/target/linux/realtek/image/Makefile
> index ebc0c0a784..cf0d588851 100644
> --- a/target/linux/realtek/image/Makefile
> +++ b/target/linux/realtek/image/Makefile
> @@ -24,7 +24,7 @@ define Device/Default
>     DEVICE_DTS = $$(SOC)_$(1)
>     IMAGES := sysupgrade.bin
>     IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-rootfs | pad-rootfs | \
> -	append-metadata | check-size
> +	check-size | append-metadata
>   endef
>   
>   # "NGE" refers to the uImage magic
diff mbox series

Patch

diff --git a/target/linux/ath79/image/Makefile b/target/linux/ath79/image/Makefile
index aa8665fbb2..aee4ddf963 100644
--- a/target/linux/ath79/image/Makefile
+++ b/target/linux/ath79/image/Makefile
@@ -81,7 +81,7 @@  define Device/Default
   COMPILE :=
   IMAGES := sysupgrade.bin
   IMAGE/sysupgrade.bin = append-kernel | pad-to $$$$(BLOCKSIZE) | \
-	append-rootfs | pad-rootfs | append-metadata | check-size
+	append-rootfs | pad-rootfs | check-size | append-metadata
 endef
 
 include $(SUBTARGET).mk
diff --git a/target/linux/ath79/image/common-mikrotik.mk b/target/linux/ath79/image/common-mikrotik.mk
index 6e739f2d85..5f5fa7899a 100644
--- a/target/linux/ath79/image/common-mikrotik.mk
+++ b/target/linux/ath79/image/common-mikrotik.mk
@@ -9,7 +9,7 @@  define Device/mikrotik_nor
   $(Device/mikrotik)
   IMAGE/sysupgrade.bin := append-kernel | kernel2minor -s 1024 -e | \
 	pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
 endef
 
 define Device/mikrotik_nand
diff --git a/target/linux/ath79/image/common-netgear.mk b/target/linux/ath79/image/common-netgear.mk
index 8a74fdc0c9..5a61caf1f6 100644
--- a/target/linux/ath79/image/common-netgear.mk
+++ b/target/linux/ath79/image/common-netgear.mk
@@ -32,10 +32,8 @@  define Device/netgear_generic
   KERNEL := kernel-bin | append-dtb | lzma -d20 | uImage lzma
   KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma -d20 | uImage lzma
   IMAGES += factory.img
-  IMAGE/default := append-kernel | pad-to $$$$(BLOCKSIZE) | netgear-squashfs | \
-	append-rootfs | pad-rootfs
-  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
-	check-size
-  IMAGE/factory.img := $$(IMAGE/default) | netgear-dni | \
-	check-size
+  IMAGE/default := append-kernel | pad-to $$$$(BLOCKSIZE) | \
+	netgear-squashfs | append-rootfs | pad-rootfs
+  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
+  IMAGE/factory.img := $$(IMAGE/default) | netgear-dni | check-size
 endef
diff --git a/target/linux/ath79/image/common-tp-link.mk b/target/linux/ath79/image/common-tp-link.mk
index 0b7b0e1935..f1d5614aa7 100644
--- a/target/linux/ath79/image/common-tp-link.mk
+++ b/target/linux/ath79/image/common-tp-link.mk
@@ -22,8 +22,7 @@  define Device/tplink-v2
   TPLINK_HVERSION := 3
   KERNEL := kernel-bin | append-dtb | lzma
   KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | tplink-v2-header
-  IMAGE/sysupgrade.bin := tplink-v2-image -s | append-metadata | \
-	check-size
+  IMAGE/sysupgrade.bin := tplink-v2-image -s | check-size | append-metadata
 endef
 
 define Device/tplink-nolzma
@@ -74,7 +73,7 @@  define Device/tplink-safeloader
   KERNEL := kernel-bin | append-dtb | lzma | tplink-v1-header -O
   KERNEL_INITRAMFS := $$(KERNEL)
   IMAGE/sysupgrade.bin := append-rootfs | tplink-safeloader sysupgrade | \
-	append-metadata | check-size
+	check-size | append-metadata
   IMAGE/factory.bin := append-rootfs | tplink-safeloader factory
 endef
 
diff --git a/target/linux/ath79/image/generic-tp-link.mk b/target/linux/ath79/image/generic-tp-link.mk
index 8b228a73d2..99fe86f592 100644
--- a/target/linux/ath79/image/generic-tp-link.mk
+++ b/target/linux/ath79/image/generic-tp-link.mk
@@ -692,7 +692,7 @@  define Device/tplink_tl-wr2543-v1
   DEVICE_PACKAGES := kmod-usb2 kmod-usb-ledtrig-usbport
   TPLINK_HWID := 0x25430001
   IMAGE/sysupgrade.bin := tplink-v1-image sysupgrade -v 3.13.99 | \
-	append-metadata | check-size
+	check-size | append-metadata
   IMAGE/factory.bin := tplink-v1-image factory -v 3.13.99
   SUPPORTED_DEVICES += tl-wr2543n
 endef
diff --git a/target/linux/ath79/image/generic-ubnt.mk b/target/linux/ath79/image/generic-ubnt.mk
index f8e1d1e432..29a1a710e4 100644
--- a/target/linux/ath79/image/generic-ubnt.mk
+++ b/target/linux/ath79/image/generic-ubnt.mk
@@ -128,7 +128,7 @@  define Device/ubnt-unifi-jffs2
   KERNEL := kernel-bin | append-dtb | lzma | uImage lzma | jffs2 kernel0
   IMAGES := sysupgrade.bin factory.bin
   IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-rootfs |\
-	pad-rootfs | append-metadata | check-size
+	pad-rootfs | check-size | append-metadata
   IMAGE/factory.bin := $$(IMAGE/sysupgrade.bin) | mkubntimage2
 endef
 
@@ -365,7 +365,7 @@  define Device/ubnt_routerstation_common
   IMAGE/factory.bin := append-rootfs | pad-rootfs | mkubntimage | \
 	check-size
   IMAGE/sysupgrade.bin := append-rootfs | pad-rootfs | combined-image | \
-	append-metadata | check-size
+	check-size | append-metadata
   KERNEL := kernel-bin | append-dtb | lzma | pad-to $$(BLOCKSIZE)
   KERNEL_INITRAMFS := kernel-bin | append-dtb
 endef
diff --git a/target/linux/ath79/image/generic.mk b/target/linux/ath79/image/generic.mk
index 9d0be2b86b..f4d266838e 100644
--- a/target/linux/ath79/image/generic.mk
+++ b/target/linux/ath79/image/generic.mk
@@ -163,7 +163,7 @@  define Device/seama
   # - 36 bytes of META data (4-bytes aligned)
   IMAGE/default := append-kernel | pad-offset $$$$(BLOCKSIZE) 64 | append-rootfs
   IMAGE/sysupgrade.bin := $$(IMAGE/default) | seama | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   IMAGE/factory.bin := $$(IMAGE/default) | pad-rootfs -x 64 | seama | \
 	seama-seal | check-size
   SEAMA_SIGNATURE :=
@@ -327,7 +327,7 @@  define Device/avm
   KERNEL_INITRAMFS := $$(KERNEL)
   IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | \
 	append-squashfs-fakeroot-be | pad-to 256 | append-rootfs | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_PACKAGES := fritz-tffs
 endef
 
@@ -768,7 +768,7 @@  define Device/dlink_dap-2xxx
   IMAGE/factory.img := append-kernel | pad-offset 6144k 160 | \
 	append-rootfs | wrgg-pad-rootfs | mkwrggimg | check-size
   IMAGE/sysupgrade.bin := append-kernel | mkwrggimg | \
-	pad-to $$$$(BLOCKSIZE) | append-rootfs | append-metadata | check-size
+	pad-to $$$$(BLOCKSIZE) | append-rootfs | check-size | append-metadata
   KERNEL := kernel-bin | append-dtb | relocate-kernel | lzma
   KERNEL_INITRAMFS := $$(KERNEL) | mkwrggimg
 endef
@@ -820,7 +820,7 @@  define Device/dlink_dap-2695-a1
   IMAGE/factory.img := $$(IMAGE/default) | append-rootfs | wrgg-pad-rootfs | \
 	mkwrggimg | check-size
   IMAGE/sysupgrade.bin := $$(IMAGE/default) | mkwrggimg | append-rootfs | \
-	wrgg-pad-rootfs | append-metadata |  check-size
+	wrgg-pad-rootfs | check-size | append-metadata
   KERNEL := kernel-bin | append-dtb | relocate-kernel | lzma
   KERNEL_INITRAMFS := $$(KERNEL) | mkwrggimg
   DAP_SIGNATURE := wapac02_dkbs_dap2695
@@ -882,7 +882,7 @@  define Device/dlink_dir-825-b1
   DEVICE_VARIANT := B1
   IMAGE_SIZE := 6208k
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_PACKAGES := kmod-usb-ohci kmod-usb2 kmod-usb-ledtrig-usbport \
 	kmod-leds-reset kmod-owl-loader
   SUPPORTED_DEVICES += dir-825-b1
@@ -903,8 +903,7 @@  define Device/dlink_dir-825-c1
 	pad-rootfs
   IMAGE/factory.bin := $$(IMAGE/default) | pad-offset $$$$(IMAGE_SIZE) 26 | \
 	append-string 00DB120AR9344-RT-101214-00 | check-size
-  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
-	check-size
+  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
 endef
 TARGET_DEVICES += dlink_dir-825-c1
 
@@ -921,8 +920,7 @@  define Device/dlink_dir-835-a1
 	pad-rootfs
   IMAGE/factory.bin := $$(IMAGE/default) | pad-offset $$$$(IMAGE_SIZE) 26 | \
 	append-string 00DB120AR9344-RT-101214-00 | check-size
-  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
-	check-size
+  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
 endef
 TARGET_DEVICES += dlink_dir-835-a1
 
@@ -941,7 +939,7 @@  define Device/dlink_dir-842-c
   IMAGE/default := append-kernel | uImage lzma | \
 	pad-offset $$$$(BLOCKSIZE) 64 | append-rootfs
   IMAGE/sysupgrade.bin := $$(IMAGE/default) | seama | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   IMAGE/factory.bin := $$(IMAGE/default) | pad-rootfs -x 64 | seama | \
 	seama-seal | check-size
   IMAGE_SIZE := 15680k
@@ -1354,7 +1352,7 @@  define Device/jjplus_ja76pf2
   IMAGE/kernel.bin := append-kernel
   IMAGE/rootfs.bin := append-rootfs | pad-rootfs
   IMAGE/sysupgrade.bin := append-rootfs | pad-rootfs | combined-image | \
-	append-metadata | check-size
+	check-size | append-metadata
   KERNEL := kernel-bin | append-dtb | lzma | pad-to $$(BLOCKSIZE)
   KERNEL_INITRAMFS := kernel-bin | append-dtb
   IMAGE_SIZE := 16000k
@@ -1421,7 +1419,7 @@  define Device/nec_wx1200cr
   DEVICE_VENDOR := NEC
   IMAGE/default := append-kernel | pad-offset $$$$(BLOCKSIZE) 64 | append-rootfs
   IMAGE/sysupgrade.bin := $$(IMAGE/default) | seama | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_PACKAGES := kmod-ath10k-ct ath10k-firmware-qca9888-ct
 endef
 
@@ -1473,10 +1471,8 @@  define Device/netgear_ex6400_ex7300
   IMAGE_SIZE := 15552k
   IMAGE/default := append-kernel | pad-offset $$$$(BLOCKSIZE) 64 | \
 	netgear-rootfs | pad-rootfs
-  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
-	check-size
-  IMAGE/factory.img := $$(IMAGE/default) | netgear-dni | \
-	check-size
+  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
+  IMAGE/factory.img := $$(IMAGE/default) | netgear-dni | check-size
   DEVICE_PACKAGES := kmod-ath10k-ct ath10k-firmware-qca99x0-ct
 endef
 
@@ -1859,7 +1855,7 @@  define Device/phicomm_k2t
   DEVICE_MODEL := K2T
   IMAGE_SIZE := 15744k
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_PACKAGES := kmod-leds-reset kmod-ath10k-ct-smallbuffers ath10k-firmware-qca9888-ct
 endef
 TARGET_DEVICES += phicomm_k2t
@@ -2199,8 +2195,7 @@  define Device/teltonika_rut955
 	pad-rootfs | teltonika-fw-fake-checksum | append-string master |\
 	append-md5sum-bin | check-size
   IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) |\
-	append-rootfs | pad-rootfs | append-metadata |\
-	check-size
+	append-rootfs | pad-rootfs | check-size | append-metadata
 endef
 TARGET_DEVICES += teltonika_rut955
 
@@ -2223,8 +2218,7 @@  define Device/trendnet_tew-823dru
 	pad-rootfs
   IMAGE/factory.bin := $$(IMAGE/default) | pad-offset $$$$(IMAGE_SIZE) 26 | \
 	append-string 00AP135AR9558-RT-131129-00 | check-size
-  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
-	check-size
+  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
 endef
 TARGET_DEVICES += trendnet_tew-823dru
 
diff --git a/target/linux/ath79/image/nand.mk b/target/linux/ath79/image/nand.mk
index caaa01c92d..20cb2f60fa 100644
--- a/target/linux/ath79/image/nand.mk
+++ b/target/linux/ath79/image/nand.mk
@@ -166,8 +166,7 @@  define Device/netgear_ath79_nand
   IMAGES := sysupgrade.bin factory.img
   IMAGE/factory.img := append-kernel | append-ubi | netgear-dni | \
 	check-size
-  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata | \
-	check-size
+  IMAGE/sysupgrade.bin := sysupgrade-tar | check-size | append-metadata
   UBINIZE_OPTS := -E 5
 endef
 
diff --git a/target/linux/ath79/image/tiny.mk b/target/linux/ath79/image/tiny.mk
index 29e411c058..f4a03e2840 100644
--- a/target/linux/ath79/image/tiny.mk
+++ b/target/linux/ath79/image/tiny.mk
@@ -21,8 +21,7 @@  define Device/dlink_dir-615-e4
   FACTORY_IMAGE_SIZE := 3456k
   IMAGES += factory.bin
   IMAGE/default := append-kernel | append-rootfs | pad-rootfs
-  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | \
-	check-size
+  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
   IMAGE/factory.bin := $$(IMAGE/default) | \
 	check-size $$$$(FACTORY_IMAGE_SIZE) | pad-to $$$$(FACTORY_IMAGE_SIZE) | \
 	append-string "AP99-AR7240-RT-091105-05"
diff --git a/target/linux/ipq40xx/image/generic.mk b/target/linux/ipq40xx/image/generic.mk
index 68e565594d..9dee742eb4 100644
--- a/target/linux/ipq40xx/image/generic.mk
+++ b/target/linux/ipq40xx/image/generic.mk
@@ -35,7 +35,7 @@  define Device/DniImage
 	IMAGES += factory.img
 	IMAGE/factory.img := append-kernel | pad-offset 64k 64 | append-uImage-fakehdr filesystem | append-rootfs | pad-rootfs | netgear-dni
 	IMAGE/sysupgrade.bin := append-kernel | pad-offset 64k 64 | append-uImage-fakehdr filesystem | \
-		append-rootfs | pad-rootfs | append-metadata | check-size
+		append-rootfs | pad-rootfs | check-size | append-metadata
 endef
 
 define Build/append-rootfshdr
@@ -106,7 +106,7 @@  define Device/8dev_habanero-dvk
 	IMAGE_SIZE := 30976k
 	SOC := qcom-ipq4019
 	DEVICE_PACKAGES := ipq-wifi-8dev_habanero-dvk
-	IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-rootfs | pad-rootfs | append-metadata | check-size
+	IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-rootfs | pad-rootfs | check-size | append-metadata
 endef
 TARGET_DEVICES += 8dev_habanero-dvk
 
@@ -207,7 +207,7 @@  define Device/avm_fritzbox-4040
 	UBOOT_PARTITION_SIZE := 524288
 	IMAGES += eva.bin
 	IMAGE/eva.bin := append-uboot | pad-to $$$$(UBOOT_PARTITION_SIZE) | append-kernel | append-rootfs | pad-rootfs
-	IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
+	IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size | append-metadata
 	DEVICE_PACKAGES := fritz-tffs fritz-caldata
 endef
 TARGET_DEVICES += avm_fritzbox-4040
@@ -822,7 +822,7 @@  define Device/zyxel_wre6606
 	DEVICE_DTS_CONFIG := config@4
 	SOC := qcom-ipq4018
 	IMAGE_SIZE := 13184k
-	IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
+	IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size | append-metadata
 	DEVICE_PACKAGES := -kmod-ath10k-ct kmod-ath10k-ct-smallbuffers
 endef
 TARGET_DEVICES += zyxel_wre6606
diff --git a/target/linux/ipq40xx/image/mikrotik.mk b/target/linux/ipq40xx/image/mikrotik.mk
index 7c2fa52738..31497608be 100644
--- a/target/linux/ipq40xx/image/mikrotik.mk
+++ b/target/linux/ipq40xx/image/mikrotik.mk
@@ -7,7 +7,7 @@  define Device/mikrotik_nor
 	IMAGES = sysupgrade.bin
 	IMAGE/sysupgrade.bin := append-kernel | kernel2minor -s 1024 | \
 		pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | \
-		append-metadata | check-size
+		check-size | append-metadata
 endef
 
 define Device/mikrotik_hap-ac2
diff --git a/target/linux/ipq806x/image/Makefile b/target/linux/ipq806x/image/Makefile
index e53fba1e1d..93e7ba3151 100644
--- a/target/linux/ipq806x/image/Makefile
+++ b/target/linux/ipq806x/image/Makefile
@@ -401,7 +401,7 @@  define Device/ubnt_unifi-ac-hd
 	BLOCKSIZE := 64k
 	IMAGE_SIZE := 14784k
 	DEVICE_PACKAGES := ath10k-firmware-qca9984-ct
-	IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | append-metadata | check-size
+	IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | check-size | append-metadata
 endef
 TARGET_DEVICES += ubnt_unifi-ac-hd
 
diff --git a/target/linux/lantiq/image/Makefile b/target/linux/lantiq/image/Makefile
index c90975d098..ec10cd882a 100644
--- a/target/linux/lantiq/image/Makefile
+++ b/target/linux/lantiq/image/Makefile
@@ -63,7 +63,7 @@  define Device/Default
   SOC := $(DEFAULT_SOC)
   DEVICE_DTS = $$(SOC)_$(1)
   IMAGES := sysupgrade.bin
-  IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
+  IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size | append-metadata
 endef
 
 define Device/NAND/xway
@@ -102,7 +102,7 @@  define Device/AVM
   KERNEL := kernel-bin | append-dtb | lzma | eva-image
   KERNEL_INITRAMFS := $$(KERNEL)
   IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-avm-fakeroot | \
-	append-rootfs | pad-rootfs | append-metadata | check-size
+	append-rootfs | pad-rootfs | check-size | append-metadata
 endef
 
 ifeq ($(SUBTARGET),ase)
diff --git a/target/linux/lantiq/image/ar9.mk b/target/linux/lantiq/image/ar9.mk
index a973c90beb..9ce36c91e6 100644
--- a/target/linux/lantiq/image/ar9.mk
+++ b/target/linux/lantiq/image/ar9.mk
@@ -91,10 +91,10 @@  define Device/netgear_dgn3500
 	factory-na.img factory.img
   IMAGE/sysupgrade-na.bin := \
 	append-kernel | append-rootfs | dgn3500-sercom-footer 0x0 "NA" | \
-	pad-rootfs | append-metadata | check-size
+	pad-rootfs | check-size | append-metadata
   IMAGE/sysupgrade.bin := \
 	append-kernel | append-rootfs | dgn3500-sercom-footer 0x0 "WW" | \
-	pad-rootfs | append-metadata | check-size
+	pad-rootfs | check-size | append-metadata
   IMAGE/factory-na.img := \
 	pad-extra $(DGN3500_KERNEL_OFFSET_DEC) | append-kernel | append-rootfs | \
 	dgn3500-sercom-footer $(DGN3500_KERNEL_OFFSET_HEX) "NA" | pad-rootfs | \
@@ -121,7 +121,7 @@  define Device/netgear_dgn3500b
   IMAGES += factory.img
   IMAGE/sysupgrade.bin := \
 	append-kernel | append-rootfs | dgn3500-sercom-footer 0x0 "DE" | \
-	pad-rootfs | append-metadata | check-size
+	pad-rootfs | check-size | append-metadata
   IMAGE/factory.img := \
 	pad-extra $(DGN3500_KERNEL_OFFSET_DEC) | append-kernel | append-rootfs | \
 	dgn3500-sercom-footer $(DGN3500_KERNEL_OFFSET_HEX) "DE" | pad-rootfs | \
diff --git a/target/linux/lantiq/image/tp-link.mk b/target/linux/lantiq/image/tp-link.mk
index cebdf46e12..4dc904d6c1 100644
--- a/target/linux/lantiq/image/tp-link.mk
+++ b/target/linux/lantiq/image/tp-link.mk
@@ -9,7 +9,7 @@  define Device/lantiqTpLink
 	tplink-v2-header -s -V "ver. 1.0"
   IMAGES := sysupgrade.bin
   IMAGE/sysupgrade.bin := tplink-v2-image -s -V "ver. 1.0" | \
-	append-metadata | check-size
+	check-size | append-metadata
 endef
 
 define Device/tplink_tdw8970
diff --git a/target/linux/lantiq/image/vr9.mk b/target/linux/lantiq/image/vr9.mk
index d8cabea972..910edd2fb3 100644
--- a/target/linux/lantiq/image/vr9.mk
+++ b/target/linux/lantiq/image/vr9.mk
@@ -227,7 +227,7 @@  define Device/netgear_dm200
   IMAGE/sysupgrade.bin := append-kernel | \
 	pad-offset 64k 64 | append-uImage-fakehdr filesystem | \
 	pad-offset 64k 64 | append-uImage-fakehdr filesystem | \
-	append-rootfs | pad-rootfs | append-metadata | check-size
+	append-rootfs | pad-rootfs | check-size | append-metadata
   IMAGE/factory.img := $$(IMAGE/sysupgrade.bin) | netgear-dni
   IMAGE_SIZE := 7872k
   NETGEAR_BOARD_ID := DM200
diff --git a/target/linux/ramips/image/Makefile b/target/linux/ramips/image/Makefile
index fc5223f3a4..cd2c425cef 100644
--- a/target/linux/ramips/image/Makefile
+++ b/target/linux/ramips/image/Makefile
@@ -166,7 +166,7 @@  define Device/Default
   IMAGES := sysupgrade.bin
   COMPILE :=
   sysupgrade_bin := append-kernel | append-rootfs | pad-rootfs
-  IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
+  IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size | append-metadata
 endef
 
 define Device/netgear_sercomm_nor
@@ -175,7 +175,7 @@  define Device/netgear_sercomm_nor
   IMAGES += factory.img
   IMAGE/default := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | \
 	pad-rootfs
-  IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | check-size
+  IMAGE/sysupgrade.bin := $$(IMAGE/default) | check-size | append-metadata
   IMAGE/factory.img := pad-extra $$$$(SERCOMM_PAD) | $$(IMAGE/default) | \
 	pad-to $$$$(BLOCKSIZE) | sercom-footer | pad-to 128 | \
 	zip $$$$(SERCOMM_HWNAME).bin | sercom-seal
@@ -190,7 +190,7 @@  define Device/seama
   # - 36 bytes of META data (4-bytes aligned)
   IMAGE/default := append-kernel | pad-offset $$$$(BLOCKSIZE) 64 | append-rootfs
   IMAGE/sysupgrade.bin := \
-	$$(IMAGE/default) | seama | pad-rootfs | append-metadata | check-size
+	$$(IMAGE/default) | seama | pad-rootfs | check-size | append-metadata
   IMAGE/factory.bin := \
 	$$(IMAGE/default) | pad-rootfs -x 64 | seama | seama-seal | check-size
   SEAMA_SIGNATURE :=
diff --git a/target/linux/ramips/image/common-tp-link.mk b/target/linux/ramips/image/common-tp-link.mk
index 07ad1ea250..915a086f98 100644
--- a/target/linux/ramips/image/common-tp-link.mk
+++ b/target/linux/ramips/image/common-tp-link.mk
@@ -11,8 +11,8 @@  define Device/tplink-v1
   KERNEL_INITRAMFS := $(KERNEL_DTB) | tplink-v1-header -e -O
   IMAGES += factory.bin
   IMAGE/factory.bin := tplink-v1-image factory -e -O
-  IMAGE/sysupgrade.bin := tplink-v1-image sysupgrade -e -O | append-metadata | \
-	check-size
+  IMAGE/sysupgrade.bin := tplink-v1-image sysupgrade -e -O | check-size | \
+	append-metadata
 endef
 
 define Device/tplink-v2
@@ -26,8 +26,8 @@  define Device/tplink-v2
   KERNEL_INITRAMFS := $(KERNEL_DTB) | tplink-v2-header -e
   IMAGES += factory.bin
   IMAGE/factory.bin := tplink-v2-image -e
-  IMAGE/sysupgrade.bin := tplink-v2-image -s -e | append-metadata | \
-	check-size
+  IMAGE/sysupgrade.bin := tplink-v2-image -s -e | check-size | \
+	append-metadata
 endef
 
 define Device/tplink-safeloader
@@ -39,6 +39,6 @@  define Device/tplink-safeloader
   KERNEL := $(KERNEL_DTB) | tplink-v1-header -e -O
   IMAGES += factory.bin
   IMAGE/sysupgrade.bin := append-rootfs | tplink-safeloader sysupgrade | \
-	append-metadata | check-size
+	check-size | append-metadata
   IMAGE/factory.bin := append-rootfs | tplink-safeloader factory
 endef
diff --git a/target/linux/ramips/image/mt7620.mk b/target/linux/ramips/image/mt7620.mk
index 849bd31ef8..c3b9bc9f6b 100644
--- a/target/linux/ramips/image/mt7620.mk
+++ b/target/linux/ramips/image/mt7620.mk
@@ -327,7 +327,7 @@  define Device/edimax_br-6478ac-v2
   IMAGE_SIZE := 7744k
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
 	edimax-header -s CSYS -m RN68 -f 0x70000 -S 0x01100000 | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci \
 	kmod-usb-ledtrig-usbport
 endef
@@ -341,7 +341,7 @@  define Device/edimax_ew-7476rpc
   IMAGE_SIZE := 7744k
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
 	edimax-header -s CSYS -m RN79 -f 0x70000 -S 0x01100000 | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_PACKAGES := kmod-mt76x2 kmod-phy-realtek
 endef
 TARGET_DEVICES += edimax_ew-7476rpc
@@ -354,7 +354,7 @@  define Device/edimax_ew-7478ac
   IMAGE_SIZE := 7744k
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
 	edimax-header -s CSYS -m RN70 -f 0x70000 -S 0x01100000 | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_PACKAGES := kmod-mt76x2 kmod-phy-realtek
 endef
 TARGET_DEVICES += edimax_ew-7478ac
@@ -367,7 +367,7 @@  define Device/edimax_ew-7478apc
   IMAGE_SIZE := 7744k
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
 	edimax-header -s CSYS -m RN75 -f 0x70000 -S 0x01100000 | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci \
 	kmod-usb-ledtrig-usbport
 endef
@@ -407,7 +407,7 @@  define Device/fon_fon2601
   DEVICE_PACKAGES := kmod-mt76x2 kmod-usb2 kmod-usb-ohci
   KERNEL_INITRAMFS := $$(KERNEL) | uimage-padhdr
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | uimage-padhdr | \
-	pad-rootfs | append-metadata | check-size
+	pad-rootfs | check-size | append-metadata
 endef
 TARGET_DEVICES += fon_fon2601
 
diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
index ae9b4757de..bd3d336a89 100644
--- a/target/linux/ramips/image/mt7621.mk
+++ b/target/linux/ramips/image/mt7621.mk
@@ -289,7 +289,7 @@  define Device/dlink_dir-8xx-a1
   KERNEL_INITRAMFS := $$(KERNEL) | uimage-padhdr 96
   IMAGES += factory.bin
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | uimage-padhdr 96 |\
-	pad-rootfs | append-metadata | check-size
+	pad-rootfs | check-size | append-metadata
   IMAGE/factory.bin := append-kernel | append-rootfs | uimage-padhdr 96 |\
 	check-size
 endef
@@ -440,7 +440,7 @@  define Device/edimax_re23s
   DEVICE_ALT0_MODEL := Gemini RE23S
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
 	edimax-header -s CSYS -m RN76 -f 0x70000 -S 0x01100000 | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   IMAGES += factory.bin
   IMAGE/factory.bin := append-kernel | append-rootfs | \
 	edimax-header -s CSYS -m RN76 -f 0x70000 -S 0x01100000 | pad-rootfs | \
@@ -824,7 +824,7 @@  define Device/linksys_ea7xxx
 	uboot-envtools
   UBINIZE_OPTS := -E 5
   IMAGES := sysupgrade.bin factory.bin
-  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata | check-size
+  IMAGE/sysupgrade.bin := sysupgrade-tar | check-size | append-metadata
   IMAGE/factory.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) | \
 	append-ubi | check-size | linksys-image type=$$$$(LINKSYS_HWNAME)
 endef
@@ -901,8 +901,8 @@  define Device/MikroTik
   KERNEL_NAME := vmlinuz
   KERNEL := kernel-bin | append-dtb-elf
   IMAGE/sysupgrade.bin := append-kernel | kernel2minor -s 1024 | \
-	pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | append-metadata | \
-	check-size
+	pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | check-size | \
+	append-metadata
 endef
 
 define Device/mikrotik_routerboard-750gr3
diff --git a/target/linux/ramips/image/rt305x.mk b/target/linux/ramips/image/rt305x.mk
index 4edc2eb3c4..6c339dcba1 100644
--- a/target/linux/ramips/image/rt305x.mk
+++ b/target/linux/ramips/image/rt305x.mk
@@ -500,7 +500,7 @@  define Device/edimax_3g-6200n
   IMAGE_SIZE := 3648k
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
 	edimax-header -s CSYS -m 3G62 -f 0x50000 -S 0x01100000 | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_VENDOR := Edimax
   DEVICE_MODEL := 3g-6200n
   SUPPORTED_DEVICES += 3g-6200n
@@ -513,7 +513,7 @@  define Device/edimax_3g-6200nl
   IMAGE_SIZE := 3648k
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
 	edimax-header -s CSYS -m 3G62 -f 0x50000 -S 0x01100000 | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_VENDOR := Edimax
   DEVICE_MODEL := 3g-6200nl
   SUPPORTED_DEVICES += 3g-6200nl
@@ -1047,7 +1047,7 @@  define Device/trendnet_tew-638apb-v2
   BLOCKSIZE := 64k
   IMAGE_SIZE := 3776k
   IMAGE/sysupgrade.bin := $$(sysupgrade_bin) | umedia-header 0x026382 | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_VENDOR := TRENDnet
   DEVICE_MODEL := TEW-638APB
   DEVICE_VARIANT := v2
diff --git a/target/linux/ramips/image/rt3883.mk b/target/linux/ramips/image/rt3883.mk
index 1b46d570fd..148bfbbe44 100644
--- a/target/linux/ramips/image/rt3883.mk
+++ b/target/linux/ramips/image/rt3883.mk
@@ -52,7 +52,7 @@  define Device/edimax_br-6475nd
   IMAGE_SIZE := 7744k
   IMAGE/sysupgrade.bin := append-kernel | append-rootfs | \
 	edimax-header -s CSYS -m RN54 -f 0x70000 -S 0x01100000 | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
   DEVICE_VENDOR := Edimax
   DEVICE_MODEL := BR-6475nD
   SUPPORTED_DEVICES += br-6475nd
diff --git a/target/linux/realtek/image/Makefile b/target/linux/realtek/image/Makefile
index ebc0c0a784..cf0d588851 100644
--- a/target/linux/realtek/image/Makefile
+++ b/target/linux/realtek/image/Makefile
@@ -24,7 +24,7 @@  define Device/Default
   DEVICE_DTS = $$(SOC)_$(1)
   IMAGES := sysupgrade.bin
   IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-rootfs | pad-rootfs | \
-	append-metadata | check-size
+	check-size | append-metadata
 endef
 
 # "NGE" refers to the uImage magic