image: use helper function for size units
authorTony Ambardar <itugrok@yahoo.com>
Sat, 11 Nov 2023 12:29:26 +0000 (04:29 -0800)
committerHauke Mehrtens <hauke@hauke-m.de>
Sun, 26 Nov 2023 17:37:20 +0000 (18:37 +0100)
Add the make function 'exp_units' for helping evaluate k/m/g size units in
expressions, and use this to consistently replace many ad hoc substitutions
like '$(subst k,* 1024,$(subst m, * 1024k,$(IMAGE_SIZE)))' in makefiles.

Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
include/image-commands.mk
include/image.mk
target/linux/ath79/image/generic.mk
target/linux/ath79/image/nand.mk
target/linux/ipq40xx/image/generic.mk
target/linux/mediatek/image/mt7622.mk
target/linux/ramips/image/Makefile

index d07c8827619fc2cb3deafa9970cf9099f23492d3..0f292d15ee364a173a6ef79a5021af22aebfbbb0 100644 (file)
@@ -215,7 +215,7 @@ endef
 
 define Build/check-size
        @imagesize="$$(stat -c%s $@)"; \
-       limitsize="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
+       limitsize="$$(($(call exp_units,$(if $(1),$(1),$(IMAGE_SIZE)))))"; \
        [ $$limitsize -ge $$imagesize ] || { \
                $(call ERROR_MESSAGE,    WARNING: Image file $@ is too big: $$imagesize > $$limitsize); \
                rm -f $@; \
@@ -466,8 +466,8 @@ endef
 define Build/pad-offset
        let \
                size="$$(stat -c%s $@)" \
-               pad="$(subst k,* 1024,$(word 1, $(1)))" \
-               offset="$(subst k,* 1024,$(word 2, $(1)))" \
+               pad="$(call exp_units,$(word 1, $(1)))" \
+               offset="$(call exp_units,$(word 2, $(1)))" \
                pad="(pad - ((size + offset) % pad)) % pad" \
                newsize='size + pad'; \
                dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
@@ -629,7 +629,7 @@ endef
 
 define Build/zyxel-ras-image
        let \
-               newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
+               newsize="$(call exp_units,$(RAS_ROOTFS_SIZE))"; \
                $(STAGING_DIR_HOST)/bin/mkrasimage \
                        -b $(RAS_BOARD) \
                        -v $(RAS_VERSION) \
index 4ebff2e9ae0424b54ccf47657b6626def5ed13d7..ef52337deea3369e5e898b689994c2c9ec7180f2 100644 (file)
@@ -20,6 +20,8 @@ include $(INCLUDE_DIR)/rootfs.mk
 override MAKE:=$(_SINGLE)$(SUBMAKE)
 override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
 
+exp_units = $(subst k, * 1024,$(subst m, * 1024k,$(subst g, * 1024m,$(1))))
+
 target_params = $(subst +,$(space),$*)
 param_get = $(patsubst $(1)=%,%,$(filter $(1)=%,$(2)))
 param_get_default = $(firstword $(call param_get,$(1),$(2)) $(3))
index e435806c7bb4b8fba6076673133204a64b1be6b1..68c410556151304f8fb5e7b6df57c17363fa3508 100644 (file)
@@ -85,7 +85,7 @@ define Build/mkmylofw_16m
 
        let \
                size="$$(stat -c%s $@)" \
-               pad="$(subst k,* 1024,$(BLOCKSIZE))" \
+               pad="$(call exp_units,$(BLOCKSIZE))" \
                pad="(pad - (size % pad)) % pad" \
                newsize='size + pad' ; \
                [ $$newsize -lt $$((0x660000)) ] && newsize=0x660000 ; \
index 5c9e190e193a63711c3681bcd3f069fa895c0fba..bf2b1a1f8ab15e869a58130583d9d1ff0df0de2c 100644 (file)
@@ -32,7 +32,7 @@ endef
 
 define Build/zyxel-factory
        let \
-               maxsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
+               maxsize="$(call exp_units,$(RAS_ROOTFS_SIZE))"; \
                let size="$$(stat -c%s $@)"; \
                if [ $$size -lt $$maxsize ]; then \
                        $(STAGING_DIR_HOST)/bin/mkrasimage \
index 1757684a7c185be00f754ab4b90c5190bb7d685c..b4719033c0a54e8531207967286984359fdf1786 100644 (file)
@@ -68,7 +68,7 @@ define Build/mkmylofw_32m
 
        let \
                size="$$(stat -c%s $@)" \
-               pad="$(subst k,* 1024,$(BLOCKSIZE))" \
+               pad="$(call exp_units,$(BLOCKSIZE))" \
                pad="(pad - (size % pad)) % pad" \
                newsize='size + pad'; \
                $(STAGING_DIR_HOST)/bin/mkmylofw \
index e362e7428bd6004aff0bf6eb909233452e5f03fd..d0f5280dcf74effe7c0842474b103e54e2311222 100644 (file)
@@ -21,7 +21,7 @@ define Build/buffalo-trx
                -f $(kern_bin) \
                $(if $(rtfs_bin),\
                        -a 0x20000 \
-                       -b $$(( $(subst k, * 1024,$(kern_size)) )) \
+                       -b $$(( $(call exp_units,$(kern_size)) )) \
                        -f $(rtfs_bin),) \
                $(if $(apnd_bin),\
                        -A $(apnd_bin) \
index 265e9fb5e0c33aa403bb7678452ef11544b2ee33..fdc15aa1efc3ce016c31001f23253cdf61a16e45 100644 (file)
@@ -31,7 +31,7 @@ KERNEL_DTB = kernel-bin | append-dtb | lzma
 
 define Build/jcg-header
        $(STAGING_DIR_HOST)/bin/jcgimage -v $(1) \
-               $(if $(JCG_MAXSIZE), -m $$(($(subst k, * 1024,$(JCG_MAXSIZE)))),) \
+               $(if $(JCG_MAXSIZE), -m $$(($(call exp_units,$(JCG_MAXSIZE)))),) \
                -u $@ -o $@.new
        mv $@.new $@
 endef
@@ -142,7 +142,7 @@ endef
 define Build/trx
        $(STAGING_DIR_HOST)/bin/trx $(1) \
                -o $@ \
-               -m $$(($(subst k, * 1024,$(IMAGE_SIZE)))) \
+               -m $$(($(call exp_units,$(IMAGE_SIZE)))) \
                -f $(IMAGE_KERNEL) \
                -a 4 -f $(IMAGE_ROOTFS)
 endef