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 EC850C433EF for ; Tue, 23 Nov 2021 18:05:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0F1C082F73; Tue, 23 Nov 2021 19:04:44 +0100 (CET) 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="QZMN7QH7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 433AD8372E; Tue, 23 Nov 2021 19:04:27 +0100 (CET) Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) (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 D16B483681 for ; Tue, 23 Nov 2021 19:04:16 +0100 (CET) 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-ot1-x32e.google.com with SMTP id r10-20020a056830080a00b0055c8fd2cebdso119421ots.6 for ; Tue, 23 Nov 2021 10:04:16 -0800 (PST) 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=rW6DuiJgFJytjuChgUSioCLCXiqC9uhznYMckWbanuQ=; b=QZMN7QH7MYSxEKM/KqmWKYXAHV/7CGzjvx+lU6LRIhV82Ew+9v3+ibnJxieItfcA5j Bi/XK0F1DODZ5zyQGPi6WlSalKpAGOJ70asxxe+/w/NZgwDqKCZGi18PGcsAaJuPawsP ubeXZghymwPzMoGFBjgy4JodvrG5Tys3CcNy8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rW6DuiJgFJytjuChgUSioCLCXiqC9uhznYMckWbanuQ=; b=7/vmTQtlgpvXsmFp5qKrFxs1MMY0xrLJ1g9BnZ9YMUy4niENUbuuY+w1Xb1/RF1itj Xi2yHfOCez4I2gKH/z362jSPiozoGt72lQ9Z+uh2Hm0TS2dublxcZnV87cZvAITo3SOV gVrh97slArnJk6pE3h/yYvQ5iHoybAXbk7hyBpp5ZWi+fqG7BCu0e1icH5rwr9DwtgY3 tyM8F9c5CIJlbiO5pFe9yNujlq42+v203J6zZlbzZZVaflWCrU+QATlmCpctILKeUdWm QE3RhE9vjNJA6vKXdfLym9sQ3ypvWWBjrbMhIja0Trf46heee9gzUdK9YaETUphliKu/ n8rA== X-Gm-Message-State: AOAM5319yQOY0yymZeDFVFA1IkUXolSqcTkJYMmw7Hb13d1Asqsh0nD0 WeF6wmf8P7hjShj5bK0woerUlH6ZvdgJag== X-Google-Smtp-Source: ABdhPJxhd6B5Cv2C5fB/tfBr8oXcKA+s0LNMYO0P7Wy6M1UI2TKg+W7zCXN936Do4tMlh3lSuY9NkQ== X-Received: by 2002:a05:6830:2712:: with SMTP id j18mr6281228otu.302.1637690655192; Tue, 23 Nov 2021 10:04:15 -0800 (PST) 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 c8sm2357514otk.40.2021.11.23.10.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 10:04:14 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Walter Lozano Subject: [PATCH 03/17] dtoc: Add support for reading fixed-length bytes properties Date: Tue, 23 Nov 2021 11:03:40 -0700 Message-Id: <20211123180354.615946-4-sjg@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211123180354.615946-1-sjg@chromium.org> References: <20211123180354.615946-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.37 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 Add functions to read a sequence of bytes from the devicetree. Signed-off-by: Simon Glass --- scripts/pylint.base | 4 ++-- tools/dtoc/fdt_util.py | 20 ++++++++++++++++++++ tools/dtoc/test_fdt.py | 17 +++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/scripts/pylint.base b/scripts/pylint.base index d848ebe9058..f4f226799c1 100644 --- a/scripts/pylint.base +++ b/scripts/pylint.base @@ -44,12 +44,12 @@ cros_ec_rw -6.00 defs 6.67 dtoc.dtb_platdata 7.82 dtoc.fdt 3.47 -dtoc.fdt_util 4.53 +dtoc.fdt_util 4.95 dtoc.main 7.33 dtoc.setup 5.00 dtoc.src_scan 8.75 dtoc.test_dtoc 8.54 -dtoc.test_fdt 6.92 +dtoc.test_fdt 6.93 dtoc.test_src_scan 9.43 efivar 6.71 endian-swap 8.93 diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py index 51d0eb52423..51bdbdcd3b2 100644 --- a/tools/dtoc/fdt_util.py +++ b/tools/dtoc/fdt_util.py @@ -202,6 +202,26 @@ def GetByte(node, propname, default=None): (node.name, propname, len(value), 1)) return ord(value[0]) +def GetBytes(node, propname, size, default=None): + """Get a set of bytes from a property + + Args: + node (Node): Node object to read from + propname (str): property name to read + size (int): Number of bytes to expect + default (bytes): Default value or None + + Returns: + bytes: Bytes value read, or default if none + """ + prop = node.props.get(propname) + if not prop: + return default + if len(prop.bytes) != size: + raise ValueError("Node '%s' property '%s' has length %d, expecting %d" % + (node.name, propname, len(prop.bytes), size)) + return prop.bytes + def GetPhandleList(node, propname): """Get a list of phandles from a property diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index 21a9a7ca063..7a4c7efaa4a 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -635,6 +635,23 @@ class TestFdtUtil(unittest.TestCase): self.assertIn("property 'intval' has length 4, expecting 1", str(e.exception)) + def testGetBytes(self): + self.assertEqual(bytes([5]), fdt_util.GetBytes(self.node, 'byteval', 1)) + self.assertEqual(None, fdt_util.GetBytes(self.node, 'missing', 3)) + self.assertEqual( + bytes([3]), fdt_util.GetBytes(self.node, 'missing', 3, bytes([3]))) + + with self.assertRaises(ValueError) as e: + fdt_util.GetBytes(self.node, 'longbytearray', 7) + self.assertIn( + "Node 'spl-test' property 'longbytearray' has length 9, expecting 7", + str(e.exception)) + + self.assertEqual( + bytes([0, 0, 0, 1]), fdt_util.GetBytes(self.node, 'intval', 4)) + self.assertEqual( + bytes([3]), fdt_util.GetBytes(self.node, 'missing', 3, bytes([3]))) + def testGetPhandleList(self): dtb = fdt.FdtScan(find_dtb_file('dtoc_test_phandle.dts')) node = dtb.GetNode('/phandle-source2') -- 2.34.0.rc2.393.gf8c9666880-goog