aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Rigby <john.rigby@linaro.org>2011-07-13 20:31:47 -0600
committerJohn Rigby <john.rigby@linaro.org>2011-07-13 22:04:19 -0600
commit99228f7aea0137c5bd4d6e2f32ebd4635e2b603c (patch)
tree0032865fbc61b9fa22bcace8e0a06d4c5c8c2747
parentcfb4154c6f54aae4f79b5327f99209fd931fdc7a (diff)
omap4: panda: generate a unique usbethaddr
The panda board has a usb nic but the nic has no rom. Use the die-id to generate a unique address. This is derived from an RFC kernel patch by Andy Green that does the same thing: https://patchwork.kernel.org/patch/660541/ [RFC PATCH 1/2] OMAP2+: add cpu id register to MAC address helper Signed-off-by: John Rigby <john.rigby@linaro.org>
-rw-r--r--arch/arm/cpu/armv7/omap4/sys_info.c41
-rw-r--r--arch/arm/include/asm/arch-omap4/cpu.h12
-rw-r--r--arch/arm/include/asm/arch-omap4/sys_proto.h1
-rw-r--r--board/ti/panda/panda.c18
-rw-r--r--include/configs/omap4_panda.h1
5 files changed, 72 insertions, 1 deletions
diff --git a/arch/arm/cpu/armv7/omap4/sys_info.c b/arch/arm/cpu/armv7/omap4/sys_info.c
index b9e57659f..7800d180a 100644
--- a/arch/arm/cpu/armv7/omap4/sys_info.c
+++ b/arch/arm/cpu/armv7/omap4/sys_info.c
@@ -23,6 +23,7 @@
*/
#include <common.h>
+#include <asm/io.h>
#include <asm/arch/sys_proto.h>
/*
@@ -51,3 +52,43 @@ int print_cpuinfo(void)
return 0;
}
+
+/*
+ * this uses the unique per-cpu info from the cpu fuses set at factory to
+ * generate a 6-byte MAC address. Two bits in the generated code are used
+ * to elaborate the generated address into four, so it can be used on multiple
+ * network interfaces.
+ */
+
+void omap4_die_id_to_ethernet_mac(u8 *mac, int subtype)
+{
+ struct ctrl_id *id_base = (struct ctrl_id *)(CTRL_BASE + 0x200);
+ u32 idcode;
+ u32 id[4];
+
+ idcode = readl(&id_base->idcode);
+ id[0] = readl(&id_base->die_id_0);
+ id[1] = readl(&id_base->die_id_1);
+ id[2] = readl(&id_base->die_id_2);
+ id[3] = readl(&id_base->die_id_3);
+
+ mac[0] = id[2];
+ mac[1] = id[2] >> 8;
+ mac[2] = id[1];
+ mac[3] = id[1] >> 8;
+ mac[4] = id[1] >> 16;
+ mac[5] = id[1] >> 24;
+ /* XOR other chip-specific data with ID */
+ idcode ^= id[3];
+
+ mac[0] ^= idcode;
+ mac[1] ^= idcode >> 8;
+ mac[2] ^= idcode >> 16;
+ mac[3] ^= idcode >> 24;
+
+ /* allow four MACs from this same basic data */
+ mac[1] = (mac[1] & ~0xc0) | ((subtype & 3) << 6);
+
+ /* mark it as not multicast and outside official 80211 MAC namespace */
+ mac[0] = (mac[0] & ~1) | 2;
+}
diff --git a/arch/arm/include/asm/arch-omap4/cpu.h b/arch/arm/include/asm/arch-omap4/cpu.h
index 7d5748acd..f43de7d31 100644
--- a/arch/arm/include/asm/arch-omap4/cpu.h
+++ b/arch/arm/include/asm/arch-omap4/cpu.h
@@ -94,6 +94,18 @@ struct gptimer {
u32 tcicr; /* 0x40 rw */
u32 tcar2; /* 0x44 r */
};
+
+struct ctrl_id {
+ u32 die_id_0; /* 0x00 */
+ u32 idcode; /* 0x04 */
+ u32 die_id_1; /* 0x08 */
+ u32 die_id_2; /* 0x0c */
+ u32 die_id_3; /* 0x10 */
+ u32 prod_id_0; /* 0x14 */
+ u32 prod_id_1; /* 0x18 */
+};
+
+
#endif /* __ASSEMBLY__ */
#endif /* __KERNEL_STRICT_NAMES */
diff --git a/arch/arm/include/asm/arch-omap4/sys_proto.h b/arch/arm/include/asm/arch-omap4/sys_proto.h
index 4813e9e21..8d92dd47f 100644
--- a/arch/arm/include/asm/arch-omap4/sys_proto.h
+++ b/arch/arm/include/asm/arch-omap4/sys_proto.h
@@ -36,6 +36,7 @@ void set_muxconf_regs(void);
void sr32(void *, u32, u32, u32);
u32 wait_on_value(u32, u32, void *, u32);
void sdelay(unsigned long);
+void omap4_die_id_to_ethernet_mac(u8 *, int);
extern const struct omap_sysinfo sysinfo;
diff --git a/board/ti/panda/panda.c b/board/ti/panda/panda.c
index 78e191079..0ac23646c 100644
--- a/board/ti/panda/panda.c
+++ b/board/ti/panda/panda.c
@@ -48,8 +48,26 @@ int board_init(void)
return 0;
}
+/*
+ * Panda has a usb nic with no ethernet rom so generate a macaddr
+ * from the SOC die-id and set the usbethaddr env var to that
+ * value.
+ */
int board_eth_init(bd_t *bis)
{
+ u8 macaddr[6];
+ char usbethaddr[20];
+
+ /*
+ * NB: The 1 here has been found to generate an address
+ * consistent with the kernel.
+ */
+ omap4_die_id_to_ethernet_mac(macaddr, 1);
+ sprintf (usbethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
+ macaddr[0], macaddr[1],
+ macaddr[2], macaddr[3],
+ macaddr[4], macaddr[5]) ;
+ setenv ("usbethaddr", usbethaddr);
return 0;
}
diff --git a/include/configs/omap4_panda.h b/include/configs/omap4_panda.h
index 7bb971cd7..d3063f40b 100644
--- a/include/configs/omap4_panda.h
+++ b/include/configs/omap4_panda.h
@@ -178,7 +178,6 @@
"console=ttyS2,115200n8\0" \
"usbtty=cdc_acm\0" \
"vram=16M\0" \
- "usbethaddr=00:02:03:04:05:06\0" \
"hostname=panda\0" \
"mmcdev=0\0" \
"mmcroot=/dev/mmcblk0p2 rw\0" \