mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-29 05:36:47 +00:00
ethmactool: new package for getting HW MAC address or generating from CPU SN
Ethernet MAC address should be passed by u-boot in device tree. In many cases this address is not correct: ethmactool package allows userspace to take care of it. Currently these are possible sources of "real" MAC: - Amlogic: cmdline, eFuse, CPU SN - Rockchip: CPU SN
This commit is contained in:
parent
6202251a6c
commit
2fb1df6623
17
packages/sysutils/ethmactool/package.mk
Normal file
17
packages/sysutils/ethmactool/package.mk
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
|
# Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv)
|
||||||
|
|
||||||
|
PKG_NAME="ethmactool"
|
||||||
|
PKG_VERSION="1.0"
|
||||||
|
PKG_LICENSE="GPLv2"
|
||||||
|
PKG_LONGDESC="ethmactool: udev rule for obtaining real MAC address or creating a persistent MAC from the CPU serial"
|
||||||
|
PKG_TOOLCHAIN="manual"
|
||||||
|
|
||||||
|
makeinstall_target() {
|
||||||
|
mkdir -p $INSTALL/usr/bin
|
||||||
|
cp $PKG_DIR/scripts/ethmactool-config $INSTALL/usr/bin
|
||||||
|
}
|
||||||
|
|
||||||
|
post_install() {
|
||||||
|
enable_service ethmactool-config.service
|
||||||
|
}
|
73
packages/sysutils/ethmactool/scripts/ethmactool-config
Executable file
73
packages/sysutils/ethmactool/scripts/ethmactool-config
Executable file
@ -0,0 +1,73 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
|
# Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv)
|
||||||
|
|
||||||
|
COMPATIBLE=$(/usr/bin/dtsoc)
|
||||||
|
MAC_STEP=""
|
||||||
|
|
||||||
|
validate_mac() {
|
||||||
|
[ ${#MAC} -eq 12 -a "${MAC}" != "000000000000" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
fixup_self_mac() {
|
||||||
|
# clear multicast bit and set local assignment bit (IEEE802)
|
||||||
|
MAC=$(printf '%012X' "$(( (0x$MAC & 0xFEFFFFFFFFFF) | 0x020000000000 ))")
|
||||||
|
}
|
||||||
|
|
||||||
|
from_cmdline() {
|
||||||
|
for arg in $(cat /proc/cmdline | tr -d ':'); do
|
||||||
|
case ${arg} in
|
||||||
|
mac=*)
|
||||||
|
MAC=${arg#*=}
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
aml_from_efuse_gxbb() {
|
||||||
|
if [ -e /sys/devices/platform/efuse/efuse0/nvmem ] ; then
|
||||||
|
MAC=$(od -x -A n -j 0x34 -N 6 /sys/bus/nvmem/devices/efuse0/nvmem | tr -d ' ')
|
||||||
|
MAC=${MAC:2:2}${MAC:0:2}${MAC:6:2}${MAC:4:2}${MAC:10:2}${MAC:8:2}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
aml_from_efuse_gxl() {
|
||||||
|
if [ -e /sys/devices/platform/efuse/efuse0/nvmem ] ; then
|
||||||
|
MAC=$(cat /sys/devices/platform/efuse/efuse0/nvmem)
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
aml_from_cpu_sn() {
|
||||||
|
if [ -e /sys/bus/platform/devices/firmware\:secure-monitor/serial ] ; then
|
||||||
|
MAC=$(cat /sys/bus/platform/devices/firmware\:secure-monitor/serial 2>/dev/null | cut -b-12)
|
||||||
|
fixup_self_mac
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
from_cpu_sn() {
|
||||||
|
MAC=$(cat /proc/cpuinfo 2>/dev/null | awk '/Serial/ {print substr($3,1,12)}')
|
||||||
|
fixup_self_mac
|
||||||
|
}
|
||||||
|
|
||||||
|
case $COMPATIBLE in
|
||||||
|
amlogic*)
|
||||||
|
MAC_STEPS="from_cmdline aml_from_efuse_gxbb aml_from_efuse_gxl aml_from_cpu_sn"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
MAC_STEPS="from_cpu_sn"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
for MAC_STEP in $MAC_STEPS ; do
|
||||||
|
$MAC_STEP
|
||||||
|
validate_mac && break
|
||||||
|
done
|
||||||
|
|
||||||
|
if validate_mac ; then
|
||||||
|
MAC=$(echo "$MAC" | sed 's/\(..\)/\1:/g' | cut -b-17)
|
||||||
|
echo "MAC=${MAC}" > /run/libreelec/ethmactool-$1
|
||||||
|
/usr/sbin/ip link set dev $1 down
|
||||||
|
/usr/sbin/ip link set dev $1 address $MAC
|
||||||
|
/usr/sbin/ip link set dev $1 up
|
||||||
|
fi
|
@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Configure eth0 MAC address
|
||||||
|
BindsTo=sys-subsystem-net-devices-eth0.device
|
||||||
|
After=sys-subsystem-net-devices-eth0.device
|
||||||
|
Before=connman.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=yes
|
||||||
|
ExecStart=/usr/bin/ethmactool-config eth0
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
x
Reference in New Issue
Block a user