aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/mediatek/mt7622
diff options
context:
space:
mode:
authorINAGAKI Hiroshi <musashino.open@gmail.com>2021-03-07 18:36:16 +0100
committerHauke Mehrtens <hauke@hauke-m.de>2021-03-15 17:02:17 +0100
commit74f15628dd8c4b00071f7a94996ff9b695a6bd7a (patch)
tree510bd25ea48cf6d57b0b5c246a8fcb531e5189f4 /target/linux/mediatek/mt7622
parent58c5e256648293fee08792098f1d8643ceedf7fd (diff)
downloadupstream-74f15628dd8c4b00071f7a94996ff9b695a6bd7a.tar.gz
upstream-74f15628dd8c4b00071f7a94996ff9b695a6bd7a.tar.bz2
upstream-74f15628dd8c4b00071f7a94996ff9b695a6bd7a.zip
mediatek: add support for Buffalo WSR-2533DHP2
This adds support for the Buffalo WSR-2533DHP2. The device uses the Broadcom TRX image format with a special magic. To be able to boot the images or load them they have to be wrapped with different headers depending how it is loaded. There are multiple ways to install OpenWrt on this device. Boot ramdisk from U-Boot ---------------------------- This will load the image and not write it into the flash. 1. Stop boot menu with "space" key 2. Select "System Load Linux to SDRAM via TFTP." 3. Load this image: openwrt-mediatek-mt7622-buffalo_wsr-2533dhp2-initramfs-kernel.bin 4. The system boots the image Write to flash from U-Boot ----------------------------- This will load the image over tftp and directly write it into the flash. 1. Stop boot menu with "space" key 2. Select "System Load Linux Kernel then write to Flash via TFTP." 3. Load this image: openwrt-mediatek-mt7622-buffalo_wsr-2533dhp2-squashfs-factory-uboot.bin 4. The system writes this image into the flash and boots into it. Write to flash from Web UI ----------------------------- This will load the image over over the Web UI and write it into the flash 1. Open the Web UI 2. Go to "管理" -> "ファームウェア更新" 3. Select "ローカルファイル指定" and click "更新実行" 4. Load this image: openwrt-mediatek-mt7622-buffalo_wsr-2533dhp2-squashfs-factory.bin 5. The system writes this image into the flash and boots into it. Specifications ------------------- * SoC: MT7622 (4x4 2.4 GHz Wifi) * Wifi: MT7615 (4x4 5 GHz Wifi) * Flash: Winbond W29N01HZ 128MB SLC NAND * RAM 256MB * Ethernet: Realtek RTL8367S (5 x 1GBit/s, SoC via 2.5GBit/s) Co-Developed-by: Hauke Mehrtens <hauke@hauke-m.de> Signed-off-by: INAGAKI Hiroshi <musashino.open@gmail.com> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Diffstat (limited to 'target/linux/mediatek/mt7622')
-rw-r--r--target/linux/mediatek/mt7622/base-files/etc/board.d/02_network4
-rw-r--r--target/linux/mediatek/mt7622/base-files/etc/uci-defaults/09_fix_crc10
-rw-r--r--target/linux/mediatek/mt7622/base-files/lib/upgrade/buffalo.sh126
-rwxr-xr-xtarget/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh15
-rw-r--r--target/linux/mediatek/mt7622/config-5.101
5 files changed, 156 insertions, 0 deletions
diff --git a/target/linux/mediatek/mt7622/base-files/etc/board.d/02_network b/target/linux/mediatek/mt7622/base-files/etc/board.d/02_network
index f537ccdb80..f1daa2fae1 100644
--- a/target/linux/mediatek/mt7622/base-files/etc/board.d/02_network
+++ b/target/linux/mediatek/mt7622/base-files/etc/board.d/02_network
@@ -14,6 +14,10 @@ mediatek_setup_interfaces()
mediatek,mt7622-rfb1)
ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" wan
;;
+ buffalo,wsr-2533dhp2)
+ ucidef_add_switch "switch0" \
+ "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
+ ;;
ubnt,unifi-6-lr)
ucidef_set_interfaces_lan "eth0"
;;
diff --git a/target/linux/mediatek/mt7622/base-files/etc/uci-defaults/09_fix_crc b/target/linux/mediatek/mt7622/base-files/etc/uci-defaults/09_fix_crc
new file mode 100644
index 0000000000..81cb6b18b7
--- /dev/null
+++ b/target/linux/mediatek/mt7622/base-files/etc/uci-defaults/09_fix_crc
@@ -0,0 +1,10 @@
+. /lib/functions.sh
+
+kernel_size=$(sed -n 's/mtd[0-9]*: \([0-9a-f]*\).*"\(kernel\|linux\)".*/\1/p' /proc/mtd)
+
+case "$(board_name)" in
+buffalo,wsr-2533dhp2)
+ mtd -M 0x44485032 ${kernel_size:+-c 0x$kernel_size} fixtrx firmware && exit 0
+ exit 1
+ ;;
+esac
diff --git a/target/linux/mediatek/mt7622/base-files/lib/upgrade/buffalo.sh b/target/linux/mediatek/mt7622/base-files/lib/upgrade/buffalo.sh
new file mode 100644
index 0000000000..844cc4ed95
--- /dev/null
+++ b/target/linux/mediatek/mt7622/base-files/lib/upgrade/buffalo.sh
@@ -0,0 +1,126 @@
+# ======== dev note ========
+# for following buffalo MT7622 devices:
+#
+# - WSR-2533DHP2 (trx magic: "DHP2")
+# - WSR-2533DHP3 (trx magic: "DHP3")
+# - WSR-3200AX4S (trx magic: "DHP3")
+#
+# sysupgrade-tar image:
+#
+# This is for normal upgrading for OpenWrt.
+# use nand_do_upgrade with CI_KERNPART="firmware"
+#
+# - if the size of new kernel is not equal with the current kernel's
+# -> block upgrade and print a message about using TRX + UBI
+# formatted image
+# (should be flashed the new ubi contains rootfs + rootfs_data
+# with the offset (=new padded kernel's end) if this case? But
+# it maybe too hard for writing scripts...)
+#
+# TRX + UBI formatted image:
+#
+# This is for upgrading if the new kernel is larger than the
+# current kernel.
+#
+# ex:
+# - stock firmware is installed in the flash and booted with
+# OpenWrt initramfs image
+# - kernel partition is increased from 4MiB in OpenWrt in the
+# future
+#
+# packing TRX + UBI formatted image by tar is needed for image validation
+# with the metadata in the future?
+# ====== dev note end ======
+#
+# The mtd partitions "firmware" and "Kernel2" on NAND flash are os-image
+# partitions. These partitions are called as "Image1/Image2" in U-Boot
+# on WSR-2533DHP2, and they are checked conditions when booting.
+# "Image1" is always used for booting.
+#
+# == U-Boot Behaviors ==
+# - "Image1"/"Image2" images are good, images are different or
+# "Image2" image is broken
+# -> writes os-image to "Image2" from "Image1"
+#
+# - "Image1" image is broken
+# -> writes os-image to "Image1" from "Image2"
+#
+# - "Image1"/"Image2" images are broken
+# -> fall to U-Boot command line
+
+buffalo_check_image() {
+ local board="$1"
+ local boardname="$(echo $board | tr ',' '_')"
+ local magic="$2"
+ local fw_image="$3"
+
+ # return error state if TRX + UBI formatted image specified
+ # to notify about configurations
+ if [ "$magic" = "44485032" -o "$magic" = "44485033" ]; then
+ echo "Your configurations won't be saved if factory-uboot.bin image specified."
+ echo "But if you want to upgrade, please execute sysupgrade with \"-F\" option."
+ return 1
+ fi
+
+ # check if valid tar file specifed
+ if ! tar tf "$fw_image" &>/dev/null; then
+ echo "Specified file is not a tar archive: $fw_image"
+ return 1
+ fi
+
+ local control_len=$( (tar xf $fw_image sysupgrade-$boardname/CONTROL -O | wc -c) 2> /dev/null)
+
+ # check if valid sysupgrade tar archive
+ if [ "$control_len" = "0" ]; then
+ echo "Invalid sysupgrade file: $fw_image"
+ return 1
+ fi
+
+ local kern_part_len=$(grep "\"linux\"" /proc/mtd | sed "s/mtd[0-9]*:[ \t]*\([^ \t]*\).*/\1/")
+ [ -z "$kern_part_len" ] && {
+ echo "Unable to get \"linux\" partition size"
+ return 1
+ }
+ kern_part_len=$((0x$kern_part_len))
+
+ # this also checks if the sysupgrade image is for correct models
+ local kern_bin_len=$( (tar xf $fw_image sysupgrade-${boardname}/kernel -O | wc -c) 2> /dev/null)
+ if [ -z "$kern_bin_len" ]; then
+ echo "Failed to get new kernel size, is valid sysupgrade image specified for the device?"
+ return 1
+ fi
+
+ # kernel binary has a trx header (len: 28 (0x1c))
+ kern_bin_len=$((kern_bin_len - 28))
+
+ if [ "$kern_bin_len" != "$kern_part_len" ]; then
+ echo -n "The length of new kernel is invalid for current "
+ echo "\"linux\" partition, please use factory-uboot.bin image."
+ echo "\"linux\" partition: $kern_part_len, new kernel: $kern_bin_len"
+ return 1
+ fi
+}
+
+# for TRX + UBI formatted image
+buffalo_upgrade_ubinized() {
+ sync
+ echo 3 > /proc/sys/vm/drop_caches
+
+ local mtdnum="$( find_mtd_index "ubi" )"
+ # if no "ubi", don't return error for the purpose of recovery
+ # ex: recovery after accidental erasing "firmware" partition
+ if [ ! "$mtdnum" ]; then
+ echo "cannot find ubi mtd partition \"ubi\", skip detachment"
+ else
+ ubidetach -m "$mtdnum"
+ fi
+
+ # erase all data in "firmware"
+ mtd erase "${PART_NAME}"
+ # write TRX + UBI formatted image to "firmware"
+ get_image "$1" | mtd $MTD_ARGS write - "${PART_NAME:-firmware}"
+ if [ $? -ne 0 ]; then
+ echo "Failed to write the specified image."
+ exit 1
+ fi
+}
diff --git a/target/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh b/target/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh
index 87852881bf..97a492c7fb 100755
--- a/target/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh
+++ b/target/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh
@@ -56,6 +56,18 @@ platform_do_upgrade() {
get_image "$1" | dd of=/dev/$fitpart
echo $rootdev > /tmp/sysupgrade.rootdev
;;
+ buffalo,wsr-2533dhp2)
+ local magic="$(get_magic_long "$1")"
+
+ # use "mtd write" if the magic is "DHP2 (0x44485032)"
+ # or "DHP3 (0x44485033)"
+ if [ "$magic" = "44485032" -o "$magic" = "44485033" ]; then
+ buffalo_upgrade_ubinized "$1"
+ else
+ CI_KERNPART="firmware"
+ nand_do_upgrade "$1"
+ fi
+ ;;
linksys,e8450-ubi|\
mediatek,mt7622,ubi)
CI_KERNPART="fit"
@@ -84,6 +96,9 @@ platform_check_image() {
[ "$#" -gt 1 ] && return 1
case "$board" in
+ buffalo,wsr-2533dhp2)
+ buffalo_check_image "$board" "$magic" "$1" || return 1
+ ;;
*)
[ "$magic" != "d00dfeed" ] && {
echo "Invalid image type."
diff --git a/target/linux/mediatek/mt7622/config-5.10 b/target/linux/mediatek/mt7622/config-5.10
index 5d80056365..b899d9dbbb 100644
--- a/target/linux/mediatek/mt7622/config-5.10
+++ b/target/linux/mediatek/mt7622/config-5.10
@@ -247,6 +247,7 @@ CONFIG_MTD_NAND_MTK_BMT=y
CONFIG_MTD_RAW_NAND=y
CONFIG_MTD_SPI_NAND=y
CONFIG_MTD_SPI_NOR=y
+CONFIG_MTD_PARSER_TRX=y
CONFIG_MTD_SPLIT_FIRMWARE=y
CONFIG_MTD_SPLIT_FIT_FW=y
CONFIG_MTD_UBI=y