From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FAKE_REPLY_A1,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E03D5C48BC2 for ; Wed, 23 Jun 2021 08:20:14 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C477560D07 for ; Wed, 23 Jun 2021 08:20:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C477560D07 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=weidmueller.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AD9FC8020E; Wed, 23 Jun 2021 10:20:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=weidmueller.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=weidmueller.onmicrosoft.com header.i=@weidmueller.onmicrosoft.com header.b="ESYJgvtY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 658F8829C3; Wed, 23 Jun 2021 10:20:08 +0200 (CEST) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on20626.outbound.protection.outlook.com [IPv6:2a01:111:f400:7d00::626]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 08A8F801E8 for ; Wed, 23 Jun 2021 10:20:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=weidmueller.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=roland.gaudig-oss@weidmueller.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bAFVlM00yeky+EXMOPrJ4txzz8aIrV9GYa3A5S3P3FwO06nNR6H4UaoDHk7NaPg/NpiZnkczjzqgXWQD5MPm6BDJkjfzT3kVr28MxT3GIX3fd/fuMKouifVCWo7wzodw5O7X9pW7m0iJbFumGpai1H25rS50cVh/oAKQPCmXNgXz/imkHxqPsLDDgRpuAW0YNUx+FvPBE9Hr9libyn1OG6m3E+pCYwzzjgJXW3py3uawf8m5kywtwuTF6RAAwwGnKldUCZSgDdf/GEdhjVD6XzBk/TcIxZ/OEjQId4Fghy4BdNLpHAMgQpe6LNveFFl4/yoWv16yJ8h7r6kWlV6+PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DOwPeWd4rG0buJ3zaMaW+vKR/dvGlVfNN9hglfE09oc=; b=ly6+NUCvrBhEJheXqsekZwewX/Ukohj75RBr3zLNNISpLr/3OkSUq+2T63hwVjduu6BFp4HCDcIcVUNvu4f6fz9/2WgAUbk3GUFZQMHTOxsXglgSTm4P4Xg5KjoYFH0jNJ2LOuJ/zC1vg+k3k9gw4U3JixEYNGHNvD4kvlMZ1LgQUYCDauhYRt2dkQK6D3sc7gy+l2Wbw6ekW0XjYrZTZgbhRTLClWc4PoZbpDZe7AMfSOv/O9wwAK+d7e2iaXiSpxmtUGaDBkPC7WdpCEtltUvFMGmQ5lN4O6jVWQ+okrWfx+4fBnLLdUp+FvHk67K7i7kxz5ByuwDanKrcWQDFuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=weidmueller.com; dmarc=pass action=none header.from=weidmueller.com; dkim=pass header.d=weidmueller.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=weidmueller.onmicrosoft.com; s=selector1-weidmueller-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DOwPeWd4rG0buJ3zaMaW+vKR/dvGlVfNN9hglfE09oc=; b=ESYJgvtY2rqw6w0jZPhuuej+ZZOzdjK63GgT7rQfusbRsAB0zXbUqyfOKP4GSv0ZMPYUla76HfTxklluPUzXq8WRQvt9nehOFiy4XOLveF8UFTBe1jm5mt1lbGX7ij+gzAxBhTUyx5xAs/mvQthhO1eWmYnN8KROFoo+xUNcuCQ= Authentication-Results: nic.cz; dkim=none (message not signed) header.d=none;nic.cz; dmarc=none action=none header.from=weidmueller.com; Received: from AS8PR08MB6728.eurprd08.prod.outlook.com (2603:10a6:20b:396::19) by AM6PR08MB4328.eurprd08.prod.outlook.com (2603:10a6:20b:74::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.21; Wed, 23 Jun 2021 08:20:03 +0000 Received: from AS8PR08MB6728.eurprd08.prod.outlook.com ([fe80::8c4:6c9d:275f:5625]) by AS8PR08MB6728.eurprd08.prod.outlook.com ([fe80::8c4:6c9d:275f:5625%8]) with mapi id 15.20.4242.023; Wed, 23 Jun 2021 08:20:03 +0000 Subject: Re: [PATCH v1 1/1] cmd: setexpr: add dec operation for converting variable to decimal To: u-boot@lists.denx.de Cc: Simon Glass , =?UTF-8?Q?Marek_Beh=c3=ban?= From: "Roland Gaudig (OSS)" Message-ID: <6d081f17-3ae3-6e24-fa09-dc6c703d5f8e@weidmueller.com> Date: Wed, 23 Jun 2021 08:20:01 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Originating-IP: [84.138.75.231] X-ClientProxiedBy: FR0P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::23) To AS8PR08MB6728.eurprd08.prod.outlook.com (2603:10a6:20b:396::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from DE12086.weidmueller.com (84.138.75.231) by FR0P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.7 via Frontend Transport; Wed, 23 Jun 2021 08:20:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 22af5ee6-0c05-41c9-e760-08d9361fb3ab X-MS-TrafficTypeDiagnostic: AM6PR08MB4328: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aYhlsm5IfbrlKVnnA+wgeQBzhYl9xoGqbOYxurtJD72Srz24ZOzL4Py8t1QlA2rVinKUjDzZXduMLb5INJbbUkhk07L36dSLKjNdkOeLvBpCx/SHizNNztz7or1QH9omtAquHbZqmnNWBn6GuZ0c9cRQwCq5P/l+mI0X6vhLxwWKGCgxXV+c3xPGZhSPlmUmfxsBsDmmFEXS2YbAwGtQycd6IOO4F28YbaF663FDTZEueE8Q03GLpaZ7w3pRFG9MWLvqxzm6Y3J1pkYHWZwgYnW8TS61sy74JFcG7OxPCKwQ7FNKeFsLLX0SzzTP6Ty3RhMA5cUUqoLDAYGcCv4mSkUBg0Jgoh3GNSIy+fjotgmMMR29l6ic7c9XUNNm8xCAd4S3jXwSKnJVFDlHpebbg8HOC8S3V9AF41IbSJKLNqlV3UI/HIIYpB9qEP/o1rmf2FsnkGsTlQctnMLY33LBrJ5pdHy/eSiaRkntvB51tY8HRQnLWimTiyeohBLHBprS20/PbbKrQWMBKDmm9y03amwkQN8hypMiGrA6kmd799PkJ75BK8fl3RyjgD8uW1JwfJfzjPYj5p3WOtnQ5U8nKpP6jmCXWZFBb5ftWUWAer9XdkJZM0+tJGOwbaFhcTBDtj6pZOJOp4YIWKZlln7dDSYPue+NstGzSNitFeEUQBiwpWETnoPfCPLMf1Zz3xJ6 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB6728.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(396003)(346002)(366004)(39860400002)(86362001)(5660300002)(478600001)(31696002)(7696005)(186003)(54906003)(26005)(16526019)(6916009)(66556008)(2616005)(66476007)(316002)(956004)(2906002)(36756003)(66946007)(4326008)(8936002)(38100700002)(31686004)(6486002)(8676002)(83380400001)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Q1hFdElrVWpCY3FVWW1Pb3VCZXhMbTVuaGZ1ZFRDT0JMM25mV1JKRnIxWWJv?= =?utf-8?B?Z1hGQUQxeTZjT1FBQWtMTnAvWnZSVGtSNWJUd1c1ZzNWWHptaFIvejNjTFEy?= =?utf-8?B?SE9uejB6T2VYYVFIZVB6aStZYXBNR2crRFdOcGNQQUVZVlA0K3hDRGxSc3lI?= =?utf-8?B?dEVTR1RrRm54clZUYzZEcno0d0FURWJtb3BWSHpXU1FVRUxEN1RyMVRtZWtY?= =?utf-8?B?VnJLcFpUbXZ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3Ns?= =?utf-8?B?RlhiN0NwWkE0VzdYT1RqVy9LVWlNeGtjUzFUSWdiLzJLekJOUzhwVktNZko1?= =?utf-8?B?bEYrM1g4K3ZQOHJ3VFFjTXN0UkRWa3ZFOU5aLzZqY2dURWpPdm1xeEVRVE40?= =?utf-8?B?M2hxOVYyWGZCNWtTM01icmQyNDA1RExwK29VV0U5eGczRUppUU1hNm52YTF4?= =?utf-8?B?N0ptVmlRdEVSVHoxZmcyOEFuQmFja3RpbGQ0aXpuWHhhZWhWbVdxeEtKckhR?= =?utf-8?B?UHh6c3RwZHBBK1hVWElqTlBKRklnOCttNFNmZUY5Tk8ybVIxc0FHT3dFOEJM?= =?utf-8?B?dTk0TmJMTTlBQTBFaG5mZm01OVdTN0F3Qzh1VWJlcU91YzBkYTBOSTBOT3Jh?= =?utf-8?B?RjlLWWlISW11RnZIK2VERVo4VC9RNnVYSE1ldmR5Z1E4dGFDNTJ0REVqWFFl?= =?utf-8?B?cEZBcWNzRERvNGhmcUdSbmRuSFUzV3lxbndZcGhhZ3pqWWJwei92TWIyNXE5?= =?utf-8?B?YUtWQXVNNzU0eldoQTZZb2NsZHdBMjJzbWE3ODFyRFZqNG1URmxYbkJaTUg2?= =?utf-8?B?R2J2MTZaeEVMSXhPbDIrVnV1V09pM3g5N2hkNjlnOGpRZFE1WUZ2K1JsUWph?= =?utf-8?Q?wQ9GhPCpOun312pE6mA9Xdgp1dqdVFMYqeCZIG7?= X-OriginatorOrg: weidmueller.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22af5ee6-0c05-41c9-e760-08d9361fb3ab X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB6728.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jun 2021 08:20:03.7706 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e4289438-1c5f-4c95-a51a-ee553b8b18ec X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jKqejzruSGdNFB4oFfxtHgXD+zGglmu7ksTulwUeTTYs5+KSNUoDFNy/ti5nZefE1TX6mrCKCh4dRzxlZukheQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4328 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.103.2 at phobos.denx.de X-Virus-Status: Clean Hi Simon, On Tue, 22. Jun 2021 at 21:25, Simon Glass wrote: > > Hi Roland, > > On Tue, 22 Jun 2021 at 07:51, wrote: >> >> From: Roland Gaudig >> >> This patch extends the setexpr command with a dec operator to >> convert an input value to decimal. >> >> Signed-off-by: Roland Gaudig >> --- >> >> cmd/setexpr.c | 16 ++++++++++++++-- >> 1 file changed, 14 insertions(+), 2 deletions(-) >> >> diff --git a/cmd/setexpr.c b/cmd/setexpr.c >> index e828be3970..2d4bee2182 100644 >> --- a/cmd/setexpr.c >> +++ b/cmd/setexpr.c >> @@ -370,15 +370,16 @@ static int do_setexpr(struct cmd_tbl *cmdtp, int > flag, int argc, >> int w; >> >> /* >> - * We take 3, 5, or 6 arguments: >> + * We take 3, 4, 5, or 6 arguments: >> * 3 : setexpr name value >> + * 4 : setexpr name dec value >> * 5 : setexpr name val1 op val2 >> * setexpr name [g]sub r s >> * 6 : setexpr name [g]sub r s t >> */ >> >> /* > 6 already tested by max command args */ >> - if ((argc < 3) || (argc == 4)) >> + if (argc < 3) >> return CMD_RET_USAGE; >> >> w = cmd_get_data_size(argv[0], 4); >> @@ -398,6 +399,13 @@ static int do_setexpr(struct cmd_tbl *cmdtp, int flag, > int argc, >> return ret; >> } >> >> + /* hexadecimal to decimal conversion: "setexpr name dec value" */ >> + if (argc == 4 && (strcmp(argv[2], "dec") == 0)) { >> + w = cmd_get_data_size(argv[3], 4); >> + a = get_arg(argv[3], w); >> + return env_set_ulong(argv[1], a); >> + } >> + >> /* 5 or 6 args (6 args only with [g]sub) */ >> #ifdef CONFIG_REGEX >> /* >> @@ -515,4 +523,8 @@ U_BOOT_CMD( >> "setexpr name sub r s [t]\n" >> " - Just like gsub(), but replace only the first matching > substring" >> #endif >> + "\n" >> + "setexpr name dec [*]value\n" >> + " - set environment variable 'name' to the result of the > decimal\n" >> + " conversion of [*]value.\n" >> ); >> -- >> 2.25.1 >> > > This seems reasonable to me. > > I have been thinking of introducing a prefix for decimal, perhaps > 0m123 ? ('m' for deciMal). This 0x prefix would then also be parsed by get_arg(), as it does currently with the 0x prefix? For my application as input to the Linux bootargs it is important, that the resulting text stored in the variable after running setexpr has no prefix at all. > Can you please add a test for this in test//cmd/setexpr.c and also, > how about adding something in doc/usage? Yes, I will add a test and a description to doc/usage. Regards, Roland