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 73018C433F5 for ; Sun, 6 Feb 2022 21:03:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C6F6083BF2; Sun, 6 Feb 2022 22:03:12 +0100 (CET) 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="JG5M/wzh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E742683BED; Sun, 6 Feb 2022 22:03:10 +0100 (CET) Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) (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 DD49A8319C for ; Sun, 6 Feb 2022 22:03:07 +0100 (CET) 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-x62e.google.com with SMTP id j14so12938787ejy.6 for ; Sun, 06 Feb 2022 13:03:07 -0800 (PST) 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=vRNZ32mKBA/CVRBJOl8Du6T7o8vgI9FMtEP2itiIbWw=; b=JG5M/wzhuTtACQg8F9r4fYLX8l7GjbdJHWp50qLq/hSRqdEmEFBlg2pfQAHaXR4mPH XW0rHLz2Y4cPDXLNTToF2A2SiFpMrjdzoslfnc/7FcGM3Eh3Qawg2mHbLSufic1fOwux kH6Xf1SpreUG3phOHer1Cvc80km/ZbnzZUWyvG27sru8nYGvr2Vy4//2/tE6Z+OaO7s3 4CJb0/BoLy1Hd2PL15oSBf0coofYoppSh6FfQ6XQAyiniwE1wvYJ5NrhbV5Pj8lVnKwy 9jJ2lMK338+JHZ1Ta3YeiasbPCHYfgjaXDfRdjfLQy94JWmw7SOB3RKWEbzX9sVm2CwX y9xA== 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=vRNZ32mKBA/CVRBJOl8Du6T7o8vgI9FMtEP2itiIbWw=; b=SrO08G2HZK5pd6PcsfHAYSAviY13LZaSOkkwf9MGQWit1KcMsTvLWHYL0o9OUsCNv5 J+QD1G0AK8IErh7wT8jSpVIcTGG4jWnSZ4Xa5ghjmtNruS2W8q2ychvKFrn73ZJQXWtk 6UDlaL/If9ECgmgvOvNRO4TKCU/VZruVXa+mNMn0ZcSZQab55g29XxSxjJqCgs4zCsxs mhWCqCCbXou3meqSgLZVjgQEMivL0EQM0mT8iw6+w0bbZCdwHGUZ6acvLoXwvFOnCY6B MjBA0r08QSOjB2DWsRVcP0CgYl/Kwb+Fky0B7Y1MY2YOQurOiV3FffvocCkAT5WHd+aI FW2Q== X-Gm-Message-State: AOAM530rMHZNMtF2D+YeQiVAjgEg/mvgdELYNg6MzcT1F/AQ9f8Gc6P3 WyerxtqjDEBUDUOupP6LvYzKU7GfTLA= X-Google-Smtp-Source: ABdhPJz3WtwjgdTddJasZsUcBayMzJd1y+gzDpvrIkUT2/IZmTFZgezRtxZo5qv5/AVNY9EUumZIJA== X-Received: by 2002:a17:907:3daa:: with SMTP id he42mr7518881ejc.222.1644181386486; Sun, 06 Feb 2022 13:03:06 -0800 (PST) Received: from localhost.localdomain ([178.233.26.119]) by smtp.gmail.com with ESMTPSA id u4sm2168405ejn.216.2022.02.06.13.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 13:03:06 -0800 (PST) From: Alper Nebi Yasak To: u-boot@lists.denx.de Cc: Simon Glass , Jan Kiszka , Heiko Thiery , Alper Nebi Yasak Subject: [PATCH 1/5] binman: Fix subentry expansion for FIT entry type Date: Mon, 7 Feb 2022 00:02:45 +0300 Message-Id: <20220206210250.90406-2-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220206210250.90406-1-alpernebiyasak@gmail.com> References: <20220206210250.90406-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 Binman tries to expand some entries into parts that make it up, e.g. 'u-boot' into a 'u-boot-expanded' section that contains 'u-boot-nodtb' and 'u-boot-dtb'. Entries with child entries must call ExpandEntries() on them to build a correct image, as it's possible that unexpanded child entries have no data of their own. The FIT entry type doesn't currently do this, which means putting a "u-boot" entry inside it doesn't work as expected. Implement ExpandEntries() for FIT and add a copy of a simple FIT image test that checks subentry expansion in FIT entries. Signed-off-by: Alper Nebi Yasak --- tools/binman/etype/fit.py | 5 +++++ tools/binman/ftest.py | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py index 6ad4a686df55..38bc2a2d784e 100644 --- a/tools/binman/etype/fit.py +++ b/tools/binman/etype/fit.py @@ -237,6 +237,11 @@ def _AddNode(base_node, depth, node): self._fdt = Fdt.FromData(fdt.as_bytearray()) self._fdt.Scan() + def ExpandEntries(self): + super().ExpandEntries() + for section in self._fit_sections.values(): + section.ExpandEntries() + def ObtainContents(self): """Obtain the contents of the FIT diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 5400f76c676a..b0f548057980 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -61,6 +61,9 @@ U_BOOT_NODTB_DATA = b'nodtb with microcode pointer somewhere in here' U_BOOT_SPL_NODTB_DATA = b'splnodtb with microcode pointer somewhere in here' U_BOOT_TPL_NODTB_DATA = b'tplnodtb with microcode pointer somewhere in here' +U_BOOT_EXP_DATA = U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA +U_BOOT_SPL_EXP_DATA = U_BOOT_SPL_NODTB_DATA + U_BOOT_SPL_DTB_DATA +U_BOOT_TPL_EXP_DATA = U_BOOT_TPL_NODTB_DATA + U_BOOT_TPL_DTB_DATA FSP_DATA = b'fsp' CMC_DATA = b'cmc' VBT_DATA = b'vbt' @@ -3755,6 +3758,48 @@ def testSimpleFit(self): self.assertEqual(len(U_BOOT_DATA), int(data_sizes[0].split()[0])) self.assertEqual(len(U_BOOT_SPL_DTB_DATA), int(data_sizes[1].split()[0])) + def testSimpleFitExpandsSubentries(self): + """Test that FIT images expand their subentries""" + data = self._DoReadFileDtb('161_fit.dts', use_expanded=True)[0] + self.assertEqual(U_BOOT_EXP_DATA, data[:len(U_BOOT_EXP_DATA)]) + self.assertEqual(U_BOOT_NODTB_DATA, data[-len(U_BOOT_NODTB_DATA):]) + fit_data = data[len(U_BOOT_EXP_DATA):-len(U_BOOT_NODTB_DATA)] + + # The data should be inside the FIT + dtb = fdt.Fdt.FromData(fit_data) + dtb.Scan() + fnode = dtb.GetNode('/images/kernel') + self.assertIn('data', fnode.props) + + fname = os.path.join(self._indir, 'fit_data.fit') + tools.WriteFile(fname, fit_data) + out = tools.Run('dumpimage', '-l', fname) + + # Check a few features to make sure the plumbing works. We don't need + # to test the operation of mkimage or dumpimage here. First convert the + # output into a dict where the keys are the fields printed by dumpimage + # and the values are a list of values for each field + lines = out.splitlines() + + # Converts "Compression: gzip compressed" into two groups: + # 'Compression' and 'gzip compressed' + re_line = re.compile(r'^ *([^:]*)(?:: *(.*))?$') + vals = collections.defaultdict(list) + for line in lines: + mat = re_line.match(line) + vals[mat.group(1)].append(mat.group(2)) + + self.assertEquals('FIT description: test-desc', lines[0]) + self.assertIn('Created:', lines[1]) + self.assertIn('Image 0 (kernel)', vals) + self.assertIn('Hash value', vals) + data_sizes = vals.get('Data Size') + self.assertIsNotNone(data_sizes) + self.assertEqual(2, len(data_sizes)) + # Format is "50 Bytes = 0.00 KiB = 0.00 MiB" so take the first word + self.assertEqual(len(U_BOOT_EXP_DATA), int(data_sizes[0].split()[0])) + self.assertEqual(len(U_BOOT_SPL_DTB_DATA), int(data_sizes[1].split()[0])) + def testFitExternal(self): """Test an image with an FIT with external images""" data = self._DoReadFile('162_fit_external.dts') -- 2.34.1