[U-Boot] [PATCH 1/2] ARM: tegra: shut down USB device controller at boot

From: Stephen Warren swarren@nvidia.com
When loading U-Boot into RAM over USB protocols using tools such as tegrarcm or L4T's exec-uboot.sh/tegraflash.py, Tegra's USB device mode controller is initialized and enumerated by the host PC running the tool. Unfortunately, these tools do not shut down the USB controller before executing the downloaded code, and so the host PC does not "de-enumerate" the USB device. This patch implements optional code to shut down the USB controller when U-Boot boots to avoid leaving a stale USB device present.
Signed-off-by: Stephen Warren swarren@nvidia.com --- This patch needs to be applied along with the next patch in this series, likely in u-boot-dm since that patch modifies test code that's only currently present in u-boot-dm. --- arch/arm/mach-tegra/Kconfig | 13 +++++++++++++ arch/arm/mach-tegra/board2.c | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-tegra/Kconfig b/arch/arm/mach-tegra/Kconfig index 48a387c95713..0b2852c4dae5 100644 --- a/arch/arm/mach-tegra/Kconfig +++ b/arch/arm/mach-tegra/Kconfig @@ -52,6 +52,19 @@ config TEGRA210
endchoice
+config TEGRA_DISCONNECT_UDC_ON_BOOT + bool "Disconnect USB device mode controller on boot" + default y + help + When loading U-Boot into RAM over USB protocols using tools such as + tegrarcm or L4T's exec-uboot.sh/tegraflash.py, Tegra's USB device + mode controller is initialized and enumerated by the host PC running + the tool. Unfortunately, these tools do not shut down the USB + controller before executing the downloaded code, and so the host PC + does not "de-enumerate" the USB device. This option shuts down the + USB controller when U-Boot boots to avoid leaving a stale USB device + present. + config SYS_MALLOC_F_LEN default 0x1800
diff --git a/arch/arm/mach-tegra/board2.c b/arch/arm/mach-tegra/board2.c index a650abd731ad..60e19c838784 100644 --- a/arch/arm/mach-tegra/board2.c +++ b/arch/arm/mach-tegra/board2.c @@ -34,8 +34,8 @@ #ifdef CONFIG_TEGRA_CLOCK_SCALING #include <asm/arch/emc.h> #endif -#ifdef CONFIG_USB_EHCI_TEGRA #include <asm/arch-tegra/usb.h> +#ifdef CONFIG_USB_EHCI_TEGRA #include <usb.h> #endif #ifdef CONFIG_TEGRA_MMC @@ -201,6 +201,14 @@ void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
int board_early_init_f(void) { +#if defined(CONFIG_TEGRA_DISCONNECT_UDC_ON_BOOT) +#define USBCMD_FS2 (1 << 15) + { + struct usb_ctlr *usbctlr = (struct usb_ctlr *)0x7d000000; + writel(USBCMD_FS2, &usbctlr->usb_cmd); + } +#endif + /* Do any special system timer/TSC setup */ #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE) if (!tegra_cpu_is_non_secure())

From: Stephen Warren swarren@nvidia.com
The DFU test requests U-Boot configure its USB controller in device mode, then waits for the host machine to enumerate the USB device and create a device node for it. However, this wait can be fooled if the USB device node already exists before the test starts, e.g. if some previous software stack already configured the USB controller into device mode and never de-configured it. This "previous software stack" could even be another test/py test, if U-Boot's own USB teardown does not operate correctly. If this happens, dfu-util may be run before U-Boot is ready to serve DFU commands, which may cause false test failures.
Enhance the dfu test to fail if the device node exists before it is expected to.
Signed-off-by: Stephen Warren swarren@nvidia.com --- This patch depends on the previous patch "ARM: tegra: shut down USB device controller at boot", so needs to be applied in the same branch. Otherwise, test failures will occur. --- test/py/tests/test_dfu.py | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/test/py/tests/test_dfu.py b/test/py/tests/test_dfu.py index cc4b8d8e04e6..6c1a363b02df 100644 --- a/test/py/tests/test_dfu.py +++ b/test/py/tests/test_dfu.py @@ -100,6 +100,12 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config): Nothing. '''
+ fh = u_boot_utils.attempt_to_open_file( + env__usb_dev_port['host_usb_dev_node']) + if fh: + fh.close() + raise Exception('USB device present before dfu command invoked') + u_boot_console.log.action( 'Starting long-running U-Boot dfu shell command')

On 26 January 2016 at 10:59, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
The DFU test requests U-Boot configure its USB controller in device mode, then waits for the host machine to enumerate the USB device and create a device node for it. However, this wait can be fooled if the USB device node already exists before the test starts, e.g. if some previous software stack already configured the USB controller into device mode and never de-configured it. This "previous software stack" could even be another test/py test, if U-Boot's own USB teardown does not operate correctly. If this happens, dfu-util may be run before U-Boot is ready to serve DFU commands, which may cause false test failures.
Enhance the dfu test to fail if the device node exists before it is expected to.
Signed-off-by: Stephen Warren swarren@nvidia.com
This patch depends on the previous patch "ARM: tegra: shut down USB device controller at boot", so needs to be applied in the same branch. Otherwise, test failures will occur.
test/py/tests/test_dfu.py | 6 ++++++ 1 file changed, 6 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On 26 January 2016 at 12:59, Simon Glass sjg@chromium.org wrote:
On 26 January 2016 at 10:59, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
The DFU test requests U-Boot configure its USB controller in device mode, then waits for the host machine to enumerate the USB device and create a device node for it. However, this wait can be fooled if the USB device node already exists before the test starts, e.g. if some previous software stack already configured the USB controller into device mode and never de-configured it. This "previous software stack" could even be another test/py test, if U-Boot's own USB teardown does not operate correctly. If this happens, dfu-util may be run before U-Boot is ready to serve DFU commands, which may cause false test failures.
Enhance the dfu test to fail if the device node exists before it is expected to.
Signed-off-by: Stephen Warren swarren@nvidia.com
This patch depends on the previous patch "ARM: tegra: shut down USB device controller at boot", so needs to be applied in the same branch. Otherwise, test failures will occur.
test/py/tests/test_dfu.py | 6 ++++++ 1 file changed, 6 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm, thanks!

On 26 January 2016 at 10:59, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
When loading U-Boot into RAM over USB protocols using tools such as tegrarcm or L4T's exec-uboot.sh/tegraflash.py, Tegra's USB device mode controller is initialized and enumerated by the host PC running the tool. Unfortunately, these tools do not shut down the USB controller before executing the downloaded code, and so the host PC does not "de-enumerate" the USB device. This patch implements optional code to shut down the USB controller when U-Boot boots to avoid leaving a stale USB device present.
Signed-off-by: Stephen Warren swarren@nvidia.com
This patch needs to be applied along with the next patch in this series, likely in u-boot-dm since that patch modifies test code that's only currently present in u-boot-dm.
arch/arm/mach-tegra/Kconfig | 13 +++++++++++++ arch/arm/mach-tegra/board2.c | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

On 26 January 2016 at 12:59, Simon Glass sjg@chromium.org wrote:
On 26 January 2016 at 10:59, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
When loading U-Boot into RAM over USB protocols using tools such as tegrarcm or L4T's exec-uboot.sh/tegraflash.py, Tegra's USB device mode controller is initialized and enumerated by the host PC running the tool. Unfortunately, these tools do not shut down the USB controller before executing the downloaded code, and so the host PC does not "de-enumerate" the USB device. This patch implements optional code to shut down the USB controller when U-Boot boots to avoid leaving a stale USB device present.
Signed-off-by: Stephen Warren swarren@nvidia.com
This patch needs to be applied along with the next patch in this series, likely in u-boot-dm since that patch modifies test code that's only currently present in u-boot-dm.
arch/arm/mach-tegra/Kconfig | 13 +++++++++++++ arch/arm/mach-tegra/board2.c | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm, thanks!
participants (2)
-
Simon Glass
-
Stephen Warren