[U-Boot] [PATCH 2/2] warp7: usb: Set u-boot serial# based on OTP value

Bryan O'Donoghue bryan.odonoghue at linaro.org
Tue Mar 13 12:00:27 UTC 2018


u-boot has a standard "serial#" environment variable that is suitable
for storing the iSerial number we will supply via the USB device
descriptor. serial# is automatically picked up by the disk subsystem in
u-boot - thus providing a handy unique identifier in /dev/disk/by-id as
detailed below.

Storing the hardware serial identifier in serial# means we can change the
serial# if we want before USB enumeration - thus making iSerial automatic
via OTP but overridable if necessary.

This patch reads the defined OTP fuse and sets environment variable
"serial#" to the value read. If there is any error in reading the value the
boot will continue and "serial#" will be set to zero.

With this patch in place the USB mass storage device will appear in
/dev/disk/by-id with a unique name based on the OTP value. For example

/dev/disk/by-id/usb-Linux_UMS_disk_0_WaRP7-0xf42400d3000000d4-0:0

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue at linaro.org>
Cc: Fabio Estevam <fabio.estevam at nxp.com>
Reviewed-by: Rui Miguel Silva <rui.silva at linaro.org>
Reviewed-by: Ryan Harkin <ryan.harkin at linaro.org>
---
 board/warp7/warp7.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/board/warp7/warp7.c b/board/warp7/warp7.c
index 2cec448..a27993f 100644
--- a/board/warp7/warp7.c
+++ b/board/warp7/warp7.c
@@ -239,6 +239,9 @@ int board_usb_phy_mode(int port)
 int board_late_init(void)
 {
 	struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
+	u64 serial_id = 0;
+	char serial_string[0x20];
+	int ret;
 
 	imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
 
@@ -250,5 +253,14 @@ int board_late_init(void)
 	 */
 	clrsetbits_le16(&wdog->wcr, 0, 0x10);
 
+	/* Set serial# standard environment variable based on OTP settings */
+	ret = warp7_get_serialid(&serial_id);
+	if (ret)
+		printf("error %d reading from serial# OTP fuse\n", ret);
+
+	snprintf(serial_string, sizeof(serial_string), "WaRP7-0x%016llx",
+		 serial_id);
+	env_set("serial#", serial_string);
+
 	return 0;
 }
-- 
2.7.4



More information about the U-Boot mailing list