mediatek: add support for TP-Link TL-XDR3230 v1 xdr3230
authorChuanhong Guo <gch981213@gmail.com>
Sat, 30 Apr 2022 12:24:52 +0000 (20:24 +0800)
committerChuanhong Guo <gch981213@gmail.com>
Mon, 26 Feb 2024 03:44:38 +0000 (11:44 +0800)
commitf2aed118798d3cf5633c75b52831f14f6457893b
tree89683b604bf36412c387211cee10b7cae1fad1e1
parent2d972676f8d5f36e89b42c4a006da3fa7e4a9f49
mediatek: add support for TP-Link TL-XDR3230 v1

Specifications:
- SoC: Mediatek MT7622B
- RAM: 256M
- Flash: EN25QH128 16M
- Ethernet: RTL8367S 4xGE
- WiFi: MT7622 2.4G 4x4 + MT7905 5G 4x4

Flash instruction:
TP-Link locks down their firmware and serial console, so the firmware
in this patch must be flashed with an SPI flash programmer.

1. Desolder the flash and backup the original flash content with a flash
   programmer.
2. Save the following script as gen_image.sh:
===========Script begins here==========

FULLFLASH=$1
IMG_DIR=$2
OUTPUT=$3
BL2=${IMG_DIR}/openwrt-mediatek-mt7622-tplink_tl-xdr3230-v1-preloader.bin
FIP=${IMG_DIR}/openwrt-mediatek-mt7622-tplink_tl-xdr3230-v1-bl31-uboot.fip
FW=${IMG_DIR}/openwrt-mediatek-mt7622-tplink_tl-xdr3230-v1-squashfs-sysupgrade.bin

macaddr_add() {
        local mac=$1
        local val=$2
        local oui=${mac%:*:*:*}
        local nic=${mac#*:*:*:}

        nic=$(printf "%06x" $((0x${nic//:/} + val & 0xffffff)) | sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/')
        echo $oui:$nic
}

macaddr_2bin() {
        local mac=$1

        echo -ne \\x${mac//:/\\x}
}

dd if=/dev/zero bs=4k count=236 | tr "\000" "\377" > ${OUTPUT}
dd conv=notrunc if=${BL2} of=${OUTPUT} bs=4k
dd conv=notrunc if=${FIP} of=${OUTPUT} bs=4k seek=32
dd conv=notrunc if=${FULLFLASH} of=${OUTPUT} bs=4k seek=112 skip=110 count=2

MAC=$(hexdump -v -n 6 -s 0x6d81c -e '5/1 "%02x:" 1/1 "%02x"' ${FULLFLASH})
macaddr_2bin ${MAC} | dd conv=notrunc of=${OUTPUT} bs=1 seek=458756 count=6
MAC_5G=$(macaddr_add ${MAC} 2)
macaddr_2bin ${MAC_5G} | dd conv=notrunc of=${OUTPUT} bs=1 seek=462852 count=6
dd conv=notrunc if=${FW} of=${OUTPUT} bs=64k seek=8

===========Script ends here==========
3. generate a image for flash programmer:
   ./gen_image.sh original_flash_backup.bin openwrt/bin/targets/mediatek/mt7622 output_image.bin
4. flash the generated output_image.bin with a flash programmer and
   solder the chip back onto the device.
target/linux/mediatek/dts/mt7622-tplink_tl-xdr3230-v1.dts [new file with mode: 0644]
target/linux/mediatek/image/mt7622.mk
target/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh