ramips: add setmac and getmac scripts

This commit is contained in:
coolsnowwolf 2024-12-16 11:20:52 +08:00
parent 4fb48d3e6f
commit 0a3cb8e16a
7 changed files with 52 additions and 7 deletions

View File

@ -1,11 +1,10 @@
do_sysinfo_generic() {
mkdir -p /tmp/sysinfo
[ -d /proc/device-tree ] || return
mkdir -p /tmp/sysinfo
[ -e /tmp/sysinfo/board_name ] || \
echo "$(strings /proc/device-tree/compatible | head -1)" > /tmp/sysinfo/board_name
[ ! -e /tmp/sysinfo/model -a -e /proc/device-tree/model ] && \
echo "$(cat /proc/device-tree/model)" > /tmp/sysinfo/model
[ -z "$(fw_printenv model_name)" ] || fw_printenv model_name > /tmp/sysinfo/model
}
boot_hook_add preinit_main do_sysinfo_generic

View File

@ -16,8 +16,7 @@ alfa-network,ac1200rm|\
alfa-network,awusfree1|\
alfa-network,quad-e4g|\
alfa-network,r36m-e4g|\
alfa-network,tube-e4g|\
huasifei,mt7621dtu)
alfa-network,tube-e4g)
ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x1000"
;;
allnet,all0256n-4m|\
@ -35,6 +34,7 @@ beeline,smartbox-turbo-plus)
;;
buffalo,wsr-1166dhp|\
buffalo,wsr-600dhp|\
huasifei,mt7621dtu|\
mediatek,linkit-smart-7688|\
samknows,whitebox-v8|\
xiaomi,mi-router-4c|\

View File

@ -0,0 +1,15 @@
#!/bin/sh
. /lib/functions.sh
. /lib/functions/system.sh
if [ -e "/dev/mtd0" ]; then
wifi_mac="$(mtd_get_mac_binary factory 0x4)"
elif [ -e "/dev/mmcblk0" ]; then
wifi_mac="$(mmc_get_mac_binary factory 0x4)"
else
echo "Error: unsupported flash."
exit 1
fi
echo "$wifi_mac" | awk '{print toupper($0)}'

View File

@ -0,0 +1,22 @@
#!/bin/sh
. /lib/functions/caldata.sh
if [ -e "/dev/mtd0" ]; then
part="$(find_mtd_part factory)"
elif [ -e "/dev/mmcblk0" ]; then
part="$(find_mmc_part factory)"
fi
[ -n "$part" ] || { echo "Partition 'Factory' not found!"; exit 1; }
mac="$1"
validate_data macaddr "$mac" >"/dev/null" 2>&1 || { echo "Please specify a correct MAC address!"; exit 1; }
dd if="$part" of="/tmp/Factory.backup" 2>"/dev/null"
caldata_patch_mac "$mac" "0x4" "" "/tmp/Factory.backup" 2>"/dev/null"
if [ -e "/dev/mtd0" ]; then
mtd -qq write "/tmp/Factory.backup" "factory"
else
dd if="/tmp/Factory.backup" of="$part" bs=512 conv=fsync 2>"/dev/null"
fi
rm -rf "/tmp/Factory.backup"

View File

@ -102,13 +102,11 @@
partition@30000 {
label = "u-boot-env";
reg = <0x30000 0x10000>;
read-only;
};
factory: partition@40000 {
label = "factory";
reg = <0x40000 0x10000>;
read-only;
compatible = "nvmem-cells";
#address-cells = <1>;

View File

@ -859,7 +859,7 @@ define Device/huasifei_mt7621dtu
DEVICE_MODEL := MT7621 DTU
DEVICE_PACKAGES := kmod-ata-ahci kmod-mt7603 kmod-mt76x2 kmod-sdhci-mt7620 \
kmod-usb3 kmod-usb-net-cdc-mbim kmod-usb-net-qmi-wwan \
kmod-usb-serial-option luci-proto-qmi sendat
kmod-usb-serial-option luci-proto-qmi sendat uboot-envtools
endef
TARGET_DEVICES += huasifei_mt7621dtu

View File

@ -0,0 +1,11 @@
#!/bin/sh /etc/rc.common
START=99
start() {
[ -n "$(fw_printenv -n model_name 2>/dev/null)" ] && fw_printenv -n model_name > /tmp/sysinfo/model
}