From patchwork Tue Mar 13 12:00:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 885085 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Mv3KT5l0"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 400tmW6B5bz9sTH for ; Tue, 13 Mar 2018 23:03:39 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 6DD4EC21DFF; Tue, 13 Mar 2018 12:03:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D827BC21E07; Tue, 13 Mar 2018 12:01:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 86AC4C21C2F; Tue, 13 Mar 2018 12:01:51 +0000 (UTC) Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by lists.denx.de (Postfix) with ESMTPS id 39B7FC21D4A for ; Tue, 13 Mar 2018 12:00:32 +0000 (UTC) Received: by mail-wr0-f196.google.com with SMTP id s18so7936626wrg.9 for ; Tue, 13 Mar 2018 05:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J+vTUWRSZsTyuZCf0w6fyQq5wgRfN9zDPPdK9SFmdcg=; b=Mv3KT5l0CrwDB7YfXsf7x7C/1DWjbxgFg1v093fM+BnS4fPgINMH/oCQe30GMICfaX jLEtFWn/8DjF8mDDC3Pn8q1dlKhI6YdcYLiE3m+XKSlw4r8N/I/veS1Hk5eNRTv9ae76 8ipt5UrwIgnTyG8uOwFiFYYF56xQltFLWGYNo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=J+vTUWRSZsTyuZCf0w6fyQq5wgRfN9zDPPdK9SFmdcg=; b=Hj3sM961ntCQzsuMMCvu0Haq010pHapxSZCkvF3I7NgA2hEwwLXGSeDNOHmKLJp2HL +CNdFEtAxmoV1HAbAGdCqGd4xIlV9li+CmkhsApZRek5kPhTRbp+BhPM7illZ3wTwCIc 3e82t6GWSETLvrhqhCk8YxaKzwFAcpfFFQDd693vGDlDUMxgha4pUxJqhTKDGtCyzIRc DOVa8E/bnMscvcE3iVWPBUhj7jcowX1vxLzgROcvIgcz5VusmpEKc/ZAWTohCINa7Fvb APkiRtmyEoZmRSQ4SZoxwpm9AX74C4U8+gAw05yMX4IQmx2eBSXZIe1T6JojiXghHv1g A5Bw== X-Gm-Message-State: AElRT7E2pU21YsOfrdjYyqsfY6B9JP01TpqC4tTikRikWLEbAg8d5qd5 J4e57haP3gNPd5Sma9/f2LYo+VyS6Vk= X-Google-Smtp-Source: AG47ELu7gV/kn31zepngh/YxFb5m3sbgv7cn8+zMQKFZ5uqO0lAYq4n3FeIaWbKuEfxX0l3rMmvtMg== X-Received: by 10.80.135.229 with SMTP id 34mr601763edz.227.1520942431495; Tue, 13 Mar 2018 05:00:31 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id t23sm39130edb.54.2018.03.13.05.00.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Mar 2018 05:00:30 -0700 (PDT) From: Bryan O'Donoghue To: U-Boot@lists.denx.de Date: Tue, 13 Mar 2018 12:00:26 +0000 Message-Id: <1520942427-7366-2-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520942427-7366-1-git-send-email-bryan.odonoghue@linaro.org> References: <1520942427-7366-1-git-send-email-bryan.odonoghue@linaro.org> Cc: fabio.estevam@nxp.com, rui.silva@linaro.org Subject: [U-Boot] [PATCH 1/2] warp7: usb: Introduce a get method for serial number X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 */ From patchwork Tue Mar 13 12:00:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 885086 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="BbLWVh5s"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 400tnG09Lsz9sTD for ; Tue, 13 Mar 2018 23:04:17 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id A00F8C21E2C; Tue, 13 Mar 2018 12:03:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 75B7EC21E15; Tue, 13 Mar 2018 12:01:56 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 845A1C21D4A; Tue, 13 Mar 2018 12:01:52 +0000 (UTC) Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by lists.denx.de (Postfix) with ESMTPS id 4CCDDC21DC1 for ; Tue, 13 Mar 2018 12:00:33 +0000 (UTC) Received: by mail-wr0-f196.google.com with SMTP id m4so9066398wrb.7 for ; Tue, 13 Mar 2018 05:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BRO3EU+H5PkBTdpVKUGT9ZGNZHepqYt9czcZwNly938=; b=BbLWVh5sZM+sCpMfuK/FC1nHTGT40xvUWsJyI4OybuxZlHGIC2q3VMosd5BeApwMtz 7QoQiqYqatLPtX5CA811e6nLjVM/e5SYxQPx3k3Tk5jD2UIhSXBrY4yigxHdZdiPio+s 9jhvkBZUEToEznN6fVKnMnXUAFN8BDK1Y5dSk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BRO3EU+H5PkBTdpVKUGT9ZGNZHepqYt9czcZwNly938=; b=sGa2o/jGpqhG8dDegBYkudjYjTWCLPW8OrnS6SBd+3B7mQkSW0sBVYL81k29zm/ZcT zuieJud3Ni9tUgaBLwSeHBbSK04S17Suh/MqRHsNamld79BfuCOggq8T5GYFGSPTJ1iQ VOTtDcDnLjH0CvgmnFO19ckoMWKgNkuM9BuCh1boIG+Q2B9/H8FD43zGm//rThz8G9k+ SbDHwxst4novbkpp7M+MEFxe0zkGW9BmriGzOq2vvVGoQjQEdQncjUmEwn/HvrzFibMB aYKMm/F7MADSK5efzxaZxHA/A2OOEs2sa/AX2L705EUFGsnSIgDQ4ZPsz9Ub79QgiSDq pJHw== X-Gm-Message-State: AElRT7F9EP0KhMVJb2qhRb3cbXFOPZoRD1+GQv9YlZq4vtWoj20tpjbm 3VBII3WnR4VJks0uYPp2PV22noBMc+8= X-Google-Smtp-Source: AG47ELuti0rJDcdReDgZIoGrKotbuH3LP4Yf/VSaTSSeLRu/loxsIlVXow71hZMa9oQTj8gIlUo4dw== X-Received: by 10.80.217.136 with SMTP id w8mr616836edj.193.1520942432641; Tue, 13 Mar 2018 05:00:32 -0700 (PDT) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id t23sm39130edb.54.2018.03.13.05.00.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Mar 2018 05:00:31 -0700 (PDT) From: Bryan O'Donoghue To: U-Boot@lists.denx.de Date: Tue, 13 Mar 2018 12:00:27 +0000 Message-Id: <1520942427-7366-3-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520942427-7366-1-git-send-email-bryan.odonoghue@linaro.org> References: <1520942427-7366-1-git-send-email-bryan.odonoghue@linaro.org> Cc: fabio.estevam@nxp.com, rui.silva@linaro.org Subject: [U-Boot] [PATCH 2/2] warp7: usb: Set u-boot serial# based on OTP value X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 Cc: Fabio Estevam Reviewed-by: Rui Miguel Silva Reviewed-by: Ryan Harkin --- 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; }