From patchwork Wed Mar 11 22:46:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Muellner X-Patchwork-Id: 1253315 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=theobroma-systems.com Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48d7WQ1b2Sz9sPJ for ; Thu, 12 Mar 2020 10:31:14 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 41F3581737; Thu, 12 Mar 2020 00:30:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=theobroma-systems.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 22CCF81536; Wed, 11 Mar 2020 23:47:03 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, KHOP_HELO_FCRDNS, SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from mail.theobroma-systems.com (vegas.theobroma-systems.com [144.76.126.164]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 48ABD81496 for ; Wed, 11 Mar 2020 23:46:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=theobroma-systems.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=christoph.muellner@theobroma-systems.com Received: from ip092042140082.rev.nessus.at ([92.42.140.82]:39500 helo=purcell.lan) by mail.theobroma-systems.com with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1jCA7s-00009u-R9; Wed, 11 Mar 2020 23:46:56 +0100 From: Christoph Muellner To: U-Boot Mailing List Cc: Heiko Stuebner , Philipp Tomsich , Christoph Muellner , Michal Simek , Simon Glass , T Karthik Reddy , Tom Rini Subject: [PATCH] cmd: test: Add operators to deal with hexadecimal numbers. Date: Wed, 11 Mar 2020 23:46:52 +0100 Message-Id: <20200311224652.16900-1-christoph.muellner@theobroma-systems.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 12 Mar 2020 00:30:36 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean The DLUG states the following: Almost all U-Boot commands expect numbers to be entered in hexadecimal input format. Besides this fact, also most commands output hex values. Given this facts, we need to be able to use the information provided by to/from commands in scripts. The test command does not support operating on hexadecimal input formats. This leads to very surprising tests like this (simple_strtol("ff", 10) == 0): => if test "ff" -eq 0; then echo "equal"; fi equal => This patch introduces comparison operators for the test command, that allow parameters in hexadecimal format. So the test above can be implemented as follows: => if test "ff" -heq 0; then echo "equal"; fi => [1] https://www.denx.de/wiki/view/DULG/UBootCommandLineInterface Signed-off-by: Christoph Muellner Reviewed-by: Simon Glass --- cmd/test.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cmd/test.c b/cmd/test.c index 258bfd8806..dbaf23596b 100644 --- a/cmd/test.c +++ b/cmd/test.c @@ -25,6 +25,12 @@ #define OP_INT_GT 14 #define OP_INT_GE 15 #define OP_FILE_EXISTS 16 +#define OP_HEX_EQ 17 +#define OP_HEX_NEQ 18 +#define OP_HEX_LT 19 +#define OP_HEX_LE 20 +#define OP_HEX_GT 21 +#define OP_HEX_GE 22 const struct { int arg; @@ -48,6 +54,12 @@ const struct { {0, "-z", OP_STR_EMPTY, 2}, {0, "-n", OP_STR_NEMPTY, 2}, {0, "-e", OP_FILE_EXISTS, 4}, + {1, "-heq", OP_HEX_EQ, 3}, + {1, "-hne", OP_HEX_NEQ, 3}, + {1, "-hlt", OP_HEX_LT, 3}, + {1, "-hle", OP_HEX_LE, 3}, + {1, "-hgt", OP_HEX_GT, 3}, + {1, "-hge", OP_HEX_GE, 3}, }; static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) @@ -139,6 +151,30 @@ static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) case OP_FILE_EXISTS: expr = file_exists(ap[1], ap[2], ap[3], FS_TYPE_ANY); break; + case OP_HEX_EQ: + expr = simple_strtol(ap[0], NULL, 16) == + simple_strtol(ap[2], NULL, 16); + break; + case OP_HEX_NEQ: + expr = simple_strtol(ap[0], NULL, 16) != + simple_strtol(ap[2], NULL, 16); + break; + case OP_HEX_LT: + expr = simple_strtol(ap[0], NULL, 16) < + simple_strtol(ap[2], NULL, 16); + break; + case OP_HEX_LE: + expr = simple_strtol(ap[0], NULL, 16) <= + simple_strtol(ap[2], NULL, 16); + break; + case OP_HEX_GT: + expr = simple_strtol(ap[0], NULL, 16) > + simple_strtol(ap[2], NULL, 16); + break; + case OP_HEX_GE: + expr = simple_strtol(ap[0], NULL, 16) >= + simple_strtol(ap[2], NULL, 16); + break; } switch (op) {