From b35c02ad41655f29b94fa71125c51fa13100add4 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Mon, 1 Jul 2024 01:58:56 +0800 Subject: [PATCH] mediatek: add support for BananaPi BPI-R4 MT7988 board --- .../filogic/base-files/etc/board.d/01_leds | 6 +++ .../filogic/base-files/etc/board.d/02_network | 3 ++ .../base-files/lib/upgrade/platform.sh | 41 ++++++++++++++- target/linux/mediatek/filogic/config-6.6 | 1 + target/linux/mediatek/image/filogic.mk | 51 ++++++++++++++++++- 5 files changed, 100 insertions(+), 2 deletions(-) diff --git a/target/linux/mediatek/filogic/base-files/etc/board.d/01_leds b/target/linux/mediatek/filogic/base-files/etc/board.d/01_leds index 69e807671c6af9..52d761805270fe 100644 --- a/target/linux/mediatek/filogic/base-files/etc/board.d/01_leds +++ b/target/linux/mediatek/filogic/base-files/etc/board.d/01_leds @@ -9,6 +9,12 @@ case $board in abt,asr3000) ucidef_set_led_netdev "wan" "WAN" "green:wan" "eth1" ;; +bananapi,bpi-r4) + ucidef_set_led_netdev "wan" "wan" "mt7530-0:00:green:lan" "wan" "link tx rx" + ucidef_set_led_netdev "lan1" "lan1" "mt7530-0:01:green:lan" "lan1" "link tx rx" + ucidef_set_led_netdev "lan2" "lan2" "mt7530-0:02:green:lan" "lan2" "link tx rx" + ucidef_set_led_netdev "lan3" "lan3" "mt7530-0:03:green:lan" "lan3" "link tx rx" + ;; hf,m7986r1*) ucidef_set_led_netdev "led-1" "LAN1" "led-1" "lan1" ucidef_set_led_netdev "led-2" "LAN2" "led-2" "lan2" diff --git a/target/linux/mediatek/filogic/base-files/etc/board.d/02_network b/target/linux/mediatek/filogic/base-files/etc/board.d/02_network index e65a634bafb936..4516ffa99d74d2 100644 --- a/target/linux/mediatek/filogic/base-files/etc/board.d/02_network +++ b/target/linux/mediatek/filogic/base-files/etc/board.d/02_network @@ -24,6 +24,9 @@ mediatek_setup_interfaces() bananapi,bpi-r3) ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4 sfp2" "eth1 wan" ;; + bananapi,bpi-r4) + ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 eth1" "wan eth2" + ;; cetron,ct3003*|\ fzs,5gcpe-p3|\ jcg,q30-pro|\ diff --git a/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh b/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh index 6642318f80eed0..218d16406b7e09 100755 --- a/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh +++ b/target/linux/mediatek/filogic/base-files/lib/upgrade/platform.sh @@ -1,4 +1,5 @@ REQUIRE_IMAGE_METADATA=1 +RAMFS_COPY_BIN='fitblk' asus_initial_setup() { @@ -11,6 +12,21 @@ asus_initial_setup() ubimkvol /dev/ubi0 -N jffs2 -s 0x3e000 } +platform_get_bootdev() { + local rootdisk="$(cat /sys/firmware/devicetree/base/chosen/rootdisk)" + local handle bootdev + for handle in /sys/class/block/*/of_node/phandle /sys/class/block/*/device/of_node/phandle; do + [ ! -e "$handle" ] && continue + if [ "$rootdisk" = "$(cat $handle)" ]; then + bootdev="${handle%/of_node/phandle}" + bootdev="${bootdev%/device}" + bootdev="${bootdev#/sys/class/block/}" + echo "$bootdev" + break + fi + done +} + platform_do_upgrade() { local board=$(board_name) @@ -40,6 +56,21 @@ platform_do_upgrade() { ;; esac ;; + bananapi,bpi-r4) + [ -e /dev/fit0 ] && fitblk /dev/fit0 + [ -e /dev/fitrw ] && fitblk /dev/fitrw + bootdev="$(platform_get_bootdev)" + case "$bootdev" in + mmcblk*) + EMMC_KERN_DEV="/dev/$bootdev" + emmc_do_upgrade "$1" + ;; + ubiblock*) + CI_KERNPART="fit" + nand_do_upgrade "$1" + ;; + esac + ;; cmcc,rax3000m-emmc|\ glinet,gl-mt2500|\ glinet,gl-mt6000|\ @@ -63,7 +94,8 @@ platform_check_image() { [ "$#" -gt 1 ] && return 1 case "$board" in - bananapi,bpi-r3) + bananapi,bpi-r3|\ + bananapi,bpi-r4) [ "$magic" != "d00dfeed" ] && { echo "Invalid image type." return 1 @@ -88,6 +120,13 @@ platform_copy_config() { ;; esac ;; + bananapi,bpi-r4) + case "$(platform_get_bootdev)" in + mmcblk*) + emmc_copy_config + ;; + esac + ;; cmcc,rax3000m-emmc|\ glinet,gl-mt2500|\ glinet,gl-mt6000|\ diff --git a/target/linux/mediatek/filogic/config-6.6 b/target/linux/mediatek/filogic/config-6.6 index 6d9d42853b96c5..f6c8ec6d9a5c8e 100644 --- a/target/linux/mediatek/filogic/config-6.6 +++ b/target/linux/mediatek/filogic/config-6.6 @@ -48,6 +48,7 @@ CONFIG_AUDIT_ARCH_COMPAT_GENERIC=y CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_SD=y CONFIG_BLK_MQ_PCI=y +CONFIG_BLK_NVMEM=y CONFIG_BLK_PM=y CONFIG_BLOCK_NOTIFIERS=y CONFIG_BSD_PROCESS_ACCT=y diff --git a/target/linux/mediatek/image/filogic.mk b/target/linux/mediatek/image/filogic.mk index 89a461f5706385..d5eb8b8114ab23 100644 --- a/target/linux/mediatek/image/filogic.mk +++ b/target/linux/mediatek/image/filogic.mk @@ -30,7 +30,7 @@ define Build/mt7988-bl31-uboot cat $(STAGING_DIR_IMAGE)/mt7988_$1-u-boot.fip >> $@ endef -define Build/mt7986-gpt +define Build/mt798x-gpt cp $@ $@.tmp 2>/dev/null || true ptgen -g -o $@.tmp -a 1 -l 1024 \ $(if $(findstring sdmmc,$1), \ @@ -147,6 +147,55 @@ define Device/bananapi_bpi-r3 endef TARGET_DEVICES += bananapi_bpi-r3 +define Device/bananapi_bpi-r4-common + DEVICE_VENDOR := Bananapi + DEVICE_DTS_DIR := $(DTS_DIR)/ + DEVICE_DTS_LOADADDR := 0x45f00000 + DEVICE_DTS_OVERLAY:= mt7988a-bananapi-bpi-r4-emmc mt7988a-bananapi-bpi-r4-rtc mt7988a-bananapi-bpi-r4-sd mt7988a-bananapi-bpi-r4-wifi-mt7996a + DEVICE_DTC_FLAGS := --pad 4096 + DEVICE_PACKAGES := kmod-hwmon-pwmfan kmod-i2c-mux-pca954x kmod-eeprom-at24 kmod-mt7996-firmware \ + kmod-rtc-pcf8563 kmod-sfp kmod-usb3 e2fsprogs f2fsck mkf2fs + IMAGES := sysupgrade.itb + KERNEL_LOADADDR := 0x46000000 + KERNEL_INITRAMFS_SUFFIX := -recovery.itb + ARTIFACTS := \ + emmc-preloader.bin emmc-bl31-uboot.fip \ + sdcard.img.gz \ + snand-preloader.bin snand-bl31-uboot.fip + ARTIFACT/emmc-preloader.bin := mt7988-bl2 emmc-comb + ARTIFACT/emmc-bl31-uboot.fip := mt7988-bl31-uboot $$(DEVICE_NAME)-emmc + ARTIFACT/snand-preloader.bin := mt7988-bl2 spim-nand-ubi-comb + ARTIFACT/snand-bl31-uboot.fip := mt7988-bl31-uboot $$(DEVICE_NAME)-snand + ARTIFACT/sdcard.img.gz := mt798x-gpt sdmmc |\ + pad-to 17k | mt7988-bl2 sdmmc-comb |\ + pad-to 6656k | mt7988-bl31-uboot $$(DEVICE_NAME)-sdmmc |\ + $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),\ + pad-to 12M | append-image-stage initramfs-recovery.itb | check-size 44m |\ + ) \ + pad-to 44M | mt7988-bl2 spim-nand-ubi-comb |\ + pad-to 45M | mt7988-bl31-uboot $$(DEVICE_NAME)-snand |\ + pad-to 51M | mt7988-bl2 emmc-comb |\ + pad-to 52M | mt7988-bl31-uboot $$(DEVICE_NAME)-emmc |\ + pad-to 56M | mt798x-gpt emmc |\ + $(if $(CONFIG_TARGET_ROOTFS_SQUASHFS),\ + pad-to 64M | append-image squashfs-sysupgrade.itb | check-size |\ + ) \ + gzip + IMAGE_SIZE := $$(shell expr 64 + $$(CONFIG_TARGET_ROOTFS_PARTSIZE))m + KERNEL := kernel-bin | gzip + KERNEL_INITRAMFS := kernel-bin | lzma | \ + fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb with-initrd | pad-to 64k + IMAGE/sysupgrade.itb := append-kernel | fit gzip $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb external-with-rootfs | pad-rootfs | append-metadata +endef + +define Device/bananapi_bpi-r4 + DEVICE_MODEL := BPi-R4 + DEVICE_DTS := mt7988a-bananapi-bpi-r4 + DEVICE_DTS_CONFIG := config-mt7988a-bananapi-bpi-r4 + $(call Device/bananapi_bpi-r4-common) +endef +TARGET_DEVICES += bananapi_bpi-r4 + define Device/cetron_ct3003 DEVICE_VENDOR := Cetron DEVICE_MODEL := CT3003