RE: [PATCH] rockchip: use stable MAC-address for NanoPi R2S

2021-01-17 Thread Karl Palsson

"Adrian Schmutzler"  wrote:
> > +   local mac_base=$(macaddr_canonicalize "$(echo "${sd_hash}" | dd
> > bs=1 count=12 2>/dev/null)")
> 
> bs=12 count=1 ?


Why? unless you're passing other flags to try and magically avoid
the block layer, you're only operating on a 1k block read out
anyway. This sort of suggestion is pointless noise that just
makes things harder to read.

Sincerely,
Karl Palsson

OpenPGP-digital-signature.html
Description: OpenPGP Digital Signature
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


RE: [PATCH] rockchip: use stable MAC-address for NanoPi R2S

2021-01-16 Thread Adrian Schmutzler
> + local mac_base=$(macaddr_canonicalize "$(echo "${sd_hash}" | dd
> bs=1 count=12 2>/dev/null)")

bs=12 count=1 ?

Best

Adrian 


openpgp-digital-signature.asc
Description: PGP signature
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH] rockchip: use stable MAC-address for NanoPi R2S

2021-01-16 Thread David Bauer
The NanoPi R2S does not have a board specific MAC address written inside
e.g. an EEPROM, hence why it is randomly generated on first boot.

The issue with that however is the lack of a driver for the PRNG.
It often results to the same MAC address used on multiple boards by
default, as urngd is not active at this early stage resulting in low
available entropy.

There is however a semi-unique identifier available to us, which is the
CID of the used SD card. It is unique to each SD card, hence we can use
it to generate the MAC address used for LAN and WAN.

Signed-off-by: David Bauer 
---
 .../rockchip/armv8/base-files/etc/board.d/02_network | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

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 e129fd6a67..48133c81a1 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
@@ -17,6 +17,13 @@ rockchip_setup_interfaces()
esac
 }
 
+nanopi_r2s_generate_mac()
+{
+   local sd_hash=$(sha256sum 
/sys/devices/platform/ff50.dwmmc/mmc_host/mmc0/mmc0:*/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}")")"
+}
+
 rockchip_setup_macs()
 {
local board="$1"
@@ -26,7 +33,7 @@ rockchip_setup_macs()
 
case "$board" in
friendlyarm,nanopi-r2s)
-   wan_mac=$(macaddr_random)
+   wan_mac=$(nanopi_r2s_generate_mac)
lan_mac=$(macaddr_add "$wan_mac" +1)
;;
esac
-- 
2.30.0


___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel