openwrtv4/target/linux/ramips/image/mt76x8.mk
Koen Vandeputte b4e17a7440 ramips: fix netgear r6120 factory image generation
as indicated in commit c5bf408ed6 "(ramips: fix image generation for mt76x8")
more rework was needed to fix the other issues.

Building on another machine, but using the same arch, showed
the application failing again for different reasons.

Fix this by completely rewriting the application, fixing following found issues:

- buffer overflows, resulting in stack corruption
- flaws in memory requirement calculations (too small, too large)
- memory leaks
- missing bounds checking on string handling
- non-reproducable images, by using unitilized memory in checksum calculation
- missing error handling, resulting in succes on specific image errors
- endianness errors when building on BE machines
- various minor build warnings
- documentation did not match the code actions (header item locations)
- allowing input to be decimal, hex or octal now

Signed-off-by: Koen Vandeputte <koen.vandeputte@ncentric.com>
2018-11-08 13:32:22 +01:00

389 lines
10 KiB
Makefile

#
# MT76x8 Profiles
#
DEVICE_VARS += SERCOMM_KERNEL_OFFSET SERCOMM_HWID SERCOMM_HWVER SERCOMM_SWVER
define Build/mksercommfw
$(STAGING_DIR_HOST)/bin/mksercommfw \
$@ \
$(SERCOMM_KERNEL_OFFSET) \
$(SERCOMM_HWID) \
$(SERCOMM_HWVER) \
$(SERCOMM_SWVER)
endef
define Device/tplink
TPLINK_FLASHLAYOUT :=
TPLINK_HWID :=
TPLINK_HWREV :=
TPLINK_HWREVADD :=
TPLINK_HVERSION :=
KERNEL := $(KERNEL_DTB)
KERNEL_INITRAMFS := $(KERNEL_DTB) | tplink-v2-header -e
IMAGES += tftp-recovery.bin
IMAGE/factory.bin := tplink-v2-image -e
IMAGE/tftp-recovery.bin := pad-extra 128k | $$(IMAGE/factory.bin)
IMAGE/sysupgrade.bin := tplink-v2-image -s -e | append-metadata | \
check-size $$$$(IMAGE_SIZE)
endef
DEVICE_VARS += TPLINK_FLASHLAYOUT TPLINK_HWID TPLINK_HWREV TPLINK_HWREVADD TPLINK_HVERSION
define Device/alfa-network_awusfree1
DTS := AWUSFREE1
IMAGE_SIZE := $(ralink_default_fw_size_8M)
DEVICE_TITLE := ALFA Network AWUSFREE1
DEVICE_PACKAGES := uboot-envtools
endef
TARGET_DEVICES += alfa-network_awusfree1
define Device/tama_w06
DTS := W06
IMAGE_SIZE := 15040k
DEVICE_TITLE := Tama W06
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci
endef
TARGET_DEVICES += tama_w06
define Device/duzun-dm06
DTS := DUZUN-DM06
DEVICE_TITLE := DuZun DM06
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += duzun-dm06
define Device/gl-mt300n-v2
DTS := GL-MT300N-V2
IMAGE_SIZE := 16064k
DEVICE_TITLE := GL-iNet GL-MT300N-V2
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci
endef
TARGET_DEVICES += gl-mt300n-v2
define Device/hc5661a
DTS := HC5661A
IMAGE_SIZE := $(ralink_default_fw_size_16M)
DEVICE_TITLE := HiWiFi HC5661A
DEVICE_PACKAGES := kmod-sdhci-mt7620
endef
TARGET_DEVICES += hc5661a
define Device/hiwifi_hc5861b
DTS := HC5861B
IMAGE_SIZE := 15808k
DEVICE_TITLE := HiWiFi HC5861B
endef
TARGET_DEVICES += hiwifi_hc5861b
define Device/LinkIt7688
DTS := LINKIT7688
IMAGE_SIZE := $(ralink_default_fw_size_32M)
SUPPORTED_DEVICES := linkits7688 linkits7688d
DEVICE_TITLE := MediaTek LinkIt Smart 7688
DEVICE_PACKAGES:= kmod-usb2 kmod-usb-ohci uboot-envtools
endef
TARGET_DEVICES += LinkIt7688
define Device/mac1200r-v2
DTS := MAC1200RV2
DEVICE_TITLE := Mercury MAC1200R v2.0
SUPPORTED_DEVICES := mac1200rv2
endef
TARGET_DEVICES += mac1200r-v2
define Device/miwifi-nano
DTS := MIWIFI-NANO
IMAGE_SIZE := $(ralink_default_fw_size_16M)
DEVICE_TITLE := Xiaomi MiWiFi Nano
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += miwifi-nano
define Device/mt7628
DTS := MT7628
BLOCKSIZE := 64k
IMAGE_SIZE := $(ralink_default_fw_size_4M)
DEVICE_TITLE := MediaTek MT7628 EVB
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += mt7628
define Device/netgear_r6120
DTS := R6120
BLOCKSIZE := 64k
IMAGE_SIZE := $(ralink_default_fw_size_16M)
DEVICE_TITLE := Netgear AC1200 R6120
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci
SERCOMM_KERNEL_OFFSET := 0x90000
SERCOMM_HWID := CGQ
SERCOMM_HWVER := A001
SERCOMM_SWVER := 0x0040
IMAGES += factory.img
IMAGE/default := append-kernel | pad-to $$$$(BLOCKSIZE)| append-rootfs | pad-rootfs
IMAGE/sysupgrade.bin := $$(IMAGE/default) | append-metadata | check-size $$$$(IMAGE_SIZE)
IMAGE/factory.img := $$(IMAGE/default) | mksercommfw
endef
TARGET_DEVICES += netgear_r6120
define Device/omega2
DTS := OMEGA2
IMAGE_SIZE := $(ralink_default_fw_size_16M)
DEVICE_TITLE := Onion Omega2
DEVICE_PACKAGES:= kmod-usb2 kmod-usb-ohci uboot-envtools
endef
TARGET_DEVICES += omega2
define Device/omega2p
DTS := OMEGA2P
IMAGE_SIZE := $(ralink_default_fw_size_32M)
DEVICE_TITLE := Onion Omega2+
DEVICE_PACKAGES:= kmod-usb2 kmod-usb-ohci uboot-envtools kmod-sdhci-mt7620
endef
TARGET_DEVICES += omega2p
define Device/pbr-d1
DTS := PBR-D1
IMAGE_SIZE := $(ralink_default_fw_size_16M)
DEVICE_TITLE := PBR-D1
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci
endef
TARGET_DEVICES += pbr-d1
define Device/tplink_tl-wa801nd-v5
$(Device/tplink)
DTS := TL-WA801NDV5
IMAGE_SIZE := 7808k
DEVICE_TITLE := TP-Link TL-WA801ND v5
TPLINK_FLASHLAYOUT := 8Mmtk
TPLINK_HWID := 0x08010005
TPLINK_HWREV := 0x1
TPLINK_HWREVADD := 0x5
TPLINK_HVERSION := 3
endef
TARGET_DEVICES += tplink_tl-wa801nd-v5
define Device/tl-wr840n-v4
$(Device/tplink)
DTS := TL-WR840NV4
IMAGE_SIZE := 7808k
DEVICE_TITLE := TP-Link TL-WR840N v4
TPLINK_FLASHLAYOUT := 8Mmtk
TPLINK_HWID := 0x08400004
TPLINK_HWREV := 0x1
TPLINK_HWREVADD := 0x4
TPLINK_HVERSION := 3
endef
TARGET_DEVICES += tl-wr840n-v4
define Device/tl-wr840n-v5
DTS := TL-WR840NV5
IMAGE_SIZE := 3904k
DEVICE_TITLE := TP-Link TL-WR840N v5
TPLINK_FLASHLAYOUT := 4Mmtk
TPLINK_HWID := 0x08400005
TPLINK_HWREV := 0x1
TPLINK_HWREVADD := 0x5
TPLINK_HVERSION := 3
KERNEL := $(KERNEL_DTB)
KERNEL_INITRAMFS := $(KERNEL_DTB) | tplink-v2-header -e
IMAGE/sysupgrade.bin := tplink-v2-image -s -e | append-metadata | \
check-size $$$$(IMAGE_SIZE)
endef
TARGET_DEVICES += tl-wr840n-v5
define Device/tl-wr841n-v13
$(Device/tplink)
DTS := TL-WR841NV13
IMAGE_SIZE := 7808k
DEVICE_TITLE := TP-Link TL-WR841N v13
TPLINK_FLASHLAYOUT := 8Mmtk
TPLINK_HWID := 0x08410013
TPLINK_HWREV := 0x268
TPLINK_HWREVADD := 0x13
TPLINK_HVERSION := 3
endef
TARGET_DEVICES += tl-wr841n-v13
define Device/tplink_c20-v4
$(Device/tplink)
DTS := ArcherC20v4
IMAGE_SIZE := 7808k
DEVICE_TITLE := TP-Link ArcherC20 v4
TPLINK_FLASHLAYOUT := 8Mmtk
TPLINK_HWID := 0xc200004
TPLINK_HWREV := 0x1
TPLINK_HWREVADD := 0x4
TPLINK_HVERSION := 3
endef
TARGET_DEVICES += tplink_c20-v4
define Device/tplink_c50-v3
$(Device/tplink)
DTS := ArcherC50V3
IMAGE_SIZE := 7808k
DEVICE_TITLE := TP-Link ArcherC50 v3
TPLINK_FLASHLAYOUT := 8Mmtk
TPLINK_HWID := 0x001D9BA4
TPLINK_HWREV := 0x79
TPLINK_HWREVADD := 0x1
TPLINK_HVERSION := 3
endef
TARGET_DEVICES += tplink_c50-v3
define Device/tplink_tl-mr3020-v3
$(Device/tplink)
DTS := TL-MR3020V3
IMAGE_SIZE := 7808k
DEVICE_TITLE := TP-Link TL-MR3020 v3
TPLINK_FLASHLAYOUT := 8Mmtk
TPLINK_HWID := 0x30200003
TPLINK_HWREV := 0x3
TPLINK_HWREVADD := 0x3
TPLINK_HVERSION := 3
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += tplink_tl-mr3020-v3
define Device/tplink_tl-mr3420-v5
$(Device/tplink)
DTS := TL-MR3420V5
IMAGE_SIZE := 7808k
DEVICE_TITLE := TP-Link TL-MR3420 v5
TPLINK_FLASHLAYOUT := 8Mmtk
TPLINK_HWID := 0x34200005
TPLINK_HWREV := 0x5
TPLINK_HWREVADD := 0x5
TPLINK_HVERSION := 3
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += tplink_tl-mr3420-v5
define Device/tplink_tl-wr842n-v5
$(Device/tplink)
DTS := TL-WR842NV5
IMAGE_SIZE := 7808k
DEVICE_TITLE := TP-Link TL-WR842N v5
TPLINK_FLASHLAYOUT := 8Mmtk
TPLINK_HWID := 0x08420005
TPLINK_HWREV := 0x5
TPLINK_HWREVADD := 0x5
TPLINK_HVERSION := 3
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += tplink_tl-wr842n-v5
define Device/tplink_tl-wr902ac-v3
$(Device/tplink)
DTS := TL-WR902ACV3
IMAGE_SIZE := 7808k
DEVICE_TITLE := TP-Link TL-WR902AC v3
TPLINK_FLASHLAYOUT := 8Mmtk
TPLINK_HWID := 0x000dc88f
TPLINK_HWREV := 0x89
TPLINK_HWREVADD := 0x1
TPLINK_HVERSION := 3
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += tplink_tl-wr902ac-v3
define Device/u7628-01-128M-16M
DTS := U7628-01-128M-16M
IMAGE_SIZE := 16064k
DEVICE_TITLE := UniElec U7628-01 (128M RAM/16M flash)
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += u7628-01-128M-16M
define Device/vocore2
DTS := VOCORE2
IMAGE_SIZE := $(ralink_default_fw_size_16M)
DEVICE_TITLE := VoCore VoCore2
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport \
kmod-sdhci-mt7620
endef
TARGET_DEVICES += vocore2
define Device/vocore2lite
DTS := VOCORE2LITE
IMAGE_SIZE := $(ralink_default_fw_size_16M)
DEVICE_TITLE := VoCore VoCore2-Lite
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport \
kmod-sdhci-mt7620
endef
TARGET_DEVICES += vocore2lite
define Device/wcr-1166ds
DTS := WCR-1166DS
BUFFALO_TAG_PLATFORM := MTK
BUFFALO_TAG_VERSION := 9.99
BUFFALO_TAG_MINOR := 9.99
IMAGES += factory.bin
IMAGE/sysupgrade.bin := trx | pad-rootfs | append-metadata
IMAGE/factory.bin := \
trx -M 0x746f435c | pad-rootfs | append-metadata | \
buffalo-enc WCR-1166DS $$(BUFFALO_TAG_VERSION) -l | \
buffalo-tag-dhp WCR-1166DS JP JP | buffalo-enc-tag -l | \
buffalo-dhp-image
DEVICE_TITLE := Buffalo WCR-1166DS
endef
TARGET_DEVICES += wcr-1166ds
define Device/wl-wn575a3
DTS := WL-WN575A3
IMAGE_SIZE := $(ralink_default_fw_size_8M)
DEVICE_TITLE := Wavlink WL-WN575A3
endef
TARGET_DEVICES += wl-wn575a3
define Device/widora_neo-16m
DTS := WIDORA-NEO-16M
IMAGE_SIZE := $(ralink_default_fw_size_16M)
DEVICE_TITLE := Widora-NEO (16M)
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci
SUPPORTED_DEVICES += widora-neo
endef
TARGET_DEVICES += widora_neo-16m
define Device/widora_neo-32m
DTS := WIDORA-NEO-32M
IMAGE_SIZE := $(ralink_default_fw_size_32M)
DEVICE_TITLE := Widora-NEO (32M)
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci
endef
TARGET_DEVICES += widora_neo-32m
define Device/wrtnode2p
DTS := WRTNODE2P
IMAGE_SIZE := $(ralink_default_fw_size_16M)
DEVICE_TITLE := WRTnode 2P
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
endef
TARGET_DEVICES += wrtnode2p
define Device/wrtnode2r
DTS := WRTNODE2R
IMAGE_SIZE := $(ralink_default_fw_size_16M)
DEVICE_TITLE := WRTnode 2R
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci
endef
TARGET_DEVICES += wrtnode2r
define Device/zbtlink_zbt-we1226
DTS := ZBT-WE1226
IMAGE_SIZE := $(ralink_default_fw_size_8M)
DEVICE_TITLE := ZBTlink ZBT-WE1226
endef
TARGET_DEVICES += zbtlink_zbt-we1226
define Device/zyxel_keenetic-extra-ii
DTS := ki_rb
IMAGE_SIZE := 14912k
BLOCKSIZE := 64k
DEVICE_TITLE := ZyXEL Keenetic Extra II
DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
IMAGES += factory.bin
IMAGE/factory.bin := $$(IMAGE/sysupgrade.bin) | pad-to $$$$(BLOCKSIZE) | \
check-size $$$$(IMAGE_SIZE) | zyimage -d 6162 -v "ZyXEL Keenetic Extra II"
endef
TARGET_DEVICES += zyxel_keenetic-extra-ii