diff mbox series

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

Message ID 1520942427-7366-3-git-send-email-bryan.odonoghue@linaro.org
State New
Headers show
Series NXP WaARP7 set serial# from OTP fuses for USB iSerial | expand

Commit Message

Bryan O'Donoghue March 13, 2018, noon UTC
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@linaro.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Ryan Harkin <ryan.harkin@linaro.org>
---
 board/warp7/warp7.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Fabio Estevam March 13, 2018, 1:03 p.m. UTC | #1
Hi Bryan,

On Tue, Mar 13, 2018 at 9:00 AM, Bryan O'Donoghue
<bryan.odonoghue@linaro.org> wrote:

> +       /* 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);

Isn't a 'return ret' missing here?
diff mbox series

Patch

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;
 }