build: avoid failing in append-metadata if image could not be generated
[openwrt/openwrt.git] / include / image-commands.mk
index 160b5d883395d3ef53f4c61426ea27a5dbd3a063..8db046bdea6a928be6152de5b69046b18a02711b 100644 (file)
@@ -7,8 +7,46 @@ define Build/uImage
        mkimage -A $(LINUX_KARCH) \
                -O linux -T kernel \
                -C $(1) -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
-               -n '$(call toupper,$(LINUX_KARCH)) LEDE Linux-$(LINUX_VERSION)' -d $@ $@.new
-       @mv $@.new $@
+               -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) LEDE Linux-$(LINUX_VERSION))' -d $@ $@.new
+       mv $@.new $@
+endef
+
+define Build/buffalo-enc
+       $(eval product=$(word 1,$(1)))
+       $(eval version=$(word 2,$(1)))
+       $(eval args=$(wordlist 3,$(words $(1)),$(1)))
+       $(STAGING_DIR_HOST)/bin/buffalo-enc \
+               -p $(product) -v $(version) $(args) \
+               -i $@ -o $@.new
+       mv $@.new $@
+endef
+
+define Build/buffalo-enc-tag
+       $(call Build/buffalo-enc,'' '' -S 152 $(1))
+endef
+
+define Build/buffalo-tag-dhp
+       $(eval product=$(word 1,$(1)))
+       $(eval region=$(word 2,$(1)))
+       $(eval language=$(word 3,$(1)))
+       $(STAGING_DIR_HOST)/bin/buffalo-tag \
+               -d 0x01000000 -w 1 \
+               -a $(BUFFALO_TAG_PLATFORM) \
+               -v $(BUFFALO_TAG_VERSION) -m $(BUFFALO_TAG_MINOR) \
+               -b $(product) -p $(product) \
+               -r $(region) -r $(region) -l $(language) \
+               -I $@ -o $@.new
+       mv $@.new $@
+endef
+
+define Build/buffalo-dhp-image
+       $(STAGING_DIR_HOST)/bin/mkdhpimg $@ $@.new
+       mv $@.new $@
+endef
+
+define Build/eva-image
+       $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ $@.new
+       mv $@.new $@
 endef
 
 define Build/netgear-chk
@@ -16,7 +54,7 @@ define Build/netgear-chk
                -o $@.new \
                -k $@ \
                -b $(NETGEAR_BOARD_ID) \
-               -r $(NETGEAR_REGION)
+               $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
        mv $@.new $@
 endef
 
@@ -29,9 +67,31 @@ define Build/netgear-dni
        mv $@.new $@
 endef
 
+define Build/append-squashfs-fakeroot-be
+       rm -rf $@.fakefs $@.fakesquashfs
+       mkdir $@.fakefs
+       $(STAGING_DIR_HOST)/bin/mksquashfs-lzma \
+               $@.fakefs $@.fakesquashfs \
+               -noappend -root-owned -be -nopad -b 65536 \
+               $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
+       cat $@.fakesquashfs >> $@
+endef
+
+# append a fake/empty rootfs uImage header, to fool the bootloaders
+# rootfs integrity check
+define Build/append-uImage-fakeroot-hdr
+       rm -f $@.fakeroot
+       $(STAGING_DIR_HOST)/bin/mkimage \
+               -A $(LINUX_KARCH) -O linux -T filesystem -C none \
+               -n '$(call toupper,$(LINUX_KARCH)) LEDE fakeroot' \
+               -s \
+               $@.fakeroot
+       cat $@.fakeroot >> $@
+endef
+
 define Build/tplink-safeloader
        -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
-               -B $(TPLINK_BOARD_NAME) \
+               -B $(TPLINK_BOARD_ID) \
                -V $(REVISION) \
                -k $(IMAGE_KERNEL) \
                -r $@ \
@@ -42,8 +102,7 @@ define Build/tplink-safeloader
 endef
 
 define Build/append-dtb
-       $(call Image/BuildDTB,$(if $(DEVICE_DTS_DIR),$(DEVICE_DTS_DIR),$(DTS_DIR))/$(DEVICE_DTS).dts,$@.dtb)
-       cat $@.dtb >> $@
+       cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
 endef
 
 define Build/install-dtb
@@ -54,12 +113,17 @@ define Build/install-dtb
        )
 endef
 
+define Build/install-zImage
+    $(CP) $(KDIR)/zImage \
+      $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE_SANITIZED)-zImage
+endef
+
 define Build/fit
        $(TOPDIR)/scripts/mkits.sh \
                -D $(DEVICE_NAME) -o $@.its -k $@ \
                $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
                -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
-               -A $(ARCH) -v $(LINUX_VERSION)
+               -A $(LINUX_KARCH) -v $(LINUX_VERSION)
        PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
        @mv $@.new $@
 endef
@@ -103,20 +167,21 @@ define Build/patch-cmdline
 endef
 
 define Build/append-kernel
-       dd if=$(IMAGE_KERNEL) $(if $(1),bs=$(1) conv=sync) >> $@
+       dd if=$(IMAGE_KERNEL) >> $@
 endef
 
 define Build/append-rootfs
-       dd if=$(IMAGE_ROOTFS) $(if $(1),bs=$(1) conv=sync) >> $@
+       dd if=$(IMAGE_ROOTFS) >> $@
 endef
 
 define Build/append-ubi
        sh $(TOPDIR)/scripts/ubinize-image.sh \
                $(if $(UBOOTENV_IN_UBI),--uboot-env) \
                $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
+               $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
                $(IMAGE_ROOTFS) \
                $@.tmp \
-               -p $(BLOCKSIZE) -m $(PAGESIZE) \
+               -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
                $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
                $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
                $(UBINIZE_OPTS)
@@ -129,15 +194,20 @@ define Build/pad-to
        mv $@.new $@
 endef
 
+define Build/pad-extra
+       dd if=/dev/zero bs=$(1) count=1 >> $@
+endef
+
 define Build/pad-rootfs
-       $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) 4 8 16 64 128 256
+       $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
+               $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
 endef
 
 define Build/pad-offset
        let \
                size="$$(stat -c%s $@)" \
-               pad="$(word 1, $(1))" \
-               offset="$(word 2, $(1))" \
+               pad="$(subst k,* 1024,$(word 1, $(1)))" \
+               offset="$(subst k,* 1024,$(word 2, $(1)))" \
                pad="(pad - ((size + offset) % pad)) % pad" \
                newsize='size + pad'; \
                dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
@@ -166,3 +236,55 @@ define Build/sysupgrade-tar
                --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
                $@
 endef
+
+define Build/tplink-v1-header
+       $(STAGING_DIR_HOST)/bin/mktplinkfw \
+               -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
+               -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
+               -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
+               -k $@ -o $@.new $(1)
+       @mv $@.new $@
+endef
+
+define Build/tplink-v2-header
+       $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
+               -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
+               -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR))  \
+               -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
+               -T $(TPLINK_HVERSION) -V "ver. 2.0" \
+               -k $@ -o $@.new $(1)
+       @mv $@.new $@
+endef
+
+define Build/tplink-v2-image
+       $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
+               -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
+               -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
+               -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
+               -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o $@.new $(1)
+       cat $@.new >> $@
+       rm -rf $@.new
+endef
+
+json_quote=$(subst ','\'',$(subst ",\",$(1)))
+#")')
+metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
+metadata_json = \
+       '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
+               "supported_devices":[$(call metadata_devices,$(1))], \
+               "version": { \
+                       "dist": "$(call json_quote,$(VERSION_DIST))", \
+                       "version": "$(call json_quote,$(VERSION_NUMBER))", \
+                       "revision": "$(call json_quote,$(REVISION))", \
+                       "board": "$(call json_quote,$(BOARD))" \
+               } \
+       }'
+
+define Build/append-metadata
+       $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
+endef
+
+define Build/kernel2minor
+       kernel2minor -k $@ -r $@.new $(1)
+       mv $@.new $@
+endef