From d9c821597d29c93467f53fcd6c842f7da3027efe Mon Sep 17 00:00:00 2001 From: Jan-Niklas Burfeind Date: Fri, 23 Dec 2022 22:03:14 +0100 Subject: [PATCH] sunxi: ensure NanoPi R1 has unique MAC address Ensure the MAC address for all NanoPi R1 boards is assigned uniquely for each board. The vendor ships the device in two variants; one with and one without eMMC; but both without static mac-addresses. In order to assign both board types unique MAC addresses, fall back on the same method used for the NanoPi R2S and R4S in case the EEPROM chip is not present by generating the board MAC from the SD card CID. [0] https://wiki.friendlyelec.com/wiki/index.php/NanoPi_R1#Hardware_Spec Similar too and based on: commit b5675f500daf ("rockchip: ensure NanoPi R4S has unique MAC address") Co-authored-by: David Bauer Signed-off-by: Jan-Niklas Burfeind --- package/base-files/files/lib/functions/system.sh | 8 ++++++++ .../rockchip/armv8/base-files/etc/board.d/02_network | 11 ++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh index 46311ae0c..a5456594f 100644 --- a/package/base-files/files/lib/functions/system.sh +++ b/package/base-files/files/lib/functions/system.sh @@ -172,6 +172,14 @@ macaddr_add() { echo $oui:$nic } +macaddr_generate_from_mmc_cid() { + local mmc_dev=$1 + + local sd_hash=$(sha256sum /sys/class/block/$mmc_dev/device/cid) + local mac_base=$(macaddr_canonicalize "$(echo "${sd_hash}" | dd bs=1 count=12 2>/dev/null)") + echo "$(macaddr_unsetbit_mc "$(macaddr_setbit_la "${mac_base}")")" +} + macaddr_geteui() { local mac=$1 local sep=$2 diff --git a/target/linux/rockchip/armv8/base-files/etc/board.d/02_network b/target/linux/rockchip/armv8/base-files/etc/board.d/02_network index 17ce0ac3b..f383c2da1 100755 --- a/target/linux/rockchip/armv8/base-files/etc/board.d/02_network +++ b/target/linux/rockchip/armv8/base-files/etc/board.d/02_network @@ -46,13 +46,6 @@ rockchip_setup_interfaces() esac } -generate_mac_from_mmc_cid() -{ - local sd_hash=$(sha256sum /sys/class/block/mmcblk*/device/cid | head -n 1) - local mac_base=$(macaddr_canonicalize "$(echo "${sd_hash}" | dd bs=1 count=12 2>/dev/null)") - echo "$(macaddr_unsetbit_mc "$(macaddr_setbit_la "${mac_base}")")" -} - nanopi_r4s_get_mac() { local interface=$1 @@ -65,7 +58,7 @@ nanopi_r4s_get_mac() address=$(macaddr_setbit_la "$address") fi else - address=$(generate_mac_from_mmc_cid) + address=$(macaddr_generate_from_mmc_cid mmcblk1) if [ "$interface" = "lan" ]; then address=$(macaddr_add "$address" 1) fi @@ -99,7 +92,7 @@ rockchip_setup_macs() sharevdi,h3399pc|\ sharevdi,guangmiao-g4c|\ rocktech,mpc1903) - wan_mac=$(generate_mac_from_mmc_cid) + wan_mac=$(macaddr_generate_from_mmc_cid mmcblk0) lan_mac=$(macaddr_add "$wan_mac" +1) ;; friendlyarm,nanopi-r4s|\