[PATCH 1/1] Add option to OCOTP to retrieve iMX6 CPU serial #.

Michael D. Burkey mdburkey at gmail.com
Thu May 8 13:19:23 PDT 2014


This patch adds an option to the OCOTP file for the iMX6 to retrieve
the CPU serial number directly from the hardware using the
"barebox,provide-cpu-serial" devicetree entry.

Once retrieved, the CPU serial number is stuffed into the appropriate
ATAG for passing to the Linux kernel.

This functionality is required in order for barebox to match the
functionality provided by the current Variscite version of u-Boot and
is intended to work with the non-devicetree, Variscite 3.0.35 Linux
kernels (i.e. you need to do an "oftree -f" before attempting to boot
with one of the Variscite provided kernels).

Signed-off-by: Michael Burkey <mdburkey at gmail.com>
---

diff -rupN a/arch/arm/dts/imx6q-var-som.dtsi b/arch/arm/dts/imx6q-var-som.dtsi
--- a/arch/arm/dts/imx6q-var-som.dtsi	2014-05-05 04:33:13.000000000 -0400
+++ b/arch/arm/dts/imx6q-var-som.dtsi	2014-05-08 15:58:36.209506892 -0400
@@ -97,3 +97,7 @@
 		};
 	};
 };
+
+&ocotp {
+	barebox,provide-cpu-serial = <0x410>;
+};
diff -rupN a/arch/arm/mach-imx/ocotp.c b/arch/arm/mach-imx/ocotp.c
--- a/arch/arm/mach-imx/ocotp.c	2014-05-05 04:33:13.000000000 -0400
+++ b/arch/arm/mach-imx/ocotp.c	2014-05-08 15:59:47.636608932 -0400
@@ -25,6 +25,7 @@
 #include <net.h>
 #include <io.h>
 #include <of.h>
+#include <asm/armlinux.h>

 /*
  * a single MAC address reference has the form
@@ -32,6 +33,13 @@
  */
 #define MAC_ADDRESS_PROPLEN	(2 * sizeof(__be32))

+/*
+ * a single CPU serial number reference has the form
+ * <regoffset>
+ */
+#define CPU_SERIALNR_PROPLEN (1 * sizeof(__be32))
+
+
 static void imx_ocotp_init_dt(struct device_d *dev, void __iomem *base)
 {
 	char mac[6];
@@ -43,31 +51,53 @@ static void imx_ocotp_init_dt(struct dev
 		return;

 	prop = of_get_property(node, "barebox,provide-mac-address", &len);
-	if (!prop)
-		return;
-
-	while (len >= MAC_ADDRESS_PROPLEN) {
-		struct device_node *rnode;
-		uint32_t phandle, offset, value;
-
-		phandle = be32_to_cpup(prop++);
-
-		rnode = of_find_node_by_phandle(phandle);
-		offset = be32_to_cpup(prop++);
-
-		value = readl(base + offset + 0x10);
-		mac[0] = (value >> 8);
-		mac[1] = value;
-		value = readl(base + offset);
-		mac[2] = value >> 24;
-		mac[3] = value >> 16;
-		mac[4] = value >> 8;
-		mac[5] = value;
-
-		of_eth_register_ethaddr(rnode, mac);
-
-		len -= MAC_ADDRESS_PROPLEN;
-	}
+	if (prop)
+    {
+	    while (len >= MAC_ADDRESS_PROPLEN) {
+		    struct device_node *rnode;
+		    uint32_t phandle, offset, value;
+
+		    phandle = be32_to_cpup(prop++);
+
+		    rnode = of_find_node_by_phandle(phandle);
+		    offset = be32_to_cpup(prop++);
+
+		    value = readl(base + offset + 0x10);
+		    mac[0] = (value >> 8);
+		    mac[1] = value;
+		    value = readl(base + offset);
+		    mac[2] = value >> 24;
+		    mac[3] = value >> 16;
+		    mac[4] = value >> 8;
+		    mac[5] = value;
+
+		    of_eth_register_ethaddr(rnode, mac);
+
+		    len -= MAC_ADDRESS_PROPLEN;
+	    }
+    }
+
+	prop = of_get_property(node, "barebox,provide-cpu-serial", &len);
+	if (prop)
+    {
+        while (len >= CPU_SERIALNR_PROPLEN) {
+            u64 serialnr;
+		    uint32_t offset;
+
+		    offset = be32_to_cpup(prop++);
+
+        	/* Read the i.MX6 Processor Serial # from the fuses */
+        	serialnr = (u64) readl(base + offset);
+        	serialnr |= ((u64) readl(base + offset + 0x10)) << 32;
+
+            /* Set the appropriate system MagicVar */
+        	armlinux_set_serial(serialnr);	
+
+		    len -= CPU_SERIALNR_PROPLEN;
+        }
+    }
+
+	return;
 }

 static int imx_ocotp_probe(struct device_d *dev)



More information about the barebox mailing list