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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5D0EBC433EF for ; Tue, 15 Feb 2022 11:53:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A1BDB83A3C; Tue, 15 Feb 2022 12:53:27 +0100 (CET) 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="hgLZ/BMA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 807BE838FD; Tue, 15 Feb 2022 12:53:15 +0100 (CET) Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) (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 B1C9083A2B for ; Tue, 15 Feb 2022 12:53:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alpernebiyasak@gmail.com Received: by mail-ed1-x52e.google.com with SMTP id u18so31571254edt.6 for ; Tue, 15 Feb 2022 03:53:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:from:subject:to:cc :references:content-language:in-reply-to:content-transfer-encoding; bh=AINTHzXwcKpXZvRNhPPEXLN0l4RWHPfgDKqcuCrnlEo=; b=hgLZ/BMA9z1esgive83Vh5vfDO/2haUZY1ArjUs8vzqEbzvaH1+T6Y4YDf3zySjtui v9MVWm8pqiTSN+Y2XfjHX6YEr7ySubtExv0KYEeBURuoi0Tqb36U3PdhHwYAc1QKFAmS DFaYTLjaK4Qs2J100vdsS8IyAdafgrvlgg3KRYbjeNpAaIVvSqgaBKS+uAAk1w2ywgyy eiUyhJ+JyotakwtAghyRxtylh8YQfleb0t/invo+WwpbJsNgLetHqaVr4f8d1GL8vM6w ZX1CcO8xQtOQTqcf87h6cP+xSK4mWVGKJScMzainuiP5o6PEpbX019I6C+7pivAQ5mf7 Kfiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:cc:references:content-language:in-reply-to :content-transfer-encoding; bh=AINTHzXwcKpXZvRNhPPEXLN0l4RWHPfgDKqcuCrnlEo=; b=CgFjOsDnE+zfmI18FxXw0tbriy6iSMyqzOmGaQdOYKICXwK9GLjhrvChG2HmisHPV0 CBmr0GuP6n/L1uBXFv3pd3IrfSLIExywkZFKoieLJkytxcJtVl+RrebfI0Wl+c56p75b j43ZXmcYKaXGpVC00JJQ8LJZd7R45Tm4enbU4NQ2N2Xe0ox6O/z8/anwhPT8qHZ8cNhe z9+I8fMDwFTBPEVS8U0wv/kq/uyaGGhlFonEePldTrz1qeyh6WxhyiXY64WbKRmypXJ0 X6yb+f1JVu2LvS/llE6zf5i1zlSF9BwO2CWY4gGULnE53HJ38+A/zRPn3NT5fNXrff3Y V+NA== X-Gm-Message-State: AOAM531uQfs2cyf71UVf7qRA2Vd4k2r1AUQNYJfAvLs/vQnfJX6Kqo78 BVi9X2AIUH9MCCmOtC0Uc88= X-Google-Smtp-Source: ABdhPJwhTl5BRE1Uz7iyJK8JL7f5CKYf+bjJEo2JqXygl+bnbFYLIwgvN1lmVE0x8zBLeANuyY13Tw== X-Received: by 2002:a05:6402:3451:: with SMTP id l17mr3547522edc.187.1644925991379; Tue, 15 Feb 2022 03:53:11 -0800 (PST) Received: from [192.168.0.74] ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id z11sm1725576edd.75.2022.02.15.03.53.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Feb 2022 03:53:10 -0800 (PST) Message-ID: <4f45167f-ec28-7535-940c-c7bb8f96db02@gmail.com> Date: Tue, 15 Feb 2022 14:43:39 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 From: Alper Nebi Yasak Subject: Re: [PATCH 09/24] dtoc: Support reading a list of arguments To: Simon Glass , U-Boot Mailing List Cc: huang lin , Jeffy Chen , Kever Yang , Tom Rini , Philippe Reynes , Ivan Mikhaylov , Walter Lozano References: <20220208185008.35843-1-sjg@chromium.org> <20220208185008.35843-8-sjg@chromium.org> Content-Language: en-US In-Reply-To: <20220208185008.35843-8-sjg@chromium.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean On 08/02/2022 21:49, Simon Glass wrote: > It is helpful to support a string or stringlist containing a list of > space-separated arguments, for example: > > args = "-n fred", "-a", "123"; > > This resolves to the list: > > -n fred -a 123 Would be clearer as ['-n', 'fred', '-a', '123'] > > which can be passed to a program as arguments. > > Add a helper to do the required processing. > > Signed-off-by: Simon Glass > --- > > tools/dtoc/fdt_util.py | 12 ++++++++++++ > tools/dtoc/test/dtoc_test_simple.dts | 1 + > tools/dtoc/test_fdt.py | 15 +++++++++++++++ > 3 files changed, 28 insertions(+) > > diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py > index 19eb13aef3..59e065884f 100644 > --- a/tools/dtoc/fdt_util.py > +++ b/tools/dtoc/fdt_util.py > @@ -184,6 +184,18 @@ def GetStringList(node, propname, default=None): > return [strval] > return value > > +def GetArgs(node, propname): > + prop = node.props.get(propname) > + if not prop: > + raise ValueError(f"Node '{node.path}': Expected property '{propname}'") > + if prop.bytes: > + value = GetStringList(node, propname) > + else: > + value = [] Isn't GetStringList(node, propname, default=[]) enough here, why check prop.bytes? > + lists = [v.split() for v in value] Use shlex.split() to handle quotes inside the strings, so that we can pass args with spaces inside them. e.g. mkimage -n "U-Boot v2022.04". Or each list element could be a single argument with no splitting done. I also wish mkimage -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board" from Makefile was possible, but can't think of a great way. > + args = [x for l in lists for x in l] > + return args > + Anyway, I don't think this belongs here as argument lists are not really a device-tree construct. It would be better in a new binman entry type ("command"?) which mkimage can subclass from. > def GetBool(node, propname, default=False): > """Get an boolean from a property > > diff --git a/tools/dtoc/test/dtoc_test_simple.dts b/tools/dtoc/test/dtoc_test_simple.dts > index 4c2c70af22..2d321fb034 100644 > --- a/tools/dtoc/test/dtoc_test_simple.dts > +++ b/tools/dtoc/test/dtoc_test_simple.dts > @@ -62,5 +62,6 @@ > > orig-node { > orig = <1 23 4>; > + args = "-n first", "second", "-p", "123,456", "-x"; Could be useful to add an argument with single quotes, and one with escaped double quotes. > }; > }; > diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py > index c8fe5fc1de..5d46e69b8b 100755 > --- a/tools/dtoc/test_fdt.py > +++ b/tools/dtoc/test_fdt.py > @@ -652,6 +652,21 @@ class TestFdtUtil(unittest.TestCase): > self.assertEqual(['test'], > fdt_util.GetStringList(self.node, 'missing', ['test'])) > > + def testGetArgs(self): > + node = self.dtb.GetNode('/orig-node') > + self.assertEqual(['message'], fdt_util.GetArgs(self.node, 'stringval')) > + self.assertEqual( > + ['multi-word', 'message'], > + fdt_util.GetArgs(self.node, 'stringarray')) > + self.assertEqual([], fdt_util.GetArgs(self.node, 'boolval')) > + self.assertEqual(['-n', 'first', 'second', '-p', '123,456', '-x'], > + fdt_util.GetArgs(node, 'args')) > + with self.assertRaises(ValueError) as exc: > + fdt_util.GetArgs(self.node, 'missing') > + self.assertIn( > + "Node '/spl-test': Expected property 'missing'", > + str(exc.exception)) > + > def testGetBool(self): > self.assertEqual(True, fdt_util.GetBool(self.node, 'boolval')) > self.assertEqual(False, fdt_util.GetBool(self.node, 'missing'))