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=-19.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT 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 4B354C4338F for ; Thu, 29 Jul 2021 01:23:59 +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 A5A71608FB for ; Thu, 29 Jul 2021 01:23:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A5A71608FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0033E82DF1; Thu, 29 Jul 2021 03:23:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org 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=chromium.org header.i=@chromium.org header.b="WjFYt7tj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5355682DDA; Thu, 29 Jul 2021 03:23:26 +0200 (CEST) Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) (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 0D7C282CDA for ; Thu, 29 Jul 2021 03:23:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x236.google.com with SMTP id t128so6304452oig.1 for ; Wed, 28 Jul 2021 18:23:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PV3LoPn+gsEPUTW589mSy2fKmYeyziVVPvw1C3F4TMw=; b=WjFYt7tjS5AW30B8OojO7jqIh9klx2MX+SdPAwQ/SJ3XxrJn/uFXSWTVwpIg/t5FoT p2hN/B7q7KptE6p1EMY9qPtuTabZIhaogqV1rM4y75iF55t2/8cu90Vli0mIRCK9TrrX 627adbcnDbLfu9HnpKR7aJCCmhBjGV9dxxGu4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PV3LoPn+gsEPUTW589mSy2fKmYeyziVVPvw1C3F4TMw=; b=kdu2tHJHL+c+DGypYgt9eLCXnobSv/8qis5IqSo3ZOsaO6QhSoxlG3a4kX6rl8VUs4 HwVJfQkIg6P8Pw2T0HIF0OGxgfuemaXgFuMGj6dfI/aaKBV/Y6I+m6qKNMCF7C9Sjrqa 1tC7OMpjdnIpwLS7wx6D1de54hPyGa/42qIef60qztTqdEq9pZ9tr76kxVyPBOkzHJxl 04DhKIbU4lTSfn1mXpXG8YziSl4wbZXmbOMRWcpqcER4yOvRnPwJpEKYzVxyvjB3Sq5O UZP6AR7xOfoewqJTnhjEvK09A+HTQ0MWTTv2rK3vOwcqIb+UXbmpMdOce8XFN8ZT8tG6 i55Q== X-Gm-Message-State: AOAM5300vuB85nYuH25xTU/cqSwP3h2NvSaSoBY3ey973/JeFNV/mx1M 9sxzO2/jyYye8rIs9xS1Xd7bYHLZOcrqaX8F X-Google-Smtp-Source: ABdhPJwH1ewIK8oFPbPdpWxTsnCh7HbDeEO+YzJBX/e4cxaJtELRjXuFp6guPe2genO+3+08aIeP/g== X-Received: by 2002:aca:4a4f:: with SMTP id x76mr1522259oia.136.1627521799220; Wed, 28 Jul 2021 18:23:19 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id l11sm308867otf.1.2021.07.28.18.23.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 18:23:18 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Heiko Schocher , Heinrich Schuchardt , Philippe Reynes , =?UTF-8?q?Vincent=20Stehl=C3=A9?= , Walter Lozano Subject: [PATCH 3/3] dtoc: Support widening a bool value Date: Wed, 28 Jul 2021 19:23:11 -0600 Message-Id: <20210729012311.1406847-4-sjg@chromium.org> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog In-Reply-To: <20210729012311.1406847-1-sjg@chromium.org> References: <20210729012311.1406847-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 At present if we see 'ranges' property (with no value) we assume it is a boolean, as per the devicetree spec. But another node may define 'ranges' with a value, forcing us to widen it to an int array. At present this is not supported and causes an error. Fix this and add some test cases. Signed-off-by: Simon Glass Reported-by: Tom Rini --- arch/sandbox/dts/sandbox.dtsi | 2 ++ test/dm/of_platdata.c | 3 +++ tools/dtoc/fdt.py | 12 ++++++++++++ tools/dtoc/test/dtoc_test_simple.dts | 2 ++ tools/dtoc/test_dtoc.py | 3 +++ tools/dtoc/test_fdt.py | 18 ++++++++++++++++-- 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi index 31db50db352..200fcab6a41 100644 --- a/arch/sandbox/dts/sandbox.dtsi +++ b/arch/sandbox/dts/sandbox.dtsi @@ -231,6 +231,7 @@ boolval; intval = <1>; intarray = <2 3 4>; + maybe-empty-int = <>; byteval = [05]; bytearray = [06]; longbytearray = [09 0a 0b 0c 0d 0e 0f 10 11]; @@ -254,6 +255,7 @@ u-boot,dm-pre-reloc; compatible = "sandbox,spl-test"; stringarray = "one"; + maybe-empty-int = <1>; }; spl-test5 { diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c index e3fa01afddf..0463cf0b433 100644 --- a/test/dm/of_platdata.c +++ b/test/dm/of_platdata.c @@ -40,6 +40,8 @@ static int dm_test_of_plat_props(struct unit_test_state *uts) ut_asserteq(3, plat->intarray[1]); ut_asserteq(4, plat->intarray[2]); ut_asserteq(5, plat->byteval); + ut_asserteq(1, ARRAY_SIZE(plat->maybe_empty_int)); + ut_asserteq(0, plat->maybe_empty_int[0]); ut_asserteq(3, ARRAY_SIZE(plat->bytearray)); ut_asserteq(6, plat->bytearray[0]); ut_asserteq(0, plat->bytearray[1]); @@ -78,6 +80,7 @@ static int dm_test_of_plat_props(struct unit_test_state *uts) ut_asserteq_str("one", plat->stringarray[0]); ut_asserteq_str("", plat->stringarray[1]); ut_asserteq_str("", plat->stringarray[2]); + ut_asserteq(1, plat->maybe_empty_int[0]); ut_assertok(uclass_next_device_err(&dev)); plat = dev_get_plat(dev); diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index 429e95f9a96..32a7aa98290 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -153,6 +153,18 @@ class Prop: specific. """ if self.type.needs_widening(newprop.type): + + # A boolean has an empty value: if it exists it is True and if not + # it is False. So when widening we always start with an empty list + # since the only valid integer property would be an empty list of + # integers. + # e.g. this is a boolean: + # some-prop; + # and it would be widened to int list by: + # some-prop = <1 2>; + if self.type == Type.BOOL: + self.type = Type.INT + self.value = [self.GetEmpty(self.type)] if self.type == Type.INT and newprop.type == Type.BYTE: if type(self.value) == list: new_value = [] diff --git a/tools/dtoc/test/dtoc_test_simple.dts b/tools/dtoc/test/dtoc_test_simple.dts index b5c1274bb7c..5a6fa88d5cc 100644 --- a/tools/dtoc/test/dtoc_test_simple.dts +++ b/tools/dtoc/test/dtoc_test_simple.dts @@ -14,6 +14,7 @@ u-boot,dm-pre-reloc; compatible = "sandbox,spl-test"; boolval; + maybe-empty-int = <>; intval = <1>; intarray = <2 3 4>; byteval = [05]; @@ -42,6 +43,7 @@ compatible = "sandbox,spl-test"; stringarray = "one"; longbytearray = [09 0a 0b 0c 0d 0e 0f 10]; + maybe-empty-int = <1>; }; i2c@0 { diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 44d5d0c354a..752061f27a4 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -299,6 +299,7 @@ struct dtd_sandbox_spl_test { \tfdt32_t\t\tintarray[3]; \tfdt32_t\t\tintval; \tunsigned char\tlongbytearray[9]; +\tfdt32_t\t\tmaybe_empty_int[1]; \tunsigned char\tnotstring[5]; \tconst char *\tstringarray[3]; \tconst char *\tstringval; @@ -358,6 +359,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test = { \t.intval\t\t\t= 0x1, \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, \t\t0x11}, +\t.maybe_empty_int\t= {0x0}, \t.notstring\t\t= {0x20, 0x21, 0x22, 0x10, 0x0}, \t.stringarray\t\t= {"multi-word", "message", ""}, \t.stringval\t\t= "message", @@ -398,6 +400,7 @@ U_BOOT_DRVINFO(spl_test2) = { static struct dtd_sandbox_spl_test dtv_spl_test3 = { \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, \t\t0x0}, +\t.maybe_empty_int\t= {0x1}, \t.stringarray\t\t= {"one", "", ""}, }; U_BOOT_DRVINFO(spl_test3) = { diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index 857861c14ed..1119e6b7847 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -122,8 +122,9 @@ class TestFdt(unittest.TestCase): node = self.dtb.GetNode('/spl-test') props = self.dtb.GetProps(node) self.assertEqual(['boolval', 'bytearray', 'byteval', 'compatible', - 'intarray', 'intval', 'longbytearray', 'notstring', - 'stringarray', 'stringval', 'u-boot,dm-pre-reloc'], + 'intarray', 'intval', 'longbytearray', + 'maybe-empty-int', 'notstring', 'stringarray', + 'stringval', 'u-boot,dm-pre-reloc'], sorted(props.keys())) def testCheckError(self): @@ -431,6 +432,19 @@ class TestProp(unittest.TestCase): self.assertEqual(Type.INT, prop.type) self.assertEqual(3, len(prop.value)) + # Widen an empty bool to an int + prop = self.node.props['maybe-empty-int'] + prop3 = node3.props['maybe-empty-int'] + self.assertEqual(Type.BOOL, prop.type) + self.assertEqual(True, prop.value) + self.assertEqual(Type.INT, prop3.type) + self.assertFalse(isinstance(prop.value, list)) + self.assertEqual(4, len(prop3.value)) + prop.Widen(prop3) + self.assertEqual(Type.INT, prop.type) + self.assertTrue(isinstance(prop.value, list)) + self.assertEqual(1, len(prop.value)) + def testAdd(self): """Test adding properties""" self.fdt.pack() -- 2.32.0.432.gabb21c7263-goog