From patchwork Sat Jan 26 02:31:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martyn Welch X-Patchwork-Id: 1031372 X-Patchwork-Delegate: trini@ti.com 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; dmarc=fail (p=none dis=none) header.from=collabora.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43mg1261wgz9s7T for ; Sat, 26 Jan 2019 13:33:10 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 7B8FCC21E1A; Sat, 26 Jan 2019 02:32:46 +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=SPF_HELO_PASS 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 D5D1BC21E02; Sat, 26 Jan 2019 02:32:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 02127C21CB6; Sat, 26 Jan 2019 02:32:04 +0000 (UTC) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lists.denx.de (Postfix) with ESMTPS id A8A51C21D65 for ; Sat, 26 Jan 2019 02:32:04 +0000 (UTC) Received: from hades.home (unknown [IPv6:2a00:23c5:58d:db00:68bb:47d:d5ca:9abd]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: martyn) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 5AA9A27D67D; Sat, 26 Jan 2019 02:32:04 +0000 (GMT) From: Martyn Welch To: Tom Rini Date: Sat, 26 Jan 2019 02:31:53 +0000 Message-Id: <20190126023154.19749-4-martyn.welch@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190126023154.19749-1-martyn.welch@collabora.com> References: <20190126023154.19749-1-martyn.welch@collabora.com> MIME-Version: 1.0 Cc: Martyn Welch , u-boot@lists.denx.de Subject: [U-Boot] [PATCH 4/5] tools: dumpimage: Add help option and make error paths consistent 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The utility dumpimage has error paths that display the usage and others that exit without displaying usage. Add an explicit help option to dumpimage to display the usage and remove it's use in error paths to make the error messages more obvious and errors paths more consistent. Signed-off-by: Martyn Welch --- tools/dumpimage.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/dumpimage.c b/tools/dumpimage.c index e17e979b04..5c9ad36322 100644 --- a/tools/dumpimage.c +++ b/tools/dumpimage.c @@ -65,7 +65,7 @@ int main(int argc, char **argv) params.cmdname = *argv; - while ((opt = getopt(argc, argv, "lo:T:p:V")) != -1) { + while ((opt = getopt(argc, argv, "hlo:T:p:V")) != -1) { switch (opt) { case 'l': params.lflag = 1; @@ -79,7 +79,7 @@ int main(int argc, char **argv) if (params.type < 0) { fprintf(stderr, "%s: Invalid type\n", params.cmdname); - usage(); + exit(EXIT_FAILURE); } break; case 'p': @@ -94,15 +94,20 @@ int main(int argc, char **argv) case 'V': printf("dumpimage version %s\n", PLAIN_VERSION); exit(EXIT_SUCCESS); + case 'h': + usage(); default: usage(); break; } } + if (argc < 2) + usage(); + if (optind >= argc) { fprintf(stderr, "%s: image file missing\n", params.cmdname); - usage(); + exit(EXIT_FAILURE); } params.imagefile = argv[optind]; @@ -123,7 +128,7 @@ int main(int argc, char **argv) if (tparams->check_params(¶ms)) { fprintf(stderr, "%s: Parameter check failed\n", params.cmdname); - usage(); + exit(EXIT_FAILURE); } } @@ -195,9 +200,12 @@ static void usage(void) " -T ==> set image type to 'type'\n" " -p ==> 'position' (starting at 0) of the component to extract from image\n", params.cmdname); + fprintf(stderr, + " %s -h ==> print usage information and exit\n", + params.cmdname); fprintf(stderr, " %s -V ==> print version information and exit\n", params.cmdname); - exit(EXIT_FAILURE); + exit(EXIT_SUCCESS); }