From patchwork Wed Sep 13 21:29:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Agner X-Patchwork-Id: 813627 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; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=agner.ch header.i=@agner.ch header.b="gCQTRhQu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xsvwB4ZqBz9s81 for ; Thu, 14 Sep 2017 07:30:34 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id EEE91C2253F; Wed, 13 Sep 2017 21:30:32 +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=KHOP_BIG_TO_CC, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, 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 F0B93C2238D; Wed, 13 Sep 2017 21:30:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A6156C22188; Wed, 13 Sep 2017 21:30:28 +0000 (UTC) Received: from mail.kmu-office.ch (mail.kmu-office.ch [178.209.48.109]) by lists.denx.de (Postfix) with ESMTPS id 44C9CC224C1 for ; Wed, 13 Sep 2017 21:29:55 +0000 (UTC) Received: from trochilidae.toradex.int (75-146-58-181-Washington.hfc.comcastbusiness.net [75.146.58.181]) by mail.kmu-office.ch (Postfix) with ESMTPSA id CE4825C0ED9; Wed, 13 Sep 2017 23:26:04 +0200 (CEST) From: Stefan Agner To: sbabic@denx.de, fabio.estevam@nxp.com, eric@nelint.com Date: Wed, 13 Sep 2017 14:29:44 -0700 Message-Id: <20170913212945.5659-1-stefan@agner.ch> X-Mailer: git-send-email 2.14.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1505337967; bh=QeZ4YLtrmTF588jJypU5J+tuULbQTTd1VSJDGbEDFAo=; h=From:To:Cc:Subject:Date:Message-Id; b=gCQTRhQu68wLc/db5LOoZ1X1h5d4vFc7u1tP37sAvZTPZ/leutm2gyuiE9M6koa9q2DgHkTcmY2gdBTH8a3dOQp2A0sdndACRgxArYPGJrWDc8xyINJstjrgSRsq1CTmmaL4w6xbfWMwlnDzGRuH95AMCk0iFfrhvkxS2N4MZk4= Cc: marex@denx.de, albert.u.boot@aribaud.net, Stefan Agner , gary.bisson@boundarydevices.com, Marcel Ziswiler , joel.esponde@honeywell.com, u-boot@lists.denx.de, Max Krummenacher , jagan@openedev.com Subject: [U-Boot] [PATCH v3 1/2] imx: add macro to detect whether USB PHY is active 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" From: Stefan Agner This macro allows to detect whether the USB PHY is active. This is helpful to detect if the boot ROM has previously started the USB serial downloader. The idea is taken from the mfgtool support in the NXP U-Boot: http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/commit/?h=imx_v2016.03_4.1.15_2.0.0_ga&id=a352ed3c5184b95c4c9f7468f5fbb5f43de5e412 Signed-off-by: Stefan Agner Acked-by: Marcel Ziswiler Tested-by: Fabio Estevam Reviewed-by: Eric Nelson --- Changes in v4: - Rename macro to is_usbotg_phy_active() Changes in v3: None Changes in v2: - Move macro to sys_proto.h - Renamed from is_boot_from_usb() to is_usbphy_active() - Use defines for register offset and field - Remove tab after define - Remove comment since the actual "magic" is happening and documented at usage side arch/arm/include/asm/arch-mx6/sys_proto.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm/include/asm/arch-mx6/sys_proto.h b/arch/arm/include/asm/arch-mx6/sys_proto.h index 14f5d948c9..ba73943260 100644 --- a/arch/arm/include/asm/arch-mx6/sys_proto.h +++ b/arch/arm/include/asm/arch-mx6/sys_proto.h @@ -6,3 +6,10 @@ */ #include + +#define USBPHY_PWD 0x00000000 + +#define USBPHY_PWD_RXPWDRX (1 << 20) /* receiver block power down */ + +#define is_usbotg_phy_active(void) (!(readl(USB_PHY0_BASE_ADDR + USBPHY_PWD) & \ + USBPHY_PWD_RXPWDRX)) From patchwork Wed Sep 13 21:29:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Agner X-Patchwork-Id: 813628 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; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=agner.ch header.i=@agner.ch header.b="pjG7RZql"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xsvxD1RCwz9s81 for ; Thu, 14 Sep 2017 07:31:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id C22AFC22523; Wed, 13 Sep 2017 21:30:49 +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=KHOP_BIG_TO_CC, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, 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 08AA2C224DD; Wed, 13 Sep 2017 21:30:31 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BFF70C22440; Wed, 13 Sep 2017 21:30:28 +0000 (UTC) Received: from mail.kmu-office.ch (mail.kmu-office.ch [178.209.48.109]) by lists.denx.de (Postfix) with ESMTPS id 6791DC224F7 for ; Wed, 13 Sep 2017 21:29:58 +0000 (UTC) Received: from trochilidae.toradex.int (75-146-58-181-Washington.hfc.comcastbusiness.net [75.146.58.181]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 15E4A5C14BF; Wed, 13 Sep 2017 23:26:07 +0200 (CEST) From: Stefan Agner To: sbabic@denx.de, fabio.estevam@nxp.com, eric@nelint.com Date: Wed, 13 Sep 2017 14:29:45 -0700 Message-Id: <20170913212945.5659-2-stefan@agner.ch> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170913212945.5659-1-stefan@agner.ch> References: <20170913212945.5659-1-stefan@agner.ch> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1505337970; bh=zbaICzUgCiWdq/gkvAH+Y8JLvhpB8D9Q6BY7KcgvsG4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=pjG7RZqltioAKIeb+hhgxbmYdbAjOSbUGIvEM30qCYE1X58E3/9l6eQqVpiOxKAfW2RDWyoAjL7Rg2qd+JPzBFOkL2/ROVgmedWUFKUE1qQ5KTeuvMvwKMac21E8nzRiWdMOyNyHJRfkW7QYi1ftGairbN5jlzvcMn6b/MWw+ig= Cc: marex@denx.de, albert.u.boot@aribaud.net, Stefan Agner , gary.bisson@boundarydevices.com, Marcel Ziswiler , joel.esponde@honeywell.com, u-boot@lists.denx.de, Max Krummenacher , jagan@openedev.com Subject: [U-Boot] [PATCH v3 2/2] imx_common: detect USB serial downloader reliably 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" From: Stefan Agner The current mechanism using SCR/GPR registers work well when the serial downloader boot mode has been selected explicitly (either via boot mode pins or using bmode command). However, in case the system entered boot ROM due to unbootable primary boot devices (e.g. empty eMMC), the SPL fails to detect that it has been downloaded through serial loader and tries to continue booting from eMMC: Trying to boot from MMC1 mmc_load_image_raw_sector: mmc block read error SPL: failed to boot from all boot devices ### ERROR ### Please RESET the board ### The only known way to reliably detect USB serial downloader is by checking the USB PHY receiver block power state... Signed-off-by: Stefan Agner Acked-by: Marcel Ziswiler Tested-by: Fabio Estevam Reviewed-by: Eric Nelson --- Changes in v4: - Rename macro to is_usbotg_phy_active() Changes in v3: - Fix spelling and grammar Changes in v2: - Add comment that we infer boot ROM behavior from USB PHY state arch/arm/mach-imx/spl.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c index 258578ac25..534cc6504d 100644 --- a/arch/arm/mach-imx/spl.c +++ b/arch/arm/mach-imx/spl.c @@ -31,6 +31,18 @@ u32 spl_boot_device(void) if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */ return BOOT_DEVICE_BOARD; + /* + * The above method does not detect that the boot ROM used + * serial downloader in case the boot ROM decided to use the + * serial downloader as a fall back (primary boot source failed). + * + * Infer that the boot ROM used the USB serial downloader by + * checking whether the USB PHY is currently active... This + * assumes that SPL did not (yet) initialize the USB PHY... + */ + if (is_otgusb_phy_active()) + return BOOT_DEVICE_BOARD; + /* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */ switch ((reg & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) { /* EIM: See 8.5.1, Table 8-9 */