From patchwork Tue Mar 9 23:52:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hauke Mehrtens X-Patchwork-Id: 1450241 X-Patchwork-Delegate: hauke@hauke-m.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=nAIxEv1u; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=hauke-m.de header.i=@hauke-m.de header.a=rsa-sha256 header.s=MBO0001 header.b=XP4mZoYu; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DwBsP3thYz9sW1 for ; Wed, 10 Mar 2021 10:55:04 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rw/IDSm+NDg3ERvWy5DowP7kiz0WfKJGmv3UjSFWyXA=; b=nAIxEv1u90QRwiHgwyx7B0GlS FP3Jr1FXoaMwSbTNDMNjubN6LtPIl+LkSJg4BAuW3/LNBQnFenVnzuJSJdIV/yfQx8MbToKEN2Jiy FTLMhQL1dc81fjUA+rejByBRWbmcwExOnJ3vrF435dEtbiZNQXywLw71PaPAl3EEAm0ltKvOhiRpR 9HEc7ug6QMZC1v3ZThnlRxloux1DioX1pVuJJwFzDGuZzyVXf77mxwQ0Aih1LQV0KSwh4yJSqcFSt 23+LMU0A3LNYGq5JDKI38xf2bRBKBbo5Two94jFh6astj5ioXhOc2ot6NZcmCMTX7MGjuYNFdL08g ujxMm7tCA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lJmAQ-005f2Q-3E; Tue, 09 Mar 2021 23:53:34 +0000 Received: from mout-p-202.mailbox.org ([2001:67c:2050::465:202]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lJm9g-005ex5-AV for openwrt-devel@lists.openwrt.org; Tue, 09 Mar 2021 23:52:51 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4DwBpl0strzQjn6; Wed, 10 Mar 2021 00:52:47 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hauke-m.de; s=MBO0001; t=1615333965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h4vFAO0Y46LthqlvjEfiR9xFB/0JMV4OXX0YW5cP4Y4=; b=XP4mZoYuZdRQvdQm7lC9qnWS28Hsqm11SE0d0MWHjpoqtWUc1MxOsJkL4eT7L4yLRDOrtt sh6l9QZbw+UGqhbFr4gJ/9QIWa+CtOGtH1Zk68TltKUTGPf4J+ouH3Qb+vHM98JIx9vcos P+0MgeoNI6QnK0XSvuEw/4l54pdBYwjyuud4MtilIiw6qfb8O4o2LtwcWnJK3QW/q/SkTb GLEiqKhoRt9qmXxhefOwBDdrQkz1M0BE7DaARKoQ7xQ5JFSaKW/Z95eeE9DEuKRb6U27Vj itHvRqozRh/S3sXX8Qh2OIiDYoeO8Gbm1412c14qiYsMfEpiB7OqntREoKtgHg== Received: from smtp2.mailbox.org ([80.241.60.241]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id v7Wz64xWam8S; Wed, 10 Mar 2021 00:52:42 +0100 (CET) From: Hauke Mehrtens To: openwrt-devel@lists.openwrt.org Cc: musashino.open@gmail.com, Hauke Mehrtens Subject: [PATCH 5/5] mediatek: Add support for Buffalo WSR-2533DHP2 Date: Wed, 10 Mar 2021 00:52:14 +0100 Message-Id: <20210309235214.1690449-6-hauke@hauke-m.de> In-Reply-To: <20210309235214.1690449-1-hauke@hauke-m.de> References: <20210309235214.1690449-1-hauke@hauke-m.de> MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -2.11 / 15.00 / 15.00 X-Rspamd-Queue-Id: 25F2F17BA X-Rspamd-UID: 6aadc3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210309_235249_095425_8D56A3BC X-CRM114-Status: GOOD ( 19.82 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: INAGAKI Hiroshi 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. Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [2001:67c:2050:0:0:0:465:202 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: INAGAKI Hiroshi 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. 1. 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 2. 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. 3. 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 (v1) ------------------- * SoC: MT7622 (4x4 2.4 GHz Wifi) * Wifi: MT7615 (4x4 5 GHz Wifi) * Flash: Winbond W29N01HZ 128MB SLC NAND * Ethernet: Realtek RTL8367S (4 x 1GBit/s, SoC via 2.5GBit/s) Co-Developed-by: Hauke Mehrtens Signed-off-by: Hauke Mehrtens --- package/boot/uboot-envtools/files/mediatek | 3 + package/system/mtd/src/Makefile | 1 + .../dts/mt7622-buffalo-wsr-2533dhp2.dts | 336 ++++++++++++++++++ target/linux/mediatek/image/mt7622.mk | 64 ++++ .../mt7622/base-files/etc/board.d/02_network | 4 + .../base-files/etc/uci-defaults/09_fix_crc | 10 + .../mt7622/base-files/lib/upgrade/buffalo.sh | 126 +++++++ .../mt7622/base-files/lib/upgrade/platform.sh | 15 + target/linux/mediatek/mt7622/config-5.10 | 1 + 9 files changed, 560 insertions(+) create mode 100644 target/linux/mediatek/dts/mt7622-buffalo-wsr-2533dhp2.dts create mode 100644 target/linux/mediatek/mt7622/base-files/etc/uci-defaults/09_fix_crc create mode 100644 target/linux/mediatek/mt7622/base-files/lib/upgrade/buffalo.sh diff --git a/package/boot/uboot-envtools/files/mediatek b/package/boot/uboot-envtools/files/mediatek index ba6d780c4926..ce28fb31cbca 100644 --- a/package/boot/uboot-envtools/files/mediatek +++ b/package/boot/uboot-envtools/files/mediatek @@ -24,6 +24,9 @@ case "$board" in ubootenv_add_uci_config "$envdev" "0x0" "0x80000" "0x80000" "1" ubootenv_add_uci_config "$envdev" "0x80000" "0x80000" "0x80000" "1" ;; +buffalo,wsr-2533dhp2) + ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x1000" "0x1000" + ;; esac config_load ubootenv diff --git a/package/system/mtd/src/Makefile b/package/system/mtd/src/Makefile index 6baea52b8f03..e204ecb221d5 100644 --- a/package/system/mtd/src/Makefile +++ b/package/system/mtd/src/Makefile @@ -12,6 +12,7 @@ obj.gemini = $(obj.wrgg) obj.brcm = trx.o obj.bcm47xx = $(obj.brcm) obj.bcm53xx = $(obj.brcm) $(obj.seama) +obj.mediatek = $(obj.brcm) obj.bcm63xx = imagetag.o obj.bmips = imagetag.o obj.ramips = $(obj.seama) $(obj.tpl) $(obj.wrg) linksys_bootcount.o diff --git a/target/linux/mediatek/dts/mt7622-buffalo-wsr-2533dhp2.dts b/target/linux/mediatek/dts/mt7622-buffalo-wsr-2533dhp2.dts new file mode 100644 index 000000000000..198c78476d33 --- /dev/null +++ b/target/linux/mediatek/dts/mt7622-buffalo-wsr-2533dhp2.dts @@ -0,0 +1,336 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT +/dts-v1/; +#include +#include + +#include "mt7622.dtsi" +#include "mt6380.dtsi" + +/ { + model = "Buffalo WSR-2533DHP2"; + compatible = "buffalo,wsr-2533dhp2", "mediatek,mt7622"; + + aliases { + serial0 = &uart0; + led-boot = &power_green; + led-failsafe = &power_amber; + led-running = &power_green; + led-upgrade = &power_green; + }; + + chosen { + bootargs = "earlycon=uart8250,mmio32,0x11002000 console=ttyS0,115200n8 swiotlb=512"; + }; + + memory { + reg = <0 0x40000000 0 0x0F000000>; + }; + + leds { + compatible = "gpio-leds"; + + wireless_amber { + label = "wsr-2533dhp2:amber:wireless"; + gpios = <&pio 2 GPIO_ACTIVE_HIGH>; + }; + + power_amber: power_amber { + label = "wsr-2533dhp2:amber:power"; + gpios = <&pio 3 GPIO_ACTIVE_LOW>; + }; + + power_green: power_green { + label = "wsr-2533dhp2:green:power"; + gpios = <&pio 4 GPIO_ACTIVE_LOW>; + default-state = "on"; + }; + + wireless_green { + label = "wsr-2533dhp2:green:wireless"; + gpios = <&pio 15 GPIO_ACTIVE_HIGH>; + }; + + internet { + label = "wsr-2533dhp2:green:internet"; + gpios = <&pio 19 GPIO_ACTIVE_HIGH>; + }; + + router { + label = "wsr-2533dhp2:green:router"; + gpios = <&pio 20 GPIO_ACTIVE_HIGH>; + }; + }; + + keys { + compatible = "gpio-keys-polled"; + poll-interval = <100>; + + reset { + label = "reset"; + gpios = <&pio 0 GPIO_ACTIVE_LOW>; + linux,code = ; + }; + + router { + label = "router"; + gpios = <&pio 1 GPIO_ACTIVE_LOW>; + linux,code = ; + linux,input-type = ; + }; + + bridge { + label = "wb"; + gpios = <&pio 16 GPIO_ACTIVE_LOW>; + linux,code = ; + linux,input-type = ; + }; + + manual { + label = "manual"; + gpios = <&pio 18 GPIO_ACTIVE_LOW>; + linux,code = ; + linux,input-type = ; + }; + + wps { + label = "wps"; + gpios = <&pio 102 GPIO_ACTIVE_LOW>; + linux,code = ; + }; + }; + + rtkgsw: rtkgsw@0 { + compatible = "mediatek,rtk-gsw"; + mediatek,ethsys = <ðsys>; + mediatek,mdio = <&mdio>; + mediatek,reset-pin = <&pio 54 GPIO_ACTIVE_HIGH>; + }; +}; + +&cpu0 { + proc-supply = <&mt6380_vcpu_reg>; + sram-supply = <&mt6380_vm_reg>; +}; + +&cpu1 { + proc-supply = <&mt6380_vcpu_reg>; + sram-supply = <&mt6380_vm_reg>; +}; + +&pcie0 { + pinctrl-names = "default"; + pinctrl-0 = <&pcie0_pins>; + status = "okay"; +}; + +&slot0 { + status = "okay"; + + wifi@0,0 { + compatible = "mediatek,mt76"; + reg = <0x0000 0 0 0 0>; + mediatek,mtd-eeprom = <&factory 0x5000>; + ieee80211-freq-limit = <5000000 6000000>; + }; +}; + +&pio { + eth_pins: eth-pins { + mux { + function = "eth"; + groups = "mdc_mdio", "rgmii_via_gmac2"; + }; + }; + + /* Parallel nand is shared pin with eMMC */ + parallel_nand_pins: parallel-nand-pins { + mux { + function = "flash"; + groups = "par_nand"; + }; + + conf-cmd-dat { + pins = "NCEB", "NWEB", "NREB", + "NDL4", "NDL5", "NDL6", + "NDL7", "NRB", "NCLE", + "NALE", "NDL0", "NDL1", + "NDL2", "NDL3"; + input-enable; + drive-strength = <8>; + bias-pull-up; + }; + }; + + pcie0_pins: pcie0-pins { + mux { + function = "pcie"; + groups = "pcie0_pad_perst", + "pcie0_1_waken", + "pcie0_1_clkreq"; + }; + }; + + pmic_bus_pins: pmic-bus-pins { + mux { + function = "pmic"; + groups = "pmic_bus"; + }; + }; + + pwm7_pins: pwm1-2-pins { + mux { + function = "pwm"; + groups = "pwm_ch7_2"; + }; + }; + + uart0_pins: uart0-pins { + mux { + function = "uart"; + groups = "uart0_0_tx_rx" ; + }; + }; + + watchdog_pins: watchdog-pins { + mux { + function = "watchdog"; + groups = "watchdog"; + }; + }; +}; + +&bch { + status = "okay"; +}; + +ð { + pinctrl-names = "default"; + pinctrl-0 = <ð_pins>; + status = "okay"; + + gmac0: mac@0 { + compatible = "mediatek,eth-mac"; + reg = <0>; + + phy-connection-type = "2500base-x"; + + mtd-mac-address = <&factory 0x4>; + mtd-mac-address-increment = <(-1)>; + + fixed-link { + speed = <2500>; + full-duplex; + pause; + }; + }; + + mdio: mdio-bus { + #address-cells = <1>; + #size-cells = <0>; + }; +}; + +&nandc { + pinctrl-names = "default"; + pinctrl-0 = <¶llel_nand_pins>; + status = "okay"; + + nand@0 { + reg = <0>; + nand-ecc-mode = "hw"; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "Preloader"; + reg = <0x0 0x80000>; + read-only; + }; + + partition@80000 { + label = "ATF"; + reg = <0x80000 0x40000>; + read-only; + }; + + partition@c0000 { + label = "Bootloader"; + reg = <0xc0000 0x80000>; + read-only; + }; + + partition@140000 { + label = "Config"; + reg = <0x140000 0x80000>; + read-only; + }; + + factory: partition@1c0000 { + label = "factory"; + reg = <0x1c0000 0x40000>; + read-only; + }; + + partition@200000 { + compatible = "brcm,trx"; + trx-magic = <0x32504844>; + label = "firmware"; + reg = <0x200000 0x3a00000>; + }; + + partition@3C00000 { + label = "Kernel2"; + reg = <0x3c00000 0x3a00000>; + }; + + partition@7600000 { + label = "glbcfg"; + reg = <0x7600000 0x200000>; + read-only; + }; + + partition@7800000 { + label = "board_data"; + reg = <0x7800000 0x200000>; + read-only; + }; + }; + }; +}; + +&pwm { + pinctrl-names = "default"; + pinctrl-0 = <&pwm7_pins>; + status = "okay"; +}; + +&pwrap { + pinctrl-names = "default"; + pinctrl-0 = <&pmic_bus_pins>; + status = "okay"; +}; + +&uart0 { + pinctrl-names = "default"; + pinctrl-0 = <&uart0_pins>; + status = "okay"; +}; + +&watchdog { + pinctrl-names = "default"; + pinctrl-0 = <&watchdog_pins>; + status = "okay"; +}; + +&wmac { + status = "okay"; + + mediatek,mtd-eeprom = <&factory 0x0>; +}; + +&rtc { + status = "disabled"; +}; diff --git a/target/linux/mediatek/image/mt7622.mk b/target/linux/mediatek/image/mt7622.mk index 0de1c375b21a..fdc8e496dea5 100644 --- a/target/linux/mediatek/image/mt7622.mk +++ b/target/linux/mediatek/image/mt7622.mk @@ -6,6 +6,28 @@ else KERNEL_LOADADDR := 0x44000000 endif +define Image/Prepare + # For UBI we want only one extra block + rm -f $(KDIR)/ubi_mark + echo -ne '\xde\xad\xc0\xde' > $(KDIR)/ubi_mark +endef + +define Build/buffalo-kernel-trx + $(eval magic=$(word 1,$(1))) + $(eval dummy=$(word 2,$(1))) + $(eval kern_size=$(if $(KERNEL_SIZE),$(KERNEL_SIZE),0x400000)) + + $(if $(dummy),touch $(dummy)) + $(STAGING_DIR_HOST)/bin/otrx create $@.new \ + $(if $(magic),-M $(magic),) \ + -f $@ \ + $(if $(dummy),\ + -a 0x20000 \ + -b $$(( $(subst k, * 1024,$(kern_size)) )) \ + -f $(dummy),) + mv $@.new $@ +endef + define Build/bl2 cat $(STAGING_DIR_IMAGE)/mt7622-$1-bl2.img >> $@ endef @@ -34,6 +56,19 @@ define Build/mt7622-gpt rm $@.tmp endef +define Build/trx-nand + # kernel: always use 4 MiB (-28 B or TRX header) to allow upgrades even + # if it grows up between releases + # root: UBI with one extra block containing UBI mark to trigger erasing + # rest of partition + $(STAGING_DIR_HOST)/bin/otrx create $@.new \ + -M 0x32504844 \ + -f $(IMAGE_KERNEL) -a 0x20000 -b 0x400000 \ + -f $@ \ + -A $(KDIR)/ubi_mark -a 0x20000 + mv $@.new $@ +endef + define Device/bananapi_bpi-r64 DEVICE_VENDOR := Bananapi DEVICE_MODEL := BPi-R64 @@ -56,6 +91,35 @@ define Device/bananapi_bpi-r64 endef TARGET_DEVICES += bananapi_bpi-r64 +define Device/buffalo_wsr-2533dhp2 + DEVICE_VENDOR := Buffalo + DEVICE_MODEL := WSR-2533DHP2 + DEVICE_DTS := mt7622-buffalo-wsr-2533dhp2 + DEVICE_DTS_DIR := ../dts + IMAGE_SIZE := 59392k + KERNEL_SIZE := 4096k + BLOCKSIZE := 128k + PAGESIZE := 2048 + SUBPAGESIZE := 512 + UBINIZE_OPTS := -E 5 + BUFFALO_TAG_PLATFORM := MTK + BUFFALO_TAG_VERSION := 9.99 + BUFFALO_TAG_MINOR := 9.99 + IMAGES += factory.bin factory-uboot.bin + KERNEL_INITRAMFS := kernel-bin | lzma | \ + fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb with-initrd | \ + buffalo-kernel-trx + IMAGE/factory.bin := append-ubi | trx-nand | \ + buffalo-enc WSR-2533DHP2 $$(BUFFALO_TAG_VERSION) -l | \ + buffalo-tag-dhp WSR-2533DHP2 JP JP | buffalo-enc-tag -l | buffalo-dhp-image + IMAGE/factory-uboot.bin := append-ubi | trx-nand + IMAGE/sysupgrade.bin := append-kernel | \ + buffalo-kernel-trx 0x32504844 $(KDIR)/tmp/$$(DEVICE_NAME).null | \ + sysupgrade-tar kernel=$$$$@ | append-metadata + DEVICE_PACKAGES := kmod-mt7615e kmod-mt7615-firmware swconfig uboot-envtools +endef +TARGET_DEVICES += buffalo_wsr-2533dhp2 + define Device/elecom_wrc-2533gent DEVICE_VENDOR := Elecom DEVICE_MODEL := WRC-2533GENT 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 f537ccdb80af..f1daa2fae152 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 000000000000..81cb6b18b7a8 --- /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 000000000000..844cc4ed9593 --- /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 87852881bf4d..97a492c7fb8f 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 5d80056365df..b899d9dbbb30 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