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 934CEC433F5 for ; Sun, 27 Mar 2022 15:32:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 759FF83941; Sun, 27 Mar 2022 17:32:50 +0200 (CEST) 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="pvwKK7uG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DED1D80F68; Sun, 27 Mar 2022 17:32:18 +0200 (CEST) Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) (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 DC12A83941 for ; Sun, 27 Mar 2022 17:32:14 +0200 (CEST) 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-ej1-x634.google.com with SMTP id j15so23942656eje.9 for ; Sun, 27 Mar 2022 08:32:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BisjAj6UECaGVKjgixlSCXKeZQxFIjGJpuabWO9BS54=; b=pvwKK7uGgh6w50vPYQtKr1fRjH0GNlUGX99k/CrPsr8keN35iLkOEksbIYsvOlUd3b W5fUeubFZXJ3XITukbip5QDQba2Mdc7h0zpwoK6YZu1m1oh8k8E4svi+c+5/9LZE30z0 Ch4nJnEtFQElFCKwnywfGyEwf1bt+2GSajw2eLRSzmqnsA2YQwJfyp9OSbmnyWlT7Kkd Qk0DFxNwDufXBp0XypRggcE9AvWuhO6iCQBWmYmSbINe9BzfYjxaoZjKZDa+AQx8sP5Y jqGXo/NGeLYNRtQxg2qucO3nsa1NkL3jI/9xYtJj2z0o7DCYMLl4i+Y5AlVJ6fdX8ETB Lh/w== 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=BisjAj6UECaGVKjgixlSCXKeZQxFIjGJpuabWO9BS54=; b=GNSUTVaOoxR0MatzlirKJQwsh6m/HwfuiiJM6qfkeOxgdXZ17N1T5S2CubIXBOVYj0 +nIes+Z/YafyZ2jJCx6zU2QDGf8t0lShrz3VvHd+EAAWTe1M1+IanEdoNWAe50m8aHk6 LuniRa6sgyNkWkUKFFtjraH8wvN2KhsbyRDK9sRzZr89lGUYMVJ/wbkUPcJ0Hinhbh8M 8aHhtbneo/4sNuJyTSfg8y5fvAYmtszIuSswmyP/VXiWveb1C+lVcM6SlHL9OfJ6K9sP q4nuxIn68m4nCheDmhTQDkPxpkxkMXKGqghQA0jeCENkjpXtitNmNSt1AqISRTiuZa3+ LTCQ== X-Gm-Message-State: AOAM533GoY9ak4v5zoYjn0by5kIYdShrQiD98rH38Ml4qxtV0A01C47z NOAhb/UuQQ29E5pda1FGEmLtg8GacQQ= X-Google-Smtp-Source: ABdhPJx+W+augIQxPKac6uOuv6dvgh0lfsDraVEcLK/CEvialEctxs5WIpssRuoV30mVnfX7rmCb3A== X-Received: by 2002:a17:906:4fcc:b0:6e0:3269:2054 with SMTP id i12-20020a1709064fcc00b006e032692054mr21960035ejw.117.1648395134408; Sun, 27 Mar 2022 08:32:14 -0700 (PDT) Received: from localhost.localdomain ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id jg22-20020a170907971600b006df9ff416ccsm4639763ejc.137.2022.03.27.08.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 08:32:13 -0700 (PDT) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Thiery , Jan Kiszka , Alper Nebi Yasak Subject: [PATCH 3/7] binman: Don't reset offset/size if image doesn't allow repacking Date: Sun, 27 Mar 2022 18:31:46 +0300 Message-Id: <20220327153151.15912-4-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220327153151.15912-1-alpernebiyasak@gmail.com> References: <20220327153151.15912-1-alpernebiyasak@gmail.com> 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 When an image has the 'allow-repack' property, binman includes the original offset and size properties from the image description in the fdtmap. These are later used as the packing constraints when replacing entries in an image, so other unconstrained entries can be freely positioned. Replacing an entry in an image without 'allow-repack' (and therefore the original offsets) follows the same logic and results in entries being merely concatenated. Instead, skip resetting the calculated offsets and sizes to the missing originals for these images so that every entry is constrained to its existing offset/size. Add tests that replace an entry with smaller or equal-sized data, in an image that doesn't allow repacking. Attempting to do so with bigger-size data is already an error that is already being tested. Signed-off-by: Alper Nebi Yasak --- tools/binman/control.py | 2 +- tools/binman/ftest.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/binman/control.py b/tools/binman/control.py index e170aeae4fab..ce57dc7efc7b 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -303,7 +303,7 @@ def BeforeReplace(image, allow_resize): # If repacking, drop the old offset/size values except for the original # ones, so we are only left with the constraints. - if allow_resize: + if image.allow_repack and allow_resize: image.ResetForPack() diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index da9733d39a6a..3d79f82dff43 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5540,6 +5540,27 @@ def testReplaceCmdOtherWithBintool(self): finally: shutil.rmtree(tmpdir) + def testReplaceResizeNoRepackSameSize(self): + """Test replacing entries with same-size data without repacking""" + expected = b'x' * len(U_BOOT_DATA) + data, expected_fdtmap, _ = self._RunReplaceCmd('u-boot', expected) + self.assertEqual(expected, data) + + path, fdtmap = state.GetFdtContents('fdtmap') + self.assertIsNotNone(path) + self.assertEqual(expected_fdtmap, fdtmap) + + def testReplaceResizeNoRepackSmallerSize(self): + """Test replacing entries with smaller-size data without repacking""" + new_data = b'x' + data, expected_fdtmap, _ = self._RunReplaceCmd('u-boot', new_data) + expected = new_data.ljust(len(U_BOOT_DATA), b'\0') + self.assertEqual(expected, data) + + path, fdtmap = state.GetFdtContents('fdtmap') + self.assertIsNotNone(path) + self.assertEqual(expected_fdtmap, fdtmap) + if __name__ == "__main__": unittest.main() -- 2.35.1