From owner-svn-src-stable-11@freebsd.org Mon Sep 5 21:25:46 2016 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9C744AC4A4F; Mon, 5 Sep 2016 21:25:46 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5508A689; Mon, 5 Sep 2016 21:25:46 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u85LPj6w088166; Mon, 5 Sep 2016 21:25:45 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u85LPj8h088165; Mon, 5 Sep 2016 21:25:45 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201609052125.u85LPj8h088165@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Mon, 5 Sep 2016 21:25:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r305441 - stable/11/sys/arm/allwinner X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Sep 2016 21:25:46 -0000 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 #include +#include #include @@ -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));