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 A4148C433F5 for ; Wed, 23 Feb 2022 23:03:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 85F4983D18; Thu, 24 Feb 2022 00:02:18 +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="VJPcB8iX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 70DCA83D0B; Thu, 24 Feb 2022 00:01:11 +0100 (CET) Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) (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 EB69183CE2 for ; Thu, 24 Feb 2022 00:00:57 +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-oo1-xc2d.google.com with SMTP id x6-20020a4a4106000000b003193022319cso845135ooa.4 for ; Wed, 23 Feb 2022 15:00:57 -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=+QnazhPCsYnFJExFfUMOPoZ3C1voj4jZycna0BhkNGQ=; b=VJPcB8iX6GsMPhz24CkIkpPy9MVHjMKJKRcO8P9AypxVHwBR4zcFyRkz12aa4S3r6W ganLVxgimxWbF0Qlapz6e7p5NkOJc83A/eWy4Ys+LXZbL4Sx5S0pFFhz6Ev5CaRRRgFu U+nCRAyQ26dKz//wepsdBg6ZFiuWsgSV5Czt4= 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=+QnazhPCsYnFJExFfUMOPoZ3C1voj4jZycna0BhkNGQ=; b=3UCXUFneSmxDzx6Ph/nehjXA4t3naxQoLHWpOU6E5TQHZjpzsDkVp+jgrPG9uAT8jX 70r0T7d/PC1atgg82VHyN5idPQuzHw8ueajKYZbLDfNDAuuD9GdCCL5XXs4GOfgsApkp ZXRRNyfIBzfMq9xNZXNMPwS2oOQi298/71RE+tPnlhU08Ou3QkDAsevo1mhoQ94f6Kas aSPN+30w5RR1iwW5xwGk3632JMdG3F0o9I43o5COEPE3NeiHzPDCFED6a5k8yHN6xRtr NfqP2Hj9mCTC4ce327n+RFFK/lUWbHdrli4/Lny9/Yv6fHKBfFmteDsMN6l+qY2dK73C NEzQ== X-Gm-Message-State: AOAM531cURw1Tr58mh1zLRhTKaFfvTCoCNtrbuLiJCyJ1LZ+QL8fECjK 9HFLKGCKAg1gm0h5jwB6Psd81cE2RRwekw== X-Google-Smtp-Source: ABdhPJzXSgrvHUEAXQYVs0vl13GgH/1+1aUo2d3JCuTBCaUhTx8I+7e+r7Px4s82asEueQ+vFU0cEA== X-Received: by 2002:a4a:1b43:0:b0:31b:aa93:dd7d with SMTP id 64-20020a4a1b43000000b0031baa93dd7dmr709039oop.68.1645657256530; Wed, 23 Feb 2022 15:00:56 -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 o2sm427507otl.9.2022.02.23.15.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 15:00:56 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Ivan Mikhaylov , Tom Rini , Philippe Reynes , Roger Quadros , Alper Nebi Yasak , huang lin , Jeffy Chen , Simon Glass , Kever Yang , Philipp Tomsich Subject: [PATCH v2 05/25] dtoc: Tidy up implementation of AddStringList() Date: Wed, 23 Feb 2022 16:00:20 -0700 Message-Id: <20220223230040.159317-6-sjg@chromium.org> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog In-Reply-To: <20220223230040.159317-1-sjg@chromium.org> References: <20220223230040.159317-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Refactor this to avoid a loop. Also add a test for an empty string. Signed-off-by: Simon Glass Suggested-by: Alper Nebi Yasak --- Changes in v2: - Add new patch to tidy up implementaiton of AddStringList() tools/dtoc/fdt.py | 4 +--- tools/dtoc/test_fdt.py | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index c16909a876..d933972918 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -516,9 +516,7 @@ class Node: Returns: Prop added """ - out = b'' - for string in val: - out += bytes(string, 'utf-8') + b'\0' + out = b'\0'.join(bytes(s, 'utf-8') for s in val) + b'\0' if val else b'' return self.AddData(prop_name, out) def AddInt(self, prop_name, val): diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index c2013b9289..d33328c392 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -550,6 +550,12 @@ class TestProp(unittest.TestCase): data = self.fdt.getprop(self.node.Offset(), 'stringlist') self.assertEqual(b'123\x00456\0', data) + val = [] + self.node.AddStringList('stringlist', val) + self.dtb.Sync(auto_resize=True) + data = self.fdt.getprop(self.node.Offset(), 'stringlist') + self.assertEqual(b'', data) + def test_delete_node(self): """Test deleting a node""" old_offset = self.fdt.path_offset('/spl-test') -- 2.35.1.574.g5d30c73bfb-goog