Re: [U-Boot] [PATCH 1/2] warp7: usb: Introduce a get method for serial number

2018-03-13 Thread Bryan O'Donoghue



On 13/03/18 13:25, Fabio Estevam wrote:

+static int warp7_get_serialid(u64 *id)

Maybe you could turn place this function in a common location as it
may be useful for others.



Ah, looking for a place to stick this as shared code I've found 
something which already does what this patch does


arch/arm/mach-imx/mx7/soc.c::void get_board_serial(struct tag_serialnr 
*serialnr)


commit c5752f73a53a ("imx: imx7d: Add SoC system support")
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 1/2] warp7: usb: Introduce a get method for serial number

2018-03-13 Thread Fabio Estevam
Hi Bryan,

On Tue, Mar 13, 2018 at 9:00 AM, Bryan O'Donoghue
 wrote:

> +static int warp7_get_serialid(u64 *id)

Maybe you could turn place this function in a common location as it
may be useful for others.

> +{
> +   u32 val;
> +   int ret;
> +
> +   if (!id)
> +   return -EINVAL;
> +
> +   /* Read first word */
> +   ret = fuse_read(WARP7_USB_SERIALID_BANK, WARP7_USB_SERIALID_MSWORD, 
> &val);
> +   if (ret)
> +   goto done;

Better just do 'return ret' instead of jumping to the 'done' label.
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/2] warp7: usb: Introduce a get method for serial number

2018-03-13 Thread Bryan O'Donoghue
We want to be able to set the USB device descriptor number iSerial number
or indeed a disk-label unique identifier based on a chip-specific piece of
data for the purposes of differentiating between WaRP7 boards via lsusb
when connected to a host machine.

In order to do this we want to have a serial number encoded in hardware,
which will persist across bootloader, filesystem and config file changes.

This patch utilises OCOTP_TESTER0 AND OCOTP_TESTER1 respectively for this
purpose. OCOTP_TESTER is a unique identifier for each chip representing

31:0 OCOTP_TESTER0 (most significant)
- FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID

OCOTP_TESTER1 (least significant)
31:24
- The X-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
23:16
- The Y-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
15:11
- The wafer number of the wafer on which the device was fabricated/SJC
  CHALLENGE/ Unique ID
10:0
- FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID

The 64 bits of data generate a unique serial number per-chip.

Signed-off-by: Bryan O'Donoghue 
Cc: Fabio Estevam 
Reviewed-by: Rui Miguel Silva 
Reviewed-by: Ryan Harkin 
---
 board/warp7/warp7.c | 53 +
 1 file changed, 53 insertions(+)

diff --git a/board/warp7/warp7.c b/board/warp7/warp7.c
index d422d63..2cec448 100644
--- a/board/warp7/warp7.c
+++ b/board/warp7/warp7.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include "../freescale/common/pfuze.h"
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -90,6 +91,58 @@ static struct fsl_esdhc_cfg usdhc_cfg[1] = {
{USDHC3_BASE_ADDR},
 };
 
+/*
+ * OCOTP_TESTER
+ * i.MX 7Solo Applications Processor Reference Manual, Rev. 0.1, 08/2016
+ * OCOTP_TESTER describes a unique ID based on silicon wafer
+ * and die X/Y position
+ *
+ * OCOTOP_TESTER offset 0x410
+ * 31:0 fuse 0
+ * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID
+ *
+ * OCOTP_TESTER1 offset 0x420
+ * 31:24 fuse 1
+ * The X-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
+ * 23:16 fuse 1
+ * The Y-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
+ * 15:11 fuse 1
+ * The wafer number of the wafer on which the device was fabricated/SJC
+ * CHALLENGE/ Unique ID
+ * 10:0 fuse 1
+ * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID
+ */
+#define WARP7_USB_SERIALID_BANK 0
+#define WARP7_USB_SERIALID_MSWORD 1
+#define WARP7_USB_SERIALID_LSWORD 2
+
+static int warp7_get_serialid(u64 *id)
+{
+   u32 val;
+   int ret;
+
+   if (!id)
+   return -EINVAL;
+
+   /* Read first word */
+   ret = fuse_read(WARP7_USB_SERIALID_BANK, WARP7_USB_SERIALID_MSWORD, 
&val);
+   if (ret)
+   goto done;
+
+   *id = val;
+   *id <<= 32;
+
+   /* Read second word */
+   ret = fuse_read(WARP7_USB_SERIALID_BANK, WARP7_USB_SERIALID_LSWORD, 
&val);
+   if (ret)
+   goto done;
+
+   *id |= val;
+
+done:
+   return ret;
+}
+
 int board_mmc_getcd(struct mmc *mmc)
 {
/* Assume uSDHC3 emmc is always present */
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot