aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2020-06-14 14:20:36 +0100
committerPetr Štetiar <ynezz@true.cz>2020-07-08 23:22:30 +0200
commite19ffb25d97e3859693c6d4582caf32e45265aa7 (patch)
tree6f50e32c624813775b7618beb67b813d88cf5dab
parent7adc29f59ede5112b94b3df4688b47a88f84f544 (diff)
downloadupstream-e19ffb25d97e3859693c6d4582caf32e45265aa7.tar.gz
upstream-e19ffb25d97e3859693c6d4582caf32e45265aa7.tar.bz2
upstream-e19ffb25d97e3859693c6d4582caf32e45265aa7.zip
mediatek: store MAC address in boot partition on Banana Pi R2
Like many boards, the Banana Pi R2 doesn't have permanant storage of its MAC address, and we store the first random one that the kernel generates in order to use it later and at least be consistent. Store it in the FAT boot partition, just as the U7623 board (and others) do. Signed-off-by: David Woodhouse <dwmw2@infradead.org>
-rw-r--r--target/linux/mediatek/mt7623/base-files/lib/preinit/07_set_iface_mac59
1 files changed, 36 insertions, 23 deletions
diff --git a/target/linux/mediatek/mt7623/base-files/lib/preinit/07_set_iface_mac b/target/linux/mediatek/mt7623/base-files/lib/preinit/07_set_iface_mac
index f64458526f..60b699d9c9 100644
--- a/target/linux/mediatek/mt7623/base-files/lib/preinit/07_set_iface_mac
+++ b/target/linux/mediatek/mt7623/base-files/lib/preinit/07_set_iface_mac
@@ -1,23 +1,19 @@
# Copyright (C) 2018 OpenWrt.org
-RECOVERY_PART=/dev/mmcblk0p1
+. /lib/functions.sh
+. /lib/functions/system.sh
-preinit_set_mac_address() {
+set_recovery_mac_address() {
+ local RECOVERY_PART="$1"
local mac
- . /lib/functions.sh
- . /lib/functions/system.sh
-
- case $(board_name) in
- unielec,u7623-02-emmc-512m)
- if [ -b $RECOVERY_PART ]; then
- insmod nls_cp437
- insmod nls_iso8859-1
- insmod fat
- insmod vfat
- mkdir -p /tmp/recovery
- mount -o rw,noatime $RECOVERY_PART /tmp/recovery
-
+ if [ -b $RECOVERY_PART ]; then
+ insmod nls_cp437
+ insmod nls_iso8859-1
+ insmod fat
+ insmod vfat
+ mkdir -p /tmp/recovery
+ if mount -o rw,noatime $RECOVERY_PART -t vfat /tmp/recovery; then
if [ -f "/tmp/recovery/mac_addr" ];
then
mac=$(cat /tmp/recovery/mac_addr)
@@ -28,17 +24,34 @@ preinit_set_mac_address() {
sync
umount /tmp/recovery
- rm -rf /tmp/recovery
- fi
+ rmdir /tmp/recovery
- ip link set dev wan address $mac 2> /dev/null
+ ip link set dev wan address $mac 2> /dev/null
- mac=$(macaddr_add $mac 1)
+ mac=$(macaddr_add $mac 1)
- ip link set dev lan0 address $mac 2>/dev/null
- ip link set dev lan1 address $mac 2>/dev/null
- ip link set dev lan2 address $mac 2>/dev/null
- ip link set dev lan3 address $mac 2>/dev/null
+ ip link set dev lan0 address $mac 2>/dev/null
+ ip link set dev lan1 address $mac 2>/dev/null
+ ip link set dev lan2 address $mac 2>/dev/null
+ ip link set dev lan3 address $mac 2>/dev/null
+ fi
+ fi
+}
+
+preinit_set_mac_address() {
+ local rootpart
+
+ case $(board_name) in
+ bananapi,bpi-r2)
+ rootpart=$(cat /proc/cmdline)
+ rootpart="${rootpart##*root=}"
+ rootpart="${rootpart%%p3 *}"
+ if [ "$rootpart" = "/dev/mmcblk0" -o "$rootpart" = "/dev/mmcblk1" ]; then
+ set_recovery_mac_address ${rootpart}p2
+ fi
+ ;;
+ unielec,u7623-02-emmc-512m)
+ set_recovery_mac_address /dev/mmcblk0p1
;;
esac
}