From patchwork Tue May 7 19:42:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 242438 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 86ECF2C016D for ; Wed, 8 May 2013 05:43:25 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AEA834A1F8; Tue, 7 May 2013 21:43:23 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9C40vl-D9U8v; Tue, 7 May 2013 21:43:22 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 701F84A1B6; Tue, 7 May 2013 21:43:00 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A3E034A1B2 for ; Tue, 7 May 2013 21:42:53 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VPeVw4V9Ug4V for ; Tue, 7 May 2013 21:42:48 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-yh0-f73.google.com (mail-yh0-f73.google.com [209.85.213.73]) by theia.denx.de (Postfix) with ESMTPS id 0E1BB4A1CC for ; Tue, 7 May 2013 21:42:41 +0200 (CEST) Received: by mail-yh0-f73.google.com with SMTP id a41so100047yho.0 for ; Tue, 07 May 2013 12:42:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=QgtEtIEU3fPMV99pEOYJDhqL1Du1EINGyUugmSXXTRw=; b=fUtv4/fQk4fnxXsW6PwE7rgbPM3PcMcGupaxMTe0mt/IYrHBWMe5P2a1wqEskVHe0q jSp3OWNAVk4Ykjm+SwqwjZuoY0qgEk9A3gty7Sm4dn5w/LYaXoV5zKzAJMisT8l4E85Q SC5mlqQwJ2u5oFMaZKk3mQ+9WfDKWYc7AgnKH40vZXpSN+7aFA5NNtd3CaO6A8BXb0ri a0eX/xxgYnWZTgX5vlhvkdpY1PyMSIXJj/8LNZeOQvNYtA55gh5/kV8rBgHqZSX1yFhy X4xt+0Jo6ENgA53EJc1itn03UpRfkZFLSJ0nSTwp/J22BvaXL5e9H69KuCPSr2brU6BQ KRFg== X-Received: by 10.236.181.234 with SMTP id l70mr1983558yhm.53.1367955760215; Tue, 07 May 2013 12:42:40 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id o42si3104464yhe.5.2013.05.07.12.42.40 for (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Tue, 07 May 2013 12:42:40 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.83.1]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 127235A4111; Tue, 7 May 2013 12:42:40 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id B4190160A39; Tue, 7 May 2013 12:42:39 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 7 May 2013 12:42:00 -0700 Message-Id: <1367955730-31902-5-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1367955730-31902-1-git-send-email-sjg@chromium.org> References: <1367955730-31902-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQmMITdGryWhf7LUacaXEUs4x7laMHDSfFSQv6+AtVJIWx51YaiNpNyx05v5na0OYb3FO2449AHAqm4jTkyOLE+q3m172quTLFoSoTN3elP/Bw5COX6YDMkN29tregsSYq3UW3DhEvAMwkeTlyC07Z/vc4Uu/X9YlOv7T+GaazeLSItc6/r97lfg91NhQ56bIclxdQ8v Cc: Tom Rini , u-boot-review@google.com Subject: [U-Boot] [RFC PATCH v2 04/14] Add cmd_process_error() to report and process errors X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de U-Boot now uses errors defined in include/errno.h which are negative integers. Command which fail need to report the error and return 1 to indicate failure. Add this functionality in cmd_process_error(). For now this merely reports the error number. It would be possible also to produce a helpful error message by storing the error strings in U-Boot. Signed-off-by: Simon Glass --- Changes in v2: None common/command.c | 10 ++++++++++ include/command.h | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/common/command.c b/common/command.c index 305a236..70faa60 100644 --- a/common/command.c +++ b/common/command.c @@ -554,3 +554,13 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[], rc = cmd_usage(cmdtp); return rc; } + +int cmd_process_error(cmd_tbl_t *cmdtp, int err) +{ + if (err) { + printf("Command '%s' failed: Error %d\n", cmdtp->name, err); + return 1; + } + + return 0; +} diff --git a/include/command.h b/include/command.h index 65692fd..e82c555 100644 --- a/include/command.h +++ b/include/command.h @@ -80,6 +80,15 @@ extern int var_complete(int argc, char * const argv[], char last_char, int maxv, extern int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp); #endif +/** + * cmd_process_error() - report and process a possible error + * + * @cmdtp: Command which caused the error + * @err: Error code (0 if none, -ve for error, like -EIO) + * @return 0 if there is not error, 1 (CMD_RET_FAILURE) if an error is found + */ +int cmd_process_error(cmd_tbl_t *cmdtp, int err); + /* * Monitor Command *