[U-Boot] [PATCH v3] sunxi: Serial number support, obtained from SID bits and passed through ATAG

Paul Kocialkowski contact at paulk.fr
Sun Mar 22 12:42:35 CET 2015


Signed-off-by: Paul Kocialkowski <contact at paulk.fr>
---
 board/sunxi/board.c            | 50 +++++++++++++++++++++++++++++++++---------
 include/configs/sunxi-common.h |  1 +
 2 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index e1891d1..9e61a7d 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -241,23 +241,53 @@ static struct musb_hdrc_platform_data musb_plat = {
 };
 #endif
 
+#ifdef CONFIG_SERIAL_TAG
+void get_board_serial(struct tag_serialnr *serialnr)
+{
+	char *serial_string = getenv("serial#");
+	unsigned long long serial;
+
+	if (serial_string) {
+		serial = simple_strtoull(serial_string, NULL, 16);
+
+		serialnr->high = (unsigned int) (serial >> 32);
+		serialnr->low = (unsigned int) (serial & 0xffffffff);
+	} else {
+		serialnr->high = 0;
+		serialnr->low = 0;
+	}
+}
+#endif
+
 #ifdef CONFIG_MISC_INIT_R
 int misc_init_r(void)
 {
+	char serial_string[17] = { 0 };
 	unsigned int sid[4];
+	uint8_t mac_addr[6];
+	int ret;
+
+	ret = sunxi_get_sid(sid);
+	if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
+		if (!getenv("ethaddr")) {
+			/* Non OUI / registered MAC address */
+			mac_addr[0] = 0x02;
+			mac_addr[1] = (sid[0] >>  0) & 0xff;
+			mac_addr[2] = (sid[3] >> 24) & 0xff;
+			mac_addr[3] = (sid[3] >> 16) & 0xff;
+			mac_addr[4] = (sid[3] >>  8) & 0xff;
+			mac_addr[5] = (sid[3] >>  0) & 0xff;
+
+			eth_setenv_enetaddr("ethaddr", mac_addr);
+		}
 
-	if (!getenv("ethaddr") && sunxi_get_sid(sid) == 0 &&
-			sid[0] != 0 && sid[3] != 0) {
-		uint8_t mac_addr[6];
+		if (!getenv("serial#")) {
+			snprintf(serial_string, sizeof(serial_string),
+				"%08x%08x", sid[0], sid[3]);
 
-		mac_addr[0] = 0x02; /* Non OUI / registered MAC address */
-		mac_addr[1] = (sid[0] >>  0) & 0xff;
-		mac_addr[2] = (sid[3] >> 24) & 0xff;
-		mac_addr[3] = (sid[3] >> 16) & 0xff;
-		mac_addr[4] = (sid[3] >>  8) & 0xff;
-		mac_addr[5] = (sid[3] >>  0) & 0xff;
+			setenv("serial#", serial_string);
 
-		eth_setenv_enetaddr("ethaddr", mac_addr);
+		}
 	}
 
 #if defined(CONFIG_MUSB_HOST) || defined(CONFIG_MUSB_GADGET)
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
index 1f7a1cb..b9bb971 100644
--- a/include/configs/sunxi-common.h
+++ b/include/configs/sunxi-common.h
@@ -98,6 +98,7 @@
 #define CONFIG_SETUP_MEMORY_TAGS
 #define CONFIG_CMDLINE_TAG
 #define CONFIG_INITRD_TAG
+#define CONFIG_SERIAL_TAG
 
 /* mmc config */
 #if !defined(CONFIG_UART0_PORT_F)
-- 
1.9.1



More information about the U-Boot mailing list