diff --git a/include/image-commands.mk b/include/image-commands.mk index 6666eddf8f..12cbbb2c2c 100644 --- a/include/image-commands.mk +++ b/include/image-commands.mk @@ -226,6 +226,43 @@ define Build/copy-file cat "$(1)" > "$@" endef +# Create a header for a D-Link AI series recovery image and add it at the beginning of the image +# Currently supported: AQUILA M30, EAGLE M32 and R32 +# Arguments: +# 1: Start string of the header +# 2: Firmware version +# 3: Block start address +# 4: Block length +# 5: Device FMID +define Build/dlink-ai-recovery-header + $(eval header_start=$(word 1,$(1))) + $(eval firmware_version=$(word 2,$(1))) + $(eval block_start=$(word 3,$(1))) + $(eval block_length=$(word 4,$(1))) + $(eval device_fmid=$(word 5,$(1))) +# create $@.header without the checksum + echo -en "$(header_start)\x00\x00" > "$@.header" +# Calculate checksum over data area ($@) and append it to the header. +# The checksum is the 2byte-sum over the whole data area. +# Every overflow during the checksum calculation must increment the current checksum value by 1. + od -v -w2 -tu2 -An --endian little "$@" | awk '{ s+=$$1; } END { s%=65535; printf "%c%c",s%256,s/256; }' >> "$@.header" + echo -en "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00" >> "$@.header" + echo -en "$(firmware_version)" >> "$@.header" +# Only one block supported: Erase start/length is identical to data start/length + echo -en "$(block_start)$(block_length)$(block_start)$(block_length)" >> "$@.header" +# Only zeros + echo -en "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" >> "$@.header" +# Last 16 bytes, but without checksum + echo -en "\x42\x48\x02\x00\x00\x00\x08\x00\x00\x00\x00\x00" >> "$@.header" + echo -en "$(device_fmid)" >> "$@.header" +# Calculate and append checksum: The checksum must be set so that the 2byte-sum of the whole header is 0. +# Every overflow during the checksum calculation must increment the current checksum value by 1. + od -v -w2 -tu2 -An --endian little "$@.header" | awk '{s+=65535-$$1;}END{s%=65535;printf "%c%c",s%256,s/256;}' >> "$@.header" + cat "$@.header" "$@" > "$@.new" + mv "$@.new" "$@" + rm "$@.header" +endef + define Build/dlink-sge-image $(STAGING_DIR_HOST)/bin/dlink-sge-image $(1) $@ $@.enc mv $@.enc $@ diff --git a/target/linux/mediatek/image/mt7622.mk b/target/linux/mediatek/image/mt7622.mk index e3a9dd510f..ce95be1c0c 100644 --- a/target/linux/mediatek/image/mt7622.mk +++ b/target/linux/mediatek/image/mt7622.mk @@ -35,31 +35,19 @@ define Build/bl31-uboot cat $(STAGING_DIR_IMAGE)/mt7622_$1-u-boot.fip >> $@ endef -# Append header to a D-Link M32/R32 Kernel 1 partition -define Build/m32-r32-recovery-header-kernel1 - $(eval header_start=$(word 1,$(1))) -# create $@.header without the checksum - echo -en "$(header_start)\x00\x00" > "$@.header" -# Calculate checksum over data area ($@) and append it to the header. -# The checksum is the 2byte-sum over the whole data area. -# Every overflow during the checksum calculation must increment the current checksum value by 1. - od -v -w2 -tu2 -An --endian little "$@" | awk '{ s+=$$1; } END { s%=65535; printf "%c%c",s%256,s/256; }' >> "$@.header" - echo -en "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x8D\x57\x30\x0B" >> "$@.header" -# Byte 0-3: Erase Start 0x002C0000 -# Byte 4-7: Erase Length 0x02D00000 -# Byte 8-11: Data offset: 0x002C0000 -# Byte 12-15: Data Length: 0x02D00000 - echo -en "\x00\x00\x2C\x00\x00\x00\xD0\x02\x00\x00\x2C\x00\x00\x00\xD0\x02" >> "$@.header" -# Only zeros - echo -en "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" >> "$@.header" -# Last 16 bytes, but without checksum - echo -en "\x42\x48\x02\x00\x00\x00\x08\x00\x00\x00\x00\x00\x60\x6E" >> "$@.header" -# Calculate and append checksum: The checksum must be set so that the 2byte-sum of the whole header is 0. -# Every overflow during the checksum calculation must increment the current checksum value by 1. - od -v -w2 -tu2 -An --endian little "$@.header" | awk '{s+=65535-$$1;}END{s%=65535;printf "%c%c",s%256,s/256;}' >> "$@.header" - cat "$@.header" "$@" > "$@.new" - mv "$@.new" "$@" - rm "$@.header" +define Build/uboot-bin + cat $(STAGING_DIR_IMAGE)/mt7622_$1-u-boot.bin >> $@ +endef + +define Build/uboot-fit + $(TOPDIR)/scripts/mkits.sh \ + -D $(DEVICE_NAME) -o $@.its -k $@ \ + -C $(word 1,$(1)) \ + -a 0x41e00000 -e 0x41e00000 \ + -c "config-1" \ + -A $(LINUX_KARCH) -v u-boot + PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new + @mv $@.new $@ endef define Build/mt7622-gpt @@ -205,7 +193,7 @@ define Device/dlink_eagle-pro-ai-m32-a1 $(Device/dlink_eagle-pro-ai-ax3200-a1) DEVICE_MODEL := EAGLE PRO AI M32 DEVICE_DTS := mt7622-dlink-eagle-pro-ai-m32-a1 - IMAGE/recovery.bin := append-kernel | pad-to $$(KERNEL_SIZE) | append-ubi | pad-to $$(IMAGE_SIZE) | m32-r32-recovery-header-kernel1 DLK6E6010001 + IMAGE/recovery.bin := append-kernel | pad-to $$(KERNEL_SIZE) | append-ubi | pad-to $$(IMAGE_SIZE) | dlink-ai-recovery-header DLK6E6010001 \x8D\x57\x30\x0B \x00\x00\x2C\x00 \x00\x00\xD0\x02 \x60\x6E endef TARGET_DEVICES += dlink_eagle-pro-ai-m32-a1 @@ -213,7 +201,7 @@ define Device/dlink_eagle-pro-ai-r32-a1 $(Device/dlink_eagle-pro-ai-ax3200-a1) DEVICE_MODEL := EAGLE PRO AI R32 DEVICE_DTS := mt7622-dlink-eagle-pro-ai-r32-a1 - IMAGE/recovery.bin := append-kernel | pad-to $$(KERNEL_SIZE) | append-ubi | pad-to $$(IMAGE_SIZE) | m32-r32-recovery-header-kernel1 DLK6E6015001 + IMAGE/recovery.bin := append-kernel | pad-to $$(KERNEL_SIZE) | append-ubi | pad-to $$(IMAGE_SIZE) | dlink-ai-recovery-header DLK6E6015001 \x8D\x57\x30\x0B \x00\x00\x2C\x00 \x00\x00\xD0\x02 \x60\x6E endef TARGET_DEVICES += dlink_eagle-pro-ai-r32-a1