svn commit: r305441 - stable/11/sys/arm/allwinner

Emmanuel Vadot manu at FreeBSD.org
Mon Sep 5 21:25:46 UTC 2016


Author: manu
Date: Mon Sep  5 21:25:45 2016
New Revision: 305441
URL: https://svnweb.freebsd.org/changeset/base/305441

Log:
  MFC r304509
  
  if_emac: Before generating a random MAC address, try using the SID rootkey
  to generate one. This is was U-Boot does to generate a random MAC so we end
  up with the same MAC address as if U-Boot did generate it.

Modified:
  stable/11/sys/arm/allwinner/if_emac.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/arm/allwinner/if_emac.c
==============================================================================
--- stable/11/sys/arm/allwinner/if_emac.c	Mon Sep  5 21:11:27 2016	(r305440)
+++ stable/11/sys/arm/allwinner/if_emac.c	Mon Sep  5 21:25:45 2016	(r305441)
@@ -77,6 +77,7 @@ __FBSDID("$FreeBSD$");
 #include <dev/mii/miivar.h>
 
 #include <arm/allwinner/if_emacreg.h>
+#include <arm/allwinner/aw_sid.h>
 
 #include <dev/extres/clk/clk.h>
 
@@ -167,12 +168,17 @@ static void
 emac_get_hwaddr(struct emac_softc *sc, uint8_t *hwaddr)
 {
 	uint32_t val0, val1, rnd;
+	u_char rootkey[16];
 
 	/*
 	 * Try to get MAC address from running hardware.
 	 * If there is something non-zero there just use it.
 	 *
 	 * Otherwise set the address to a convenient locally assigned address,
+	 * using the SID rootkey.
+	 * This is was uboot does so we end up with the same mac as if uboot
+	 * did set it.
+	 * If we can't get the root key, generate a random one,
 	 * 'bsd' + random 24 low-order bits. 'b' is 0x62, which has the locally
 	 * assigned bit set, and the broadcast/multicast bit clear.
 	 */
@@ -186,13 +192,23 @@ emac_get_hwaddr(struct emac_softc *sc, u
 		hwaddr[4] = (val0 >> 8) & 0xff;
 		hwaddr[5] = (val0 >> 0) & 0xff;
 	} else {
-		rnd = arc4random() & 0x00ffffff;
-		hwaddr[0] = 'b';
-		hwaddr[1] = 's';
-		hwaddr[2] = 'd';
-		hwaddr[3] = (rnd >> 16) & 0xff;
-		hwaddr[4] = (rnd >> 8) & 0xff;
-		hwaddr[5] = (rnd >> 0) & 0xff;
+		if (aw_sid_get_rootkey(rootkey) == 0) {
+			hwaddr[0] = 0x2;
+			hwaddr[1] = rootkey[3];
+			hwaddr[2] = rootkey[12];
+			hwaddr[3] = rootkey[13];
+			hwaddr[4] = rootkey[14];
+			hwaddr[5] = rootkey[15];
+		}
+		else {
+			rnd = arc4random() & 0x00ffffff;
+			hwaddr[0] = 'b';
+			hwaddr[1] = 's';
+			hwaddr[2] = 'd';
+			hwaddr[3] = (rnd >> 16) & 0xff;
+			hwaddr[4] = (rnd >> 8) & 0xff;
+			hwaddr[5] = (rnd >> 0) & 0xff;
+		}
 	}
 	if (bootverbose)
 		printf("MAC address: %s\n", ether_sprintf(hwaddr));


More information about the svn-src-all mailing list