aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux
diff options
context:
space:
mode:
authorDavid Bauer <mail@david-bauer.net>2022-09-10 01:01:57 +0200
committerDavid Bauer <mail@david-bauer.net>2022-09-10 13:02:36 +0200
commit18f77ef2d6ee2d3b28f686cbbfff2d7b8c37fb7e (patch)
tree6f53c822f5b45d08aaac8b5d1369720cdbdde9ac /target/linux
parent8ff1d27e4895a597b00cb68b2e1936b186700223 (diff)
downloadupstream-18f77ef2d6ee2d3b28f686cbbfff2d7b8c37fb7e.tar.gz
upstream-18f77ef2d6ee2d3b28f686cbbfff2d7b8c37fb7e.tar.bz2
upstream-18f77ef2d6ee2d3b28f686cbbfff2d7b8c37fb7e.zip
rockchip: ensure NanoPi R4S has unique MAC address
Ensure the MAC address for all NanoPi R4S boards is assigned unique for each board. FriendlyElec ship two versions of the R4S: The standard as well as the enterprise edition with only the enterprise edition including the EEPROM chip that stores the unique MAC address. In order to assign both board types unique MAC addresses, fall back on the same method used for the NanoPi R2S 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_R4S#Differences_Between_R4S_Standard_Version_.26_R4S_Enterprise_Version Signed-off-by: David Bauer <mail@david-bauer.net> (cherry picked from commit b5675f500daff3ef3f904e53a5566aa7dc09b786)
Diffstat (limited to 'target/linux')
-rw-r--r--target/linux/rockchip/armv8/base-files/etc/board.d/02_network33
1 files changed, 28 insertions, 5 deletions
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 91bdb760d5..b0e6479947 100644
--- a/target/linux/rockchip/armv8/base-files/etc/board.d/02_network
+++ b/target/linux/rockchip/armv8/base-files/etc/board.d/02_network
@@ -17,13 +17,36 @@ rockchip_setup_interfaces()
esac
}
-nanopi_r2s_generate_mac()
+generate_mac_from_mmc_cid()
{
- local sd_hash=$(sha256sum /sys/class/block/mmcblk0/device/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}")")"
}
+nanopi_r4s_get_mac()
+{
+ local interface=$1
+ local eeprom_path="/sys/bus/i2c/devices/2-0051/eeprom"
+ local address
+
+ if [ -f "$eeprom_path" ]; then
+ address=$(get_mac_binary "$eeprom_path" 0xfa)
+ if [ "$interface" = "lan" ]; then
+ address=$(macaddr_setbit_la "$address")
+ fi
+ else
+ address=$(generate_mac_from_mmc_cid mmcblk1)
+ if [ "$interface" = "lan" ]; then
+ address=$(macaddr_add "$address" 1)
+ fi
+ fi
+
+ echo "$address"
+}
+
rockchip_setup_macs()
{
local board="$1"
@@ -33,12 +56,12 @@ rockchip_setup_macs()
case "$board" in
friendlyarm,nanopi-r2s)
- wan_mac=$(nanopi_r2s_generate_mac)
+ wan_mac=$(generate_mac_from_mmc_cid mmcblk0)
lan_mac=$(macaddr_add "$wan_mac" 1)
;;
friendlyarm,nanopi-r4s)
- wan_mac=$(get_mac_binary "/sys/bus/i2c/devices/2-0051/eeprom" 0xfa)
- lan_mac=$(macaddr_setbit_la "$wan_mac")
+ wan_mac=$(nanopi_r4s_get_mac wan)
+ lan_mac=$(nanopi_r4s_get_mac lan)
;;
esac