From patchwork Tue Mar 15 02:42:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jimmzhang X-Patchwork-Id: 597336 X-Patchwork-Delegate: swarren@nvidia.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3qPJnl1t5Dz9snk for ; Tue, 15 Mar 2016 13:43:07 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932113AbcCOCnG (ORCPT ); Mon, 14 Mar 2016 22:43:06 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:16496 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932076AbcCOCnF (ORCPT ); Mon, 14 Mar 2016 22:43:05 -0400 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com id ; Mon, 14 Mar 2016 19:43:25 -0700 Received: from hqemhub02.nvidia.com ([172.20.150.31]) by hqnvupgp07.nvidia.com (PGP Universal service); Mon, 14 Mar 2016 19:41:37 -0700 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Mon, 14 Mar 2016 19:41:37 -0700 Received: from jimmzhang-P9X79.nvidia.com (172.20.144.16) by hqemhub02.nvidia.com (172.20.150.31) with Microsoft SMTP Server (TLS) id 8.3.406.0; Mon, 14 Mar 2016 19:43:03 -0700 From: Jimmy Zhang To: , , CC: , Jimmy Zhang Subject: [tegrarcm PATCH V3 4/4] Add option --usb-timeout= Date: Mon, 14 Mar 2016 19:42:47 -0700 Message-ID: <1458009767-26615-5-git-send-email-jimmzhang@nvidia.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1458009767-26615-1-git-send-email-jimmzhang@nvidia.com> References: <1458009767-26615-1-git-send-email-jimmzhang@nvidia.com> MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org RCM communication sometimes fails if the USB timeout is short. The default timeout is 1000ms. Increasing the timeout value may avoid this issue. The exact cause is not yet diagnosed. Value 0 means unlimited timeout. Example: $ sudo tegrarcm --bct=jetson-tk1-bct.bct --bootloader=u-boot.bin \ --loadaddr=0x83d88000 --pkc=rsa_priv.der --usb-timeout=5000 Signed-off-by: Jimmy Zhang --- src/main.c | 8 ++++++++ src/usb.c | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 57cd2d84e5ae..f20ab3a98729 100644 --- a/src/main.c +++ b/src/main.c @@ -87,6 +87,7 @@ static void set_platform_info(nv3p_platform_info_t *info); static uint32_t get_op_mode(void); static nv3p_platform_info_t *g_platform_info = NULL; +extern uint32_t usb_timeout; enum cmdline_opts { OPT_BCT, @@ -105,6 +106,7 @@ enum cmdline_opts { OPT_SIGNED_MSGS_FILE, OPT_SOC, OPT_DOWNLOAD_SIGNED_MSGS, + OPT_USB_TIMEOUT, OPT_END, }; @@ -155,6 +157,8 @@ static void usage(char *progname) fprintf(stderr, "\t\tSpecify Tegra SoC chip model number, ie, 124.\n"); fprintf(stderr, "\t--download-signed-msgs\n"); fprintf(stderr, "\t\tDownload signed messages\n"); + fprintf(stderr, "\t--usb-timeout=\n"); + fprintf(stderr, "\t\tSpecify usb transfer timeout value in ms, 0 for unlimited timeout\n"); fprintf(stderr, "\n"); } @@ -259,6 +263,7 @@ int main(int argc, char **argv) [OPT_SIGNED_MSGS_FILE] = {"signed-msgs-file", 1, 0, 0}, [OPT_SOC] = {"soc", 1, 0, 0}, [OPT_DOWNLOAD_SIGNED_MSGS] = {"download-signed-msgs", 0, 0, 0}, + [OPT_USB_TIMEOUT] = {"usb-timeout", 1, 0, 0}, [OPT_END] = {0, 0, 0, 0} }; // parse command line args @@ -316,6 +321,9 @@ int main(int argc, char **argv) case OPT_DOWNLOAD_SIGNED_MSGS: download_signed_msgs = true; break; + case OPT_USB_TIMEOUT: + usb_timeout = strtoul(optarg, NULL, 0); + break; case OPT_HELP: default: usage(argv[0]); diff --git a/src/usb.c b/src/usb.c index 8a367426b29c..5bed1efd7a21 100644 --- a/src/usb.c +++ b/src/usb.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, NVIDIA CORPORATION + * Copyright (c) 2011-2016, NVIDIA CORPORATION * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -39,6 +39,7 @@ #define USB_XFER_MAX 4096 +uint32_t usb_timeout = USB_TIMEOUT; // // returns 1 if the specified usb device matches the vendor id // @@ -307,7 +308,7 @@ int usb_write(usb_device_t *usb, uint8_t *buf, int len) while (len) { chunk_size = MIN(len, USB_XFER_MAX); ret = libusb_bulk_transfer(usb->handle, usb->endpt_out, buf, - chunk_size, &actual_chunk, USB_TIMEOUT); + chunk_size, &actual_chunk, usb_timeout); if (ret != LIBUSB_SUCCESS) { dprintf("libusb write failure: %d: %s\n", ret, libusb_error_name(ret)); return EIO; @@ -334,7 +335,7 @@ int usb_read(usb_device_t *usb, uint8_t *buf, int len, int *actual_len) while (len) { chunk_size = MIN(len, USB_XFER_MAX); ret = libusb_bulk_transfer(usb->handle, usb->endpt_in, buf, - chunk_size, &actual_chunk, USB_TIMEOUT); + chunk_size, &actual_chunk, usb_timeout); if (ret != LIBUSB_SUCCESS) { dprintf("libusb read failure: %d: %s\n", ret, libusb_error_name(ret)); return EIO;