ramips: add support for I-O DATA WN-DX1167R
[openwrt/staging/chunkeey.git] / target / linux / ramips / image / mt7621.mk
index be2a32952488b09123e1c86b698c651ea23bf27d..b66842e88073959ccee802fdc4ce8cd1230b47db 100644 (file)
@@ -2,10 +2,26 @@
 # MT7621 Profiles
 #
 
+include ./common-tp-link.mk
+
 DEFAULT_SOC := mt7621
 
 KERNEL_DTB += -d21
-DEVICE_VARS += TPLINK_BOARD_ID TPLINK_HEADER_VERSION TPLINK_HWID TPLINK_HWREV
+DEVICE_VARS += UIMAGE_MAGIC
+
+# The OEM webinterface expects an kernel with initramfs which has the uImage
+# header field ih_name.
+# We don't want to set the header name field for the kernel include in the
+# sysupgrade image as well, as this image shouldn't be accepted by the OEM
+# webinterface. It will soft-brick the board.
+define Build/custom-initramfs-uimage
+       mkimage -A $(LINUX_KARCH) \
+               -O linux -T kernel \
+               -C lzma -a $(KERNEL_LOADADDR) $(if $(UIMAGE_MAGIC),-M $(UIMAGE_MAGIC),) \
+               -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
+               -n '$(1)' -d $@ $@.new
+       mv $@.new $@
+endef
 
 define Build/elecom-gst-factory
   $(eval product=$(word 1,$(1)))
@@ -49,6 +65,22 @@ define Build/iodata-factory
        fi
 endef
 
+define Build/iodata-mstc-header
+  ( \
+    data_size_crc="$$(dd if=$@ ibs=64 skip=1 2>/dev/null | \
+      gzip -c | tail -c 8 | od -An -tx8 --endian little | tr -d ' \n')"; \
+    echo -ne "$$(echo $$data_size_crc | sed 's/../\\x&/g')" | \
+      dd of=$@ bs=8 count=1 seek=7 conv=notrunc 2>/dev/null; \
+  )
+  dd if=/dev/zero of=$@ bs=4 count=1 seek=1 conv=notrunc 2>/dev/null
+  ( \
+    header_crc="$$(dd if=$@ bs=64 count=1 2>/dev/null | \
+      gzip -c | tail -c 8 | od -An -N4 -tx4 --endian little | tr -d ' \n')"; \
+    echo -ne "$$(echo $$header_crc | sed 's/../\\x&/g')" | \
+      dd of=$@ bs=4 count=1 seek=1 conv=notrunc 2>/dev/null; \
+  )
+endef
+
 define Build/ubnt-erx-factory-image
        if [ -e $(KDIR)/tmp/$(KERNEL_INITRAMFS_IMAGE) -a "$$(stat -c%s $@)" -lt "$(KERNEL_SIZE)" ]; then \
                echo '21001:6' > $(1).compat; \
@@ -73,19 +105,6 @@ define Build/ubnt-erx-factory-image
        fi
 endef
 
-# The OEM webinterface expects an kernel with initramfs which has the uImage
-# header field ih_name.
-# We don't wan't to set the header name field for the kernel include in the
-# sysupgrade image as well, as this image shouldn't be accepted by the OEM
-# webinterface. It will soft-brick the board.
-define Build/wr1201-factory-header
-       mkimage -A $(LINUX_KARCH) \
-               -O linux -T kernel \
-               -C lzma -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
-               -n 'WR1201_8_128' -d $@ $@.new
-       mv $@.new $@
-endef
-
 define Device/afoundry_ew1200
   IMAGE_SIZE := 16064k
   DEVICE_VENDOR := AFOUNDRY
@@ -333,6 +352,22 @@ define Device/iodata_wn-ax1167gr
 endef
 TARGET_DEVICES += iodata_wn-ax1167gr
 
+define Device/iodata_wn-dx1167r
+  BLOCKSIZE := 128k
+  PAGESIZE := 2048
+  UBINIZE_OPTS := -E 5
+  UIMAGE_MAGIC := 0x434f4d43
+  KERNEL_SIZE := 4096k
+  IMAGE_SIZE := 51200k
+  DEVICE_VENDOR := I-O DATA
+  DEVICE_MODEL := WN-DX1167R
+  KERNEL_INITRAMFS := $(KERNEL_DTB) | custom-initramfs-uimage 3.10(XIK.1)b10 | \
+       iodata-mstc-header
+  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
+  DEVICE_PACKAGES := kmod-mt7615e wpad-basic
+endef
+TARGET_DEVICES += iodata_wn-dx1167r
+
 define Device/iodata_wn-gx300gr
   IMAGE_SIZE := 7616k
   DEVICE_VENDOR := I-O DATA
@@ -465,7 +500,7 @@ define Device/mtc_wr1201
   IMAGE_SIZE := 16000k
   DEVICE_VENDOR := MTC
   DEVICE_MODEL := Wireless Router WR1201
-  KERNEL_INITRAMFS := $(KERNEL_DTB) | wr1201-factory-header
+  KERNEL_INITRAMFS := $(KERNEL_DTB) | custom-initramfs-uimage WR1201_8_128
   DEVICE_PACKAGES := kmod-sdhci-mt7620 kmod-mt76x2 kmod-usb3 \
        kmod-usb-ledtrig-usbport wpad-basic
 endef
@@ -662,19 +697,6 @@ define Device/adslr_g7
 endef
 TARGET_DEVICES += adslr_g7
 
-define Device/tplink-safeloader
-  DEVICE_VENDOR := TP-Link
-  TPLINK_BOARD_ID :=
-  TPLINK_HWID := 0x0
-  TPLINK_HWREV := 0
-  TPLINK_HEADER_VERSION := 1
-  KERNEL := $(KERNEL_DTB) | tplink-v1-header -e -O
-  IMAGES += factory.bin
-  IMAGE/sysupgrade.bin := append-rootfs | tplink-safeloader sysupgrade | \
-       append-metadata | check-size $$$$(IMAGE_SIZE)
-  IMAGE/factory.bin := append-rootfs | tplink-safeloader factory
-endef
-
 define Device/tplink_re350-v1
   $(Device/tplink-safeloader)
   DEVICE_MODEL := RE350