Amit Pundir | e0b877a | 2023-07-19 10:17:38 +0530 | [diff] [blame] | 1 | #! /system/bin/sh |
| 2 | # Set eth0 mac address. |
| 3 | # |
| 4 | # Get the unique board serial number from /proc/cmdline or |
| 5 | # /proc/bootconfig, prepend '0's to the serial number to |
| 6 | # fill 5 LSBs of the MAC address and prepend "02" as MSB to |
| 7 | # prepare a 6 byte locally administered unicast MAC address. |
| 8 | # |
| 9 | # Format the output in xx:xx:xx:xx:xx:xx format for the "ip" |
| 10 | # set address command to work. |
| 11 | |
| 12 | ETHADDR=`cat /proc/cmdline | grep -o serialno.* | cut -f2 -d'=' |\ |
| 13 | awk '{printf("02%010s\n", $1)}' | sed 's/\(..\)/\1:/g' |\ |
| 14 | sed '$s/:$//'` |
| 15 | if [ -z "${ETHADDR}" ] |
| 16 | then |
| 17 | ETHADDR=`cat /proc/bootconfig | grep -o serialno.* |\ |
| 18 | cut -f2 -d'=' | cut -c 3-10 |\ |
| 19 | awk '{printf("02%010s\n", $1)}' | sed 's/\(..\)/\1:/g' |\ |
| 20 | sed '$s/:$//'` |
| 21 | fi |
| 22 | |
| 23 | ip link set dev eth0 down |
| 24 | ip link set dev eth0 address "${ETHADDR}" |
| 25 | ip link set dev eth0 up |