From patchwork Mon Feb 17 22:06:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 321158 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 4E0422C00CD for ; Tue, 18 Feb 2014 09:08:13 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 71E614B75D; Mon, 17 Feb 2014 23:08:11 +0100 (CET) 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 h7EvKA19WQTo; Mon, 17 Feb 2014 23:08:11 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5594B4B709; Mon, 17 Feb 2014 23:07:43 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8C2A04B709 for ; Mon, 17 Feb 2014 23:07:38 +0100 (CET) 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 uY56GiTsLHIq for ; Mon, 17 Feb 2014 23:07:34 +0100 (CET) X-Greylist: delayed 110563 seconds by postgrey-1.27 at theia; Mon, 17 Feb 2014 23:07:30 CET 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-ie0-f201.google.com (mail-ie0-f201.google.com [209.85.223.201]) by theia.denx.de (Postfix) with ESMTPS id 4D0494B6FF for ; Mon, 17 Feb 2014 23:07:30 +0100 (CET) Received: by mail-ie0-f201.google.com with SMTP id at1so465103iec.2 for ; Mon, 17 Feb 2014 14:07:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JQMNr2VhMRzk/DHVcO8njdMSzJjVJ/sUhAo40GOUGSc=; b=Pfy4EzwEqwu95Sx/7Hi13C7mTFRTYg1UoIT9TkMAKhVehHdUh0/ODJGXw6mKsDfPJ7 EOkEpaV0euOqQhOAZX8yUz/BSSzZqCSai3/zkJbrsy5Vfya/9qF9appMBE3Zy+PzRw7z AcWQUq56kWiTzaoSciOkV24ncgd7Pzx/Vq4uc+C17Cxq6joI4fR39P8KoOfifmuNSgaY UP7tNXJd5R6Puu5HORfbscSfyrwqdVOzzOajP+f3S70OgpKSuNeqYzXgmTeWuzLXW6qg fUxt3yn5TIQn0eJ0Mz1c9AkCZ9VOavJvZIKBaSaLcPj6kWu+TNDlYoHk2WdPPXMhqmkw fvXg== X-Gm-Message-State: ALoCoQmwRrAUNpW8sbQiHJnAad3QwSxWCPoXW8xWbV4Zp7mwwg5EzBz0VCwZMzNUy5SgE4dckDce94Fd39KT0zFb8oHHrScAF07nQm760wKAS2iOULUsiE7YY+J2+bmJYu593VVgdh5ZVCiOwt9y5BsUuz5nysspTzkHnyFa7C67+je4Gog/Ar+9ojXrdRwO+NjT8J5p7dQC X-Received: by 10.50.78.231 with SMTP id e7mr1095227igx.5.1392674849490; Mon, 17 Feb 2014 14:07:29 -0800 (PST) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id d9si2456758yhl.2.2014.02.17.14.07.29 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Feb 2014 14:07:29 -0800 (PST) Received: from kaki.bld.corp.google.com (kaki.bld.corp.google.com [172.29.216.32]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 5446A31C19E; Mon, 17 Feb 2014 14:07:29 -0800 (PST) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 07F3B221617; Mon, 17 Feb 2014 15:07:28 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Mon, 17 Feb 2014 15:06:36 -0700 Message-Id: <1392674808-6961-3-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.9.0.rc1.175.g0b1dcb5 In-Reply-To: <1392674808-6961-1-git-send-email-sjg@chromium.org> References: <1392674808-6961-1-git-send-email-sjg@chromium.org> Cc: Tom Rini , u-boot-review@google.com Subject: [U-Boot] [PATCH v8 02/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. Commands 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 v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None 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 597ab4c..26c37f2 100644 --- a/common/command.c +++ b/common/command.c @@ -538,3 +538,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 f782779..d3f700f 100644 --- a/include/command.h +++ b/include/command.h @@ -64,6 +64,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 *