From 9f2db43da3e8a43eabf3784e9bcb2a0d427e4260 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Mon, 1 Jul 2024 02:06:35 +0800 Subject: [PATCH] mediatek: bpi-r4: store random MAC addresses for the BPi-R4 --- .../uboot-envtools/files/mediatek_filogic | 53 +++++++++++++------ .../uci-defaults/99_fwenv-store-ethaddr.sh | 5 +- .../filogic/base-files/etc/board.d/02_network | 4 +- .../etc/hotplug.d/ieee80211/11_fix_wifi_mac | 6 +++ 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/package/boot/uboot-envtools/files/mediatek_filogic b/package/boot/uboot-envtools/files/mediatek_filogic index 17c8141810c84a..e8f3c14664ce0b 100644 --- a/package/boot/uboot-envtools/files/mediatek_filogic +++ b/package/boot/uboot-envtools/files/mediatek_filogic @@ -11,26 +11,45 @@ touch /etc/config/ubootenv board=$(board_name) +ubootenv_add_mmc_default() { + local envdev="$(find_mmc_part "ubootenv" "${1:-mmcblk0}")" + ubootenv_add_uci_config "$envdev" "0x0" "0x40000" "0x40000" "1" + ubootenv_add_uci_config "$envdev" "0x40000" "0x40000" "0x40000" "1" +} + +ubootenv_add_nor_default() { + local envdev="/dev/mtd$(find_mtd_index "u-boot-env")" + ubootenv_add_uci_config "$envdev" "0x0" "0x20000" "0x20000" "1" + ubootenv_add_uci_config "$envdev" "0x20000" "0x20000" "0x20000" "1" +} + +ubootenv_add_ubi_default() { + . /lib/upgrade/nand.sh + local envubi=$(nand_find_ubi ubi) + local envdev=/dev/$(nand_find_volume $envubi ubootenv) + local envdev2=/dev/$(nand_find_volume $envubi ubootenv2) + ubootenv_add_uci_config "$envdev" "0x0" "0x1f000" "0x1f000" "1" + ubootenv_add_uci_config "$envdev2" "0x0" "0x1f000" "0x1f000" "1" +} + case "$board" in -bananapi,bpi-r3) - case "$(cmdline_get_var root)" in - /dev/mmc*) - local envdev=$(find_mmc_part "ubootenv" $rootdev) - ubootenv_add_uci_config "$envdev" "0x0" "0x40000" "0x40000" "1" - ubootenv_add_uci_config "$envdev" "0x40000" "0x40000" "0x40000" "1" +bananapi,bpi-r3|\ +bananapi,bpi-r3-mini|\ +bananapi,bpi-r4|\ +bananapi,bpi-r4-poe|\ +jdcloud,re-cp-03) + . /lib/upgrade/common.sh + + bootdev="$(fitblk_get_bootdev)" + case "$bootdev" in + ubi*) + ubootenv_add_ubi_default ;; - /dev/mtd*) - local envdev=/dev/mtd$(find_mtd_index "u-boot-env") - ubootenv_add_uci_config "$envdev" "0x0" "0x20000" "0x20000" "1" - ubootenv_add_uci_config "$envdev" "0x20000" "0x20000" "0x20000" "1" + mmc*) + ubootenv_add_mmc_default "${bootdev%%p[0-9]*}" ;; - /dev/ubi*) - . /lib/upgrade/nand.sh - local envubi=$(nand_find_ubi ubi) - local envdev=/dev/$(nand_find_volume $envubi ubootenv) - local envdev2=/dev/$(nand_find_volume $envubi ubootenv2) - ubootenv_add_uci_config "$envdev" "0x0" "0x1f000" "0x1f000" "1" - ubootenv_add_uci_config "$envdev2" "0x0" "0x1f000" "0x1f000" "1" + mtd*) + ubootenv_add_nor_default ;; esac ;; diff --git a/target/linux/mediatek/base-files/etc/uci-defaults/99_fwenv-store-ethaddr.sh b/target/linux/mediatek/base-files/etc/uci-defaults/99_fwenv-store-ethaddr.sh index 5dec158a93f41c..e9cb4f921d9aed 100644 --- a/target/linux/mediatek/base-files/etc/uci-defaults/99_fwenv-store-ethaddr.sh +++ b/target/linux/mediatek/base-files/etc/uci-defaults/99_fwenv-store-ethaddr.sh @@ -9,7 +9,10 @@ unielec,u7623-02) [ -z "$(fw_printenv -n ethaddr 2>/dev/null)" ] && fw_setenv ethaddr "$(cat /sys/class/net/eth0/address)" ;; -bananapi,bpi-r3) +bananapi,bpi-r3|\ +bananapi,bpi-r3-mini|\ +bananapi,bpi-r4|\ +bananapi,bpi-r4-poe) [ -z "$(fw_printenv -n ethaddr 2>/dev/null)" ] && fw_setenv ethaddr "$(cat /sys/class/net/eth0/address)" [ -z "$(fw_printenv -n eth1addr 2>/dev/null)" ] && 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 4516ffa99d74d2..5586a6a8b3bad0 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 @@ -81,7 +81,9 @@ mediatek_setup_macs() wan_mac="${addr}" lan_mac="${addr}" ;; - bananapi,bpi-r3) + bananapi,bpi-r3|\ + bananapi,bpi-r3-mini|\ + bananapi,bpi-r4) wan_mac=$(macaddr_add $(cat /sys/class/net/eth0/address) 1) ;; cmcc,rax3000m-emmc) diff --git a/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac b/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac index 39acbafd585009..a1e86697fd6580 100644 --- a/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac +++ b/target/linux/mediatek/filogic/base-files/etc/hotplug.d/ieee80211/11_fix_wifi_mac @@ -29,6 +29,12 @@ case "$board" in [ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress [ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress ;; + bananapi,bpi-r4) + addr=$(cat /sys/class/net/eth0/address) + [ "$PHYNBR" = "0" ] && macaddr_add $addr 2 > /sys${DEVPATH}/macaddress + [ "$PHYNBR" = "1" ] && macaddr_add $addr 3 > /sys${DEVPATH}/macaddress + [ "$PHYNBR" = "2" ] && macaddr_add $addr 4 > /sys${DEVPATH}/macaddress + ;; cetron,ct3003*) addr=$(mtd_get_mac_binary "art" 0) [ "$PHYNBR" = "0" ] && macaddr_add $addr 1 > /sys${DEVPATH}/macaddress