mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-18 21:28:02 +00:00
image: use helper function for size units
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>
This commit is contained in:
parent
c66511bc48
commit
b16e14a220
@ -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) \
|
||||
|
@ -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))
|
||||
|
@ -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 ; \
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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) \
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user