aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/ramips/mt7621
diff options
context:
space:
mode:
authorAdrian Schmutzler <freifunk@adrianschmutzler.de>2019-10-22 12:37:13 +0200
committerAdrian Schmutzler <freifunk@adrianschmutzler.de>2019-11-03 00:26:17 +0100
commit19724e28c81e3ff642f09c49f612cd147c54a697 (patch)
tree278c45d3b1563cee6108e65c3b5856dbab304062 /target/linux/ramips/mt7621
parent0975c35b83a632f9662d1944307f87da9db06154 (diff)
downloadupstream-19724e28c81e3ff642f09c49f612cd147c54a697.tar.gz
upstream-19724e28c81e3ff642f09c49f612cd147c54a697.tar.bz2
upstream-19724e28c81e3ff642f09c49f612cd147c54a697.zip
ramips: split base-files into subtargets
While most of the target's contents are split into subtargets, the base-files are maintained for the target as a whole. However, OpenWrt already implements a mechanism that will use (and even prefer) files in the subtargets' directories. This can be exploited to make several scripts subtarget-specific and thus save some space. In certain cases, keeping files in parent (=target) base-files was more convenient, and thus no splitting was performed for those. Note that this will increase overall code lines, but reduce code per subtarget. base-files ipk size reduction: master (mt7621) 60958 B split (mt7620) 46358 B (- 14.3 kiB) split (mt7621) 48759 B (- 11.9 kiB) split (mt76x8) 44948 B (- 15.6 kiB) split (rt288x) 43508 B (- 17.0 kiB) split (rt305x) 45616 B (- 15.0 kiB) split (rt3883) 44176 B (- 16.4 kiB) Run-tested on: GL.iNet GL-MT300N-V2 (mt76x8) D-Link DWR-116 (mt7620) Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Diffstat (limited to 'target/linux/ramips/mt7621')
-rwxr-xr-xtarget/linux/ramips/mt7621/base-files/etc/board.d/01_leds83
-rwxr-xr-xtarget/linux/ramips/mt7621/base-files/etc/board.d/02_network238
-rwxr-xr-xtarget/linux/ramips/mt7621/base-files/etc/board.d/03_gpio_switches30
-rwxr-xr-xtarget/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh50
-rw-r--r--target/linux/ramips/mt7621/base-files/lib/upgrade/ubnt.sh78
-rwxr-xr-xtarget/linux/ramips/mt7621/base-files/sbin/fixup-mac-address80
6 files changed, 559 insertions, 0 deletions
diff --git a/target/linux/ramips/mt7621/base-files/etc/board.d/01_leds b/target/linux/ramips/mt7621/base-files/etc/board.d/01_leds
new file mode 100755
index 0000000000..4eab8f42fe
--- /dev/null
+++ b/target/linux/ramips/mt7621/base-files/etc/board.d/01_leds
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+. /lib/functions/leds.sh
+. /lib/functions/uci-defaults.sh
+
+set_wifi_led() {
+ ucidef_set_led_netdev "wifi_led" "wifi" "${1}" "${2:-wlan0}"
+}
+
+
+board=$(board_name)
+boardname="${board##*,}"
+
+board_config_update
+
+led_wlan="$(get_dt_led wlan)"
+[ -n "$led_wlan" ] && ucidef_set_led_wlan "wifi_led" "wifi" "$led_wlan" "phy0tpt"
+
+case $board in
+d-team,newifi-d2)
+ ucidef_set_led_switch "internet" "internet" "$boardname:amber:internet" "switch0" "0x10"
+ ucidef_set_led_netdev "wlan2g" "WiFi 2.4GHz" "$boardname:blue:wlan2g" "wlan0"
+ ucidef_set_led_netdev "wlan5g" "WiFi 5GHz" "$boardname:blue:wlan5g" "wlan1"
+ ;;
+d-team,pbr-m1|\
+gehua,ghl-r-001)
+ ucidef_set_led_netdev "internet" "internet" "$boardname:blue:internet" "eth0.2"
+ ;;
+dlink,dir-860l-b1)
+ ucidef_set_led_netdev "wan" "wan" "$boardname:green:net" "eth0.2"
+ ;;
+gnubee,gb-pc1|\
+gnubee,gb-pc2)
+ ucidef_set_led_switch "lan1" "lan1" "$boardname:green:lan1" "switch0" "0x01"
+ ucidef_set_led_switch "lan2" "lan2" "$boardname:green:lan2" "switch0" "0x10"
+ ;;
+mikrotik,rbm11g)
+ ucidef_set_rssimon "wlan0" "200000" "1"
+ ucidef_set_led_rssi "rssilow" "RSSILOW" "$boardname:green:rssi0" "wlan0" "1" "100"
+ ucidef_set_led_rssi "rssimediumlow" "RSSIMEDIUMLOW" "$boardname:green:rssi1" "wlan0" "20" "100"
+ ucidef_set_led_rssi "rssimediumhigh" "RSSIMEDIUMHIGH" "$boardname:green:rssi2" "wlan0" "40" "100"
+ ucidef_set_led_rssi "rssihigh" "RSSIHIGH" "$boardname:green:rssi3" "wlan0" "60" "100"
+ ucidef_set_led_rssi "rssiveryhigh" "RSSIVERYHIGH" "$boardname:green:rssi4" "wlan0" "80" "100"
+ ;;
+mtc,wr1201)
+ ucidef_set_led_switch "eth_link" "LAN link" "$boardname:green:eth_link" "switch0" "0x0f"
+ ;;
+netgear,r6220|\
+netgear,r6260|\
+netgear,r6350|\
+netgear,r6850|\
+netgear,wndr3700-v5)
+ ucidef_set_led_switch "wan" "wan" "$boardname:green:wan" "switch0" "0x10"
+ ;;
+tplink,re350-v1|\
+tplink,re650-v1)
+ ucidef_set_led_netdev "wifi2g" "Wifi 2.4G" "$boardname:blue:wifi2G" "wlan0"
+ ucidef_set_led_netdev "wifi5g" "Wifi 5G" "$boardname:blue:wifi5G" "wlan1"
+ ucidef_set_led_netdev "eth_act" "LAN act" "$boardname:green:eth_act" "eth0" "tx rx"
+ ucidef_set_led_switch "eth_link" "LAN link" "$boardname:green:eth_link" "switch0" "0x01"
+ ;;
+xiaomi,mir3g)
+ ucidef_set_led_switch "wan-amber" "WAN (amber)" "$boardname:amber:wan" "switch0" "0x02" "0x08"
+ ucidef_set_led_switch "lan1-amber" "LAN1 (amber)" "$boardname:amber:lan1" "switch0" "0x08" "0x08"
+ ucidef_set_led_switch "lan2-amber" "LAN2 (amber)" "$boardname:amber:lan2" "switch0" "0x04" "0x08"
+ ;;
+xiaomi,mir3p)
+ ucidef_set_led_switch "wan-amber" "WAN (amber)" "$boardname:amber:wan" "switch0" "0x10" "0x08"
+ ucidef_set_led_switch "lan1-amber" "LAN1 (amber)" "$boardname:amber:lan1" "switch0" "0x02" "0x08"
+ ucidef_set_led_switch "lan2-amber" "LAN2 (amber)" "$boardname:amber:lan2" "switch0" "0x04" "0x08"
+ ucidef_set_led_switch "lan3-amber" "LAN3 (amber)" "$boardname:amber:lan3" "switch0" "0x08" "0x08"
+ ;;
+xzwifi,creativebox-v1)
+ ucidef_set_led_switch "internet" "internet" "$boardname:blue:internet" "switch0" "0x10"
+ ;;
+youhua,wr1200js)
+ ucidef_set_led_switch "internet" "INTERNET" "$boardname:green:wan" "switch0" "0x01"
+ ;;
+esac
+
+board_config_flush
+
+exit 0
diff --git a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
new file mode 100755
index 0000000000..11cf27e092
--- /dev/null
+++ b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
@@ -0,0 +1,238 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. /lib/functions/uci-defaults.sh
+. /lib/functions/system.sh
+
+ramips_setup_interfaces()
+{
+ local board="$1"
+
+ case $board in
+ adslr,g7|\
+ afoundry,ew1200|\
+ d-team,pbr-m1|\
+ firefly,firewrt|\
+ hiwifi,hc5962|\
+ mediatek,ap-mt7621a-v60|\
+ mediatek,mt7621-eval-board|\
+ mqmaker,witi|\
+ mtc,wr1201|\
+ netis,wf-2881|\
+ phicomm,k2p|\
+ planex,vr500|\
+ samknows,whitebox-v8|\
+ storylink,sap-g3200u3|\
+ telco-electronics,x1|\
+ totolink,a7000r|\
+ unielec,u7621-06-16m|\
+ unielec,u7621-06-64m|\
+ xiaoyu,xy-c5|\
+ xzwifi,creativebox-v1|\
+ youku,yk-l2|\
+ zbtlink,zbt-we1326|\
+ zbtlink,zbt-we3526|\
+ zbtlink,zbt-wg2626|\
+ zbtlink,zbt-wg3526-16m|\
+ zbtlink,zbt-wg3526-32m)
+ ucidef_add_switch "switch0" \
+ "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
+ ;;
+ asiarf,ap7621-001)
+ ucidef_add_switch "switch0" "0:lan" "4:wan" "6@eth0"
+ ;;
+ asiarf,ap7621-nv1)
+ ucidef_add_switch "switch0" "0:wan" "2:lan" "3:lan" "6@eth0"
+ ;;
+ asus,rt-ac57u|\
+ mikrotik,rb750gr3|\
+ mikrotik,rbm33g|\
+ ubiquiti,edgerouterx|\
+ ubiquiti,edgerouterx-sfp|\
+ youhua,wr1200js)
+ ucidef_add_switch "switch0" \
+ "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
+ ;;
+ asus,rt-ac65p|\
+ asus,rt-ac85p|\
+ dlink,dir-860l-b1|\
+ elecom,wrc-1167ghbk2-s|\
+ elecom,wrc-1900gst|\
+ elecom,wrc-2533gst|\
+ iodata,wn-ax1167gr|\
+ iodata,wn-gx300gr|\
+ iodata,wnpr2600g)
+ ucidef_add_switch "switch0" \
+ "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
+ ;;
+ buffalo,wsr-1166dhp|\
+ buffalo,wsr-600dhp)
+ ucidef_add_switch "switch0" \
+ "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
+ ;;
+ d-team,newifi-d2|\
+ wevo,11acnas|\
+ wevo,w2914ns-v2)
+ ucidef_add_switch "switch0" \
+ "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan:5" "6@eth0"
+ ;;
+ edimax,rg21s)
+ ucidef_add_switch "switch0" \
+ "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
+ ;;
+ gehua,ghl-r-001)
+ ucidef_add_switch "switch0" \
+ "0:lan" "1:lan" "2:lan" "4:wan" "6@eth0"
+ ;;
+ gnubee,gb-pc1|\
+ gnubee,gb-pc2)
+ ucidef_add_switch "switch0" \
+ "0:lan" "4:lan" "6@eth0"
+ ;;
+ lenovo,newifi-d1)
+ ucidef_add_switch "switch0" \
+ "1:lan:2" "2:lan:1" "4:wan" "6@eth0"
+ ;;
+ linksys,re6500)
+ ucidef_add_switch "switch0" \
+ "0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
+ ;;
+ mikrotik,rbm11g|\
+ thunder,timecloud)
+ ucidef_add_switch "switch0"
+ ucidef_add_switch_attr "switch0" "enable" "false"
+ ucidef_set_interface_lan "eth0"
+ ;;
+ netgear,ex6150|\
+ tplink,re350-v1|\
+ tplink,re650-v1)
+ ucidef_add_switch "switch0" \
+ "0:lan" "6@eth0"
+ ;;
+ netgear,r6220|\
+ netgear,r6260|\
+ netgear,r6350|\
+ netgear,r6850|\
+ netgear,wndr3700-v5)
+ ucidef_add_switch "switch0" \
+ "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
+ ;;
+ xiaomi,mir3g)
+ ucidef_add_switch "switch0" \
+ "2:lan:2" "3:lan:1" "1:wan" "6t@eth0"
+ ;;
+ xiaomi,mir3g-v2)
+ ucidef_add_switch "switch0" \
+ "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
+ ;;
+ xiaomi,mir3p)
+ ucidef_add_switch "switch0" \
+ "1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
+ ;;
+ *)
+ ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
+ ;;
+ esac
+}
+
+ramips_setup_macs()
+{
+ local board="$1"
+ local lan_mac=""
+ local wan_mac=""
+ local label_mac=""
+
+ case $board in
+ asus,rt-ac57u|\
+ d-team,newifi-d2|\
+ d-team,pbr-m1|\
+ elecom,wrc-1167ghbk2-s|\
+ elecom,wrc-1900gst|\
+ elecom,wrc-2533gst|\
+ lenovo,newifi-d1|\
+ phicomm,k2p|\
+ planex,vr500|\
+ samknows,whitebox-v8|\
+ youhua,wr1200js|\
+ youku,yk-l2|\
+ zbtlink,zbt-we3526)
+ wan_mac=$(mtd_get_mac_binary factory 0xe006)
+ ;;
+ asus,rt-ac65p|\
+ asus,rt-ac85p)
+ wan_mac=$(mtd_get_mac_ascii u-boot-env et1macaddr)
+ label_mac=$(cat /sys/class/ieee80211/phy0/macaddress)
+ ;;
+ buffalo,wsr-1166dhp)
+ local index="$(find_mtd_index "board_data")"
+ wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
+ lan_mac=$wan_mac
+ ;;
+ buffalo,wsr-600dhp)
+ # This empty case has to be kept for devices without any MAC address adjustments
+ ;;
+ dlink,dir-860l-b1)
+ lan_mac=$(mtd_get_mac_ascii factory lanmac)
+ wan_mac=$(mtd_get_mac_ascii factory wanmac)
+ label_mac=$(cat /sys/class/ieee80211/phy1/macaddress)
+ ;;
+ edimax,rg21s)
+ lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
+ wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
+ ;;
+ hiwifi,hc5962)
+ lan_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
+ label_mac=$lan_mac
+ [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
+ wan_mac=$(macaddr_add "$lan_mac" 1)
+ ;;
+ iodata,wn-ax1167gr|\
+ iodata,wn-gx300gr)
+ wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x4)" 1)
+ ;;
+ iodata,wnpr2600g)
+ wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
+ label_mac=$wan_mac
+ ;;
+ netgear,r6260|\
+ netgear,r6350|\
+ netgear,r6850)
+ wan_mac=$(macaddr_add "$(cat /sys/class/net/eth0/address)" 2)
+ ;;
+ xiaomi,mir3g)
+ lan_mac=$(mtd_get_mac_binary factory 0xe006)
+ ;;
+ xiaomi,mir3g-v2)
+ wan_mac=$(mtd_get_mac_binary factory 0xe006)
+ label_mac=$wan_mac
+ ;;
+ xiaomi,mir3p)
+ lan_mac=$(mtd_get_mac_binary factory 0xe006)
+ label_mac=$lan_mac
+ ;;
+ zbtlink,zbt-we1326)
+ wan_mac=$(mtd_get_mac_binary factory 0xe006)
+ label_mac=$(cat /sys/class/ieee80211/phy0/macaddress)
+ ;;
+ zbtlink,zbt-wg3526-16m|\
+ zbtlink,zbt-wg3526-32m)
+ wan_mac=$(macaddr_add "$(cat /sys/class/net/eth0/address)" 1)
+ label_mac=$(cat /sys/class/ieee80211/phy0/macaddress)
+ ;;
+ *)
+ wan_mac=$(macaddr_add "$(cat /sys/class/net/eth0/address)" 1)
+ ;;
+ esac
+
+ [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
+ [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
+ [ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
+}
+
+board_config_update
+board=$(board_name)
+ramips_setup_interfaces $board
+ramips_setup_macs $board
+board_config_flush
+
+exit 0
diff --git a/target/linux/ramips/mt7621/base-files/etc/board.d/03_gpio_switches b/target/linux/ramips/mt7621/base-files/etc/board.d/03_gpio_switches
new file mode 100755
index 0000000000..d3bc85f827
--- /dev/null
+++ b/target/linux/ramips/mt7621/base-files/etc/board.d/03_gpio_switches
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+. /lib/functions/uci-defaults.sh
+
+board_config_update
+
+board=$(board_name)
+
+case "$board" in
+mikrotik,rb750gr3)
+ ucidef_add_gpio_switch "poe_passthrough" "PoE Passthrough" "17"
+ ;;
+telco-electronics,x1)
+ ucidef_add_gpio_switch "modem_reset" "Modem Reset" "16"
+ ;;
+ubiquiti,edgerouterx)
+ ucidef_add_gpio_switch "poe_passthrough" "PoE Passthrough" "0"
+ ;;
+ubiquiti,edgerouterx-sfp)
+ ucidef_add_gpio_switch "poe_power_port0" "PoE Power Port0" "496"
+ ucidef_add_gpio_switch "poe_power_port1" "PoE Power Port1" "497"
+ ucidef_add_gpio_switch "poe_power_port2" "PoE Power Port2" "498"
+ ucidef_add_gpio_switch "poe_power_port3" "PoE Power Port3" "499"
+ ucidef_add_gpio_switch "poe_power_port4" "PoE Power Port4" "500"
+ ;;
+esac
+
+board_config_flush
+
+exit 0
diff --git a/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh
new file mode 100755
index 0000000000..f8aa0373a0
--- /dev/null
+++ b/target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh
@@ -0,0 +1,50 @@
+#
+# Copyright (C) 2010 OpenWrt.org
+#
+
+PART_NAME=firmware
+REQUIRE_IMAGE_METADATA=1
+
+platform_check_image() {
+ return 0
+}
+
+platform_do_upgrade() {
+ local board=$(board_name)
+
+ case "$board" in
+ mikrotik,rb750gr3|\
+ mikrotik,rbm11g|\
+ mikrotik,rbm33g)
+ [ -z "$(rootfs_type)" ] && mtd erase firmware
+ ;;
+ asus,rt-ac65p|\
+ asus,rt-ac85p)
+ echo "Backing up firmware"
+ dd if=/dev/mtd4 bs=1024 count=4096 > /tmp/backup_firmware.bin
+ dd if=/dev/mtd5 bs=1024 count=52224 >> /tmp/backup_firmware.bin
+ mtd -e firmware2 write /tmp/backup_firmware.bin firmware2
+ ;;
+ esac
+
+ case "$board" in
+ asus,rt-ac65p|\
+ asus,rt-ac85p|\
+ hiwifi,hc5962|\
+ netgear,r6220|\
+ netgear,r6260|\
+ netgear,r6350|\
+ netgear,r6850|\
+ xiaomi,mir3g|\
+ xiaomi,mir3p)
+ nand_do_upgrade "$1"
+ ;;
+ ubiquiti,edgerouterx|\
+ ubiquiti,edgerouterx-sfp)
+ platform_upgrade_ubnt_erx "$1"
+ ;;
+ *)
+ default_do_upgrade "$1"
+ ;;
+ esac
+}
diff --git a/target/linux/ramips/mt7621/base-files/lib/upgrade/ubnt.sh b/target/linux/ramips/mt7621/base-files/lib/upgrade/ubnt.sh
new file mode 100644
index 0000000000..748ec8e628
--- /dev/null
+++ b/target/linux/ramips/mt7621/base-files/lib/upgrade/ubnt.sh
@@ -0,0 +1,78 @@
+#
+# Copyright (C) 2015 OpenWrt.org
+#
+
+. /lib/functions.sh
+#Note: this code also uses some functions from nand.sh, but it is expected to be run by nand.sh, so we are not
+#sourcing it explicitly here
+
+UBNT_ERX_KERNEL_INDEX_OFFSET=160
+
+ubnt_get_target_kernel() {
+ local factory_mtd=$1
+ local current_kernel_index=$(hexdump -s $UBNT_ERX_KERNEL_INDEX_OFFSET -n 1 -e '/1 "%X "' ${factory_mtd})
+
+ if [ $current_kernel_index == "0" ]; then
+ echo 'kernel2'
+ elif [ $current_kernel_index == "1" ]; then
+ echo 'kernel1'
+ fi
+}
+
+ubnt_update_target_kernel() {
+ local factory_mtd=$1
+ local kernel_part=$2
+
+ local new_kernel_index
+ if [ $kernel_part == "kernel1" ]; then
+ new_kernel_index="\x00"
+ elif [ $kernel_part == "kernel2" ]; then
+ new_kernel_index="\x01"
+ else
+ echo 'Unknown kernel image index' >&2
+ return 1
+ fi
+
+ if ! (echo -e $new_kernel_index | dd of=${factory_mtd} bs=1 count=1 seek=$UBNT_ERX_KERNEL_INDEX_OFFSET); then
+ echo 'Failed to update kernel bootup index' >&2
+ return 1
+ fi
+}
+
+platform_upgrade_ubnt_erx() {
+ local factory_mtd=$(find_mtd_part factory)
+ if [ -z "$factory_mtd" ]; then
+ echo "cannot find factory partition" >&2
+ exit 1
+ fi
+
+ local kernel_part="$(ubnt_get_target_kernel ${factory_mtd})"
+ if [ -z "$kernel_part" ]; then
+ echo "cannot find factory partition" >&2
+ exit 1
+ fi
+
+ # This is a global defined in nand.sh, sets partition kernel will be flashed into
+ CI_KERNPART=${kernel_part}
+
+ #Remove volume possibly left over from stock firmware
+ local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
+ if [ -z "$ubidev" ]; then
+ local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
+ if [ -z "$mtdnum" ]; then
+ echo "cannot find ubi mtd partition $CI_UBIPART" >&2
+ exit 1
+ fi
+ ubiattach -m "$mtdnum"
+ sync
+ ubidev="$( nand_find_ubi "$CI_UBIPART" )"
+ fi
+ if [ -n "$ubidev" ]; then
+ local troot_ubivol="$( nand_find_volume $ubidev troot )"
+ [ -n "$troot_ubivol" ] && ubirmvol /dev/$ubidev -N troot || true
+ fi
+
+ ubnt_update_target_kernel ${factory_mtd} ${kernel_part} || exit 1
+
+ nand_do_upgrade "$1"
+}
diff --git a/target/linux/ramips/mt7621/base-files/sbin/fixup-mac-address b/target/linux/ramips/mt7621/base-files/sbin/fixup-mac-address
new file mode 100755
index 0000000000..dad15c5842
--- /dev/null
+++ b/target/linux/ramips/mt7621/base-files/sbin/fixup-mac-address
@@ -0,0 +1,80 @@
+#!/bin/sh
+. /lib/functions.sh
+. /lib/functions/system.sh
+
+partname=""
+offset=""
+NEW_MAC=
+YES=
+
+board=$(board_name)
+case $board in
+ mqmaker,witi)
+ partname=factory
+ offset=$((0xe000))
+ ;;
+ *)
+ echo "Unsupported board"
+ exit 1
+ ;;
+esac
+
+while [ -n "$1" ]; do
+ case "$1" in
+ ??:??:??:??:??:??) NEW_MAC="$1";;
+ -y) YES=1;;
+ *)
+ cat <<EOF
+Unknown option/argument '$1'
+Usage: $0 [-y] [<macaddr>]
+EOF
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+ask_bool() {
+ local message="$1"
+ local default="$((! ${2:-0}))"
+ [ -n "$YES" ] && return 0
+ echo -n "$message "
+ read opt
+ case "$opt" in
+ y|Y) return 0;;
+ n|N) return 1;;
+ *) return $default;;
+ esac
+}
+
+convert_hex() {
+ hexdump -e '/1 "%02x "'
+}
+
+gen_mac() {
+ dd if=/dev/urandom bs=6 count=1 2>/dev/null
+}
+
+mac="$(mtd_get_mac_binary $partname $offset)"
+case "$mac" in
+ 00:00:00:00:00:00);;
+ ff:ff:ff:ff:ff:ff);;
+ *)
+ echo "Current MAC address: $mac"
+ ask_bool "Overwrite (y/N)?" 0 || exit
+ ;;
+esac
+
+if [ -n "$NEW_MAC" ]; then
+ set -- $(echo "$NEW_MAC" | sed 's,:, ,g')
+else
+ set -- $(gen_mac | convert_hex)
+ set -- $(printf %02x $(( (0x$1 & 0xfe) | 0x02 ))) $2 $3 $4 $5 $6
+fi
+echo "New MAC address: $1:$2:$3:$4:$5:$6"
+ask_bool "Write to EEPROM (y/N)?" || exit
+
+part=$(find_mtd_part "$partname")
+[ -n "$part" ] || exit
+echo -ne "\x$1\x$2\x$3\x$4\x$5\x$6" | dd of=$part conv=notrunc bs=1 count=6 seek=$offset 2>/dev/null
+echo "Done"