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=-4.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 2ABAFC11F66 for ; Tue, 29 Jun 2021 13:57:31 +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 9F70161D8B for ; Tue, 29 Jun 2021 13:57:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F70161D8B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.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 765568319A; Tue, 29 Jun 2021 15:57:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TbAG5IhC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DF82F8319A; Tue, 29 Jun 2021 15:57:26 +0200 (CEST) Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4723C8319F for ; Tue, 29 Jun 2021 15:57:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qk1-x72b.google.com with SMTP id 65so13647854qko.5 for ; Tue, 29 Jun 2021 06:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=OzHb0VIjBfk2yrS9hIquu5lFD5bHfwyu5RgxktZwfTY=; b=TbAG5IhCAfgwtlkYJJJjbjmcoU4MicKsW2oaN7//LZEb9Vd4T65zKW0yhLkoaDFEQs Sa9WVqiFrQizZuG+NHv012VArYw86qDxo1FaJFLCJeFnT2jS6h7D7kE+5IP76l8/dXqN j3vL2FHj+AHM4OXOQajM5K5JRCdd8K5tg6Io8/hJf1Th+xNpVwBsRZK4AQG+JuO6eLkS KNUL8xSXdEJ9s0wW59tWaP5nFP+DUzXZz+yPVHdW3XgZY+XOXPmHFdygneq3ze6fTJMJ zansbD+npIQGgODMolUpRuFOW0OFcO1N1/4C1Od9Vj98aqy3k3cfKyZ4ENfN5ADBnJ8x 4LHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=OzHb0VIjBfk2yrS9hIquu5lFD5bHfwyu5RgxktZwfTY=; b=WNVFUc8R3dJonQnPg9ECQ0V0BqPgKn+BlWi2exmdVS21Zo6J2WqZd7eQFCRpDrys7r YgggO9j5eo0lJIHSsOklmsa6TTjGUU/Ciodl6kVG+InsMcHCk9KqJyiuAFjDXdRbNu6C KjYWtlDQ2ECvT6RrOyvhabEms06mTU9Nlaaaucq/pyLAK36QvsTtAtU/JGbKqPsBFYc5 GmoM5/s+fOQzOd0B353GNIgTHz3DFTg6zSVJFv0J3eFZP0bAw+Twwp2p7q8EPiBfDa6I 2ZhbcP/+9UyUWExDOS8gEj6R+hHOf7IgPtmU2E1pP9mvz8X+cNAZsgrrl8Fyn1jp22ZH IJqA== X-Gm-Message-State: AOAM530IKr1rUwf/eKBVaFOIzF/lEthpyxG+nvJCN4GPKV7qvl5pjCMa g/qGCHh4QB7VTDNQzD6laG8= X-Google-Smtp-Source: ABdhPJyRkPVxaUIqbt97nc5otlwUUBeR1hcrMJGy7ty4TrrLKoGP2XfgThjdyngxWDdR5HJZXihmNw== X-Received: by 2002:a05:620a:5ef:: with SMTP id z15mr29981832qkg.147.1624975041144; Tue, 29 Jun 2021 06:57:21 -0700 (PDT) Received: from [192.168.1.201] (pool-74-96-87-9.washdc.fios.verizon.net. [74.96.87.9]) by smtp.googlemail.com with ESMTPSA id b8sm9498471qtr.77.2021.06.29.06.57.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Jun 2021 06:57:20 -0700 (PDT) Subject: Re: [PATCH 0/3] cmd: setexpr: add fmt format string operation To: Wolfgang Denk , Roland Gaudig Cc: u-boot@lists.denx.de, Simon Glass , Roland Gaudig , Alex Nemirovsky , Bin Meng , Heinrich Schuchardt , =?UTF-8?Q?Marek_Beh=c3=ban?= , Patrick Delaunay , Rayagonda Kokatanur , Robert Marko , Stefan Bosch , Weijie Gao References: <20210628151750.572837-1-roland.gaudig-oss@weidmueller.com> <83741.1624955845@gemini.denx.de> From: Sean Anderson Message-ID: <19b6eeea-2aad-972b-aeeb-8959aab17d7a@gmail.com> Date: Tue, 29 Jun 2021 09:57:19 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <83741.1624955845@gemini.denx.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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 On 6/29/21 4:37 AM, Wolfgang Denk wrote: > Dear Roland, > > In message <20210628151750.572837-1-roland.gaudig-oss@weidmueller.com> you wrote: >> >> >> U-Boot uses almost everywhere hexadecimal numbers. But some bootargs >> passed to Linux are expecting decimal numbers. As long as the values >> are in the range 0 to 9 it is sufficient to just strip 0x from the >> number. But for greater values a method for converting numbers to >> decimal is needed. >> >> This patch adds C like format string capabilities to the setexpr >> command. Here are some examples: > > Thanks! > >> In contrast to the original C format strings the number of parameters >> is limited to one. As the get_arg() function returns unsigned long >> type, the format string commands are limited to those which are >> operating on unsigned long type. > > These are two pretty unfortunate restrictions. I guess it should > not be too hard to avoid both of these. Can you please give it a > try? > > I think it is reasonable to assume (and specify) that, when the > "fmt" option is used, _all_ following arguments will be passed > (unchanged) to the sprintf() function. > > This was actually one of my intentions when making this suggestion - > to be able to construct any kind of data from pieces; say, for > example: > > => setexpr foo fmt "%0x08x-%s-%d-%s" $a $b $c $d > > Best regards, > > Wolfgang Denk > The issue with this is twofold. First, there is no portable way to construct a va_list from C code. So the likely way to do this would be to set an arbitrary limit, and then just pass the arguments in. E.g. something like snprintf(buf, sizeof(buf), argv[3], argc >= 4 ? argv[4] : NULL, /* etc */); but of course there is no way to check that the format string matches the correct number of arguments. This is a pretty big footgun. The other problem is that things like `%d` expect a number and not a string. So you would have to reimplement snprintf anyway so that it expects all of its arguments to be strings, and calls strtoul as appropriate. And considering that the *printf functions take 5k already, this reimplementation may add a significant amount of code. For this reason, I'd much prefer to just have `hex` and `dec` functions which do the appropriate conversions. --Sean