* [U-Boot] [PATCH] sunxi: use random parts of SID to set ethaddr
@ 2014-06-14 6:59 Hans de Goede
2014-06-14 9:46 ` Ian Campbell
0 siblings, 1 reply; 3+ messages in thread
From: Hans de Goede @ 2014-06-14 6:59 UTC (permalink / raw)
To: u-boot
From: Jonathan Liu <net147@gmail.com>
Similar to the USB NIC found on OMAP5uEVM, PandaBoard and BeagleBoard-XM
boards, the sunxi SoCs have a NIC onboard without an embedded MAC address.
Just like the omap used on these boards, the sunxi SoCs do have a unique chip
id, in the form of the 128 bit SID register:
http://linux-sunxi.org/SID_Register_Guide
So mimick the BeagleBoard-XM board code (commit 548a64d8) and use the chip id
to generate a unique fixed MAC address.
We check for the SID not being all 0, since some early A20 batches
shipped without having there SID programmed.
Note we use specific parts of the 128 bits, since some parts indicate the
SoC family / revision, and thus are fixed. The algorithm for this was taken
from the linux-sunxi.org kernels.
Signed-off-by: Jonathan Liu <net147@gmail.com>
[hdegoede at redhat.com: Expanded the commit message with some more info]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
board/sunxi/board.c | 28 ++++++++++++++++++++++++++++
include/configs/sunxi-common.h | 2 ++
2 files changed, 30 insertions(+)
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 8607eb3..2179e23 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -19,9 +19,12 @@
#include <axp209.h>
#endif
#include <asm/arch/clock.h>
+#include <asm/arch/cpu.h>
#include <asm/arch/dram.h>
#include <asm/arch/gpio.h>
#include <asm/arch/mmc.h>
+#include <asm/io.h>
+#include <net.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -157,3 +160,28 @@ void sunxi_board_init(void)
printf("Failed to set core voltage! Can't set CPU frequency\n");
}
#endif
+
+#ifdef CONFIG_MISC_INIT_R
+int misc_init_r(void)
+{
+ if (!getenv("ethaddr")) {
+ uint32_t reg_val = readl(SUNXI_SID_BASE);
+
+ if (reg_val) {
+ uint8_t mac_addr[6];
+
+ mac_addr[0] = 0x02; /* Non OUI / registered MAC address */
+ mac_addr[1] = (reg_val >> 0) & 0xff;
+ reg_val = readl(SUNXI_SID_BASE + 0x0c);
+ mac_addr[2] = (reg_val >> 24) & 0xff;
+ mac_addr[3] = (reg_val >> 16) & 0xff;
+ mac_addr[4] = (reg_val >> 8) & 0xff;
+ mac_addr[5] = (reg_val >> 0) & 0xff;
+
+ eth_setenv_enetaddr("ethaddr", mac_addr);
+ }
+ }
+
+ return 0;
+}
+#endif
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
index 4083388..13e72d5 100644
--- a/include/configs/sunxi-common.h
+++ b/include/configs/sunxi-common.h
@@ -207,6 +207,8 @@
#define CONFIG_ENV_IS_NOWHERE
#endif
+#define CONFIG_MISC_INIT_R
+
#ifndef CONFIG_SPL_BUILD
#include <config_distro_defaults.h>
#endif
--
2.0.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] sunxi: use random parts of SID to set ethaddr
2014-06-14 6:59 [U-Boot] [PATCH] sunxi: use random parts of SID to set ethaddr Hans de Goede
@ 2014-06-14 9:46 ` Ian Campbell
2014-07-23 19:05 ` Siarhei Siamashka
0 siblings, 1 reply; 3+ messages in thread
From: Ian Campbell @ 2014-06-14 9:46 UTC (permalink / raw)
To: u-boot
On Sat, 2014-06-14 at 08:59 +0200, Hans de Goede wrote:
> From: Jonathan Liu <net147@gmail.com>
>
> Similar to the USB NIC found on OMAP5uEVM, PandaBoard and BeagleBoard-XM
> boards, the sunxi SoCs have a NIC onboard without an embedded MAC address.
>
> Just like the omap used on these boards, the sunxi SoCs do have a unique chip
> id, in the form of the 128 bit SID register:
> http://linux-sunxi.org/SID_Register_Guide
>
> So mimick the BeagleBoard-XM board code (commit 548a64d8) and use the chip id
> to generate a unique fixed MAC address.
>
> We check for the SID not being all 0, since some early A20 batches
> shipped without having there SID programmed.
>
> Note we use specific parts of the 128 bits, since some parts indicate the
> SoC family / revision, and thus are fixed. The algorithm for this was taken
> from the linux-sunxi.org kernels.
>
> Signed-off-by: Jonathan Liu <net147@gmail.com>
> [hdegoede at redhat.com: Expanded the commit message with some more info]
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] sunxi: use random parts of SID to set ethaddr
2014-06-14 9:46 ` Ian Campbell
@ 2014-07-23 19:05 ` Siarhei Siamashka
0 siblings, 0 replies; 3+ messages in thread
From: Siarhei Siamashka @ 2014-07-23 19:05 UTC (permalink / raw)
To: u-boot
On Sat, 14 Jun 2014 10:46:37 +0100
Ian Campbell <ijc@hellion.org.uk> wrote:
> On Sat, 2014-06-14 at 08:59 +0200, Hans de Goede wrote:
> > From: Jonathan Liu <net147@gmail.com>
> >
> > Similar to the USB NIC found on OMAP5uEVM, PandaBoard and BeagleBoard-XM
> > boards, the sunxi SoCs have a NIC onboard without an embedded MAC address.
> >
> > Just like the omap used on these boards, the sunxi SoCs do have a unique chip
> > id, in the form of the 128 bit SID register:
> > http://linux-sunxi.org/SID_Register_Guide
> >
> > So mimick the BeagleBoard-XM board code (commit 548a64d8) and use the chip id
> > to generate a unique fixed MAC address.
> >
> > We check for the SID not being all 0, since some early A20 batches
> > shipped without having there SID programmed.
> >
> > Note we use specific parts of the 128 bits, since some parts indicate the
> > SoC family / revision, and thus are fixed. The algorithm for this was taken
> > from the linux-sunxi.org kernels.
> >
> > Signed-off-by: Jonathan Liu <net147@gmail.com>
> > [hdegoede at redhat.com: Expanded the commit message with some more info]
> > Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>
> Acked-by: Ian Campbell <ijc@hellion.org.uk>
Acked-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
--
Best regards,
Siarhei Siamashka
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-07-23 19:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-14 6:59 [U-Boot] [PATCH] sunxi: use random parts of SID to set ethaddr Hans de Goede
2014-06-14 9:46 ` Ian Campbell
2014-07-23 19:05 ` Siarhei Siamashka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox