From patchwork Mon Oct 19 02:41:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1383978 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Jrr6bDat; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CF1P053cjz9sSG for ; Mon, 19 Oct 2020 13:46:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2466C824DA; Mon, 19 Oct 2020 04:42:40 +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="Jrr6bDat"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5068D8244F; Mon, 19 Oct 2020 04:42:12 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) (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 293F08243D for ; Mon, 19 Oct 2020 04:42:08 +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-io1-xd41.google.com with SMTP id k25so11279769ioh.7 for ; Sun, 18 Oct 2020 19:42:08 -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=vUVcHQ4Wv1c271lq6r/0FI16lH+cEUMkMm7onKuzqVQ=; b=Jrr6bDatlxxJ7nSke4LoTyVAbKR7nxZM6oDSquYYnrlNrBuGQX5amyyka57AwKs5i/ ImXQJXB0NvaXUy5s0txPe4WSEoIWeNEIYvqJib5vJsSboJnYvmdc/2LFgatQVUYwpTV1 4tWST9jnOXR6+j+QlsvIggkdN2Bj/KXLn6quQ= 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=vUVcHQ4Wv1c271lq6r/0FI16lH+cEUMkMm7onKuzqVQ=; b=lcogOBNjVo2/eVrF/h7u72Z1Ea4UlBEZayqU99i+HKVimvXnl4W0Oo5pzif3Yp7Wb2 5gWhse2biJBIPONmOQlxIq05qMOFmQG3m2xZLpT231yLbpEJarSdWUFGQ/maobi7vOKN otog8KHyg76OdFfh+kBhZD2ykh9hD47abHVI2TXb+2hpH+S7yOL6JpLI//B+57sO+csz 9J4BW7qz99LVO92mGRHziWLZ8dpVSzpp2sDcUnmxYM9d7uAN/bRibj1UBfyYgCgoxBsG jJRe2ZK+9iLs+/NzM3on7fYURBxoCiCiRUFwXQ5JyvxJcCB2ghzo2DtO40ZFRib3ClhR d4hQ== X-Gm-Message-State: AOAM533lIrQbKeegJHcEHiHPE0ED3M1UiyGK40oKtQ5+gNv4IAYPsCig LR+XJEbuJnmIuBNy6+CS0Jd6FoMGxh0TqX5q X-Google-Smtp-Source: ABdhPJzZOJ8ov3HoXid+YqlAtNBym/NwK2uQHqOiDtg9D8VUe6RmiLC9gRZXz807/x9s/o5flS6EnQ== X-Received: by 2002:a02:6d61:: with SMTP id e33mr9496091jaf.14.1603075326585; Sun, 18 Oct 2020 19:42:06 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id g185sm9750871ilh.35.2020.10.18.19.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 19:42:06 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Alper Nebi Yasak , Bin Meng Subject: [PATCH 25/25] binman: Avoid calculated section data repeatedly Date: Sun, 18 Oct 2020 20:41:38 -0600 Message-Id: <20201019024138.3804540-25-sjg@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201019024138.3804540-1-sjg@chromium.org> References: <20201019024138.3804540-1-sjg@chromium.org> MIME-Version: 1.0 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.102.3 at phobos.denx.de X-Virus-Status: Clean Refactor the implementation slightly so that section data is not rebuilt when it is already available. We still have GetData() set up to rebuild the section, since we don't currently track when things change that might affect a section. For example, if a blob is updated within a section, we must rebuild it. Tracking that would be possible but is more complex, so it left for another time. Signed-off-by: Simon Glass --- tools/binman/etype/section.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 570dbfcfd41..3dd5f58c4c2 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -147,7 +147,7 @@ class Entry_section(Entry): def ObtainContents(self): return self.GetEntryContents() - def GetPaddedDataForEntry(self, entry): + def GetPaddedDataForEntry(self, entry, entry_data): """Get the data for an entry including any padding Gets the entry data and uses the section pad-byte value to add padding @@ -170,7 +170,7 @@ class Entry_section(Entry): data += tools.GetBytes(self._pad_byte, entry.pad_before) # Add in the actual entry data - data += entry.GetData() + data += entry_data # Handle padding after the entry if entry.pad_after: @@ -197,7 +197,7 @@ class Entry_section(Entry): section_data = b'' for entry in self._entries.values(): - data = self.GetPaddedDataForEntry(entry) + data = self.GetPaddedDataForEntry(entry, entry.GetData()) # Handle empty space before the entry pad = (entry.offset or 0) - self._skip_at_start - len(section_data) if pad > 0: @@ -210,7 +210,7 @@ class Entry_section(Entry): (len(self._entries), len(section_data))) return self.CompressData(section_data) - def GetPaddedData(self): + def GetPaddedData(self, data=None): """Get the data for a section including any padding Gets the section data and uses the parent section's pad-byte value to @@ -225,7 +225,9 @@ class Entry_section(Entry): after it (bytes) """ section = self.section or self - return section.GetPaddedDataForEntry(self) + if data is None: + data = self.GetData() + return section.GetPaddedDataForEntry(self, data) def GetData(self): """Get the contents of an entry @@ -264,8 +266,10 @@ class Entry_section(Entry): self._SortEntries() self._ExpandEntries() - size = self.CheckSize() - self.size = size + data = self._BuildSectionData() + self.SetContents(data) + + self.CheckSize() offset = super().Pack(offset) self.CheckEntries() @@ -542,14 +546,12 @@ class Entry_section(Entry): for name, info in offset_dict.items(): self._SetEntryOffsetSize(name, *info) - def CheckSize(self): - data = self._BuildSectionData() - contents_size = len(data) + contents_size = len(self.data) size = self.size if not size: - data = self.GetPaddedData() + data = self.GetPaddedData(self.data) size = len(data) size = tools.Align(size, self.align_size)