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 9DE02EB64DC for ; Tue, 11 Jul 2023 15:03:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id ED987868D6; Tue, 11 Jul 2023 17:00: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="CkuzolBA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6A983868C8; Tue, 11 Jul 2023 17:00:29 +0200 (CEST) Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) (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 1D174868CF for ; Tue, 11 Jul 2023 17:00:07 +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-il1-x12b.google.com with SMTP id e9e14a558f8ab-3460815fde5so29443955ab.2 for ; Tue, 11 Jul 2023 08:00:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1689087601; x=1691679601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bJKqERo9Og/cl4SLkNe7ynzZQ9nhWhun3l1OyHK95ko=; b=CkuzolBAR/1OTU8qie1v6Pu564r+kCYWeogK+iqBGEVlZ7X9WpQSZKViKnuXaTFXaR sYGpPq6pafeVLvTSa7XMvdV2zHKWditgSKyRyXkbFbwlLHKF55Bovp9YeardCWJTmGic V24vpRq5xMcHV3K46ruIR/lCuLKe0uSXJ2Aqc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689087601; x=1691679601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bJKqERo9Og/cl4SLkNe7ynzZQ9nhWhun3l1OyHK95ko=; b=iLk7zH11UQaQcHgkDC0q4mcxOW14UAfoPta9vgMqpOkdcjp4Lwj0nwN7m3Kln+VhGX JsSHMUd/9DkTvCoRcKl2AvQPhd2WgIiBOGhZJ7rqEzuMg9HwUrlYvcY6xugXVXjvKFkX BduhpOF8c/IStFcU3t3HyFuxML+8VE9o9oBgc5IatMdsROUN346p2+6JDMI/uAh9lrem BR/xe5Z1Q7kpHOqypnE7zLs0tYym2SPVr2RmSrr7vDTbMbF0TXInd4x53VCH/yCfj7KV 6ArnvqERlWd7zMYQ8aAUG4AXkqIlLuKe8v2r8HBl81f2jTEkaIz0yVo0pKhmGfKKFkn0 2qDg== X-Gm-Message-State: ABy/qLZYJGZY3ZJNDP8x/pw2j6ocz3hyOJkt+yOfrSHtBWnEWVS0mmdN 2YzR2jAP2zyGB34zEQUcbplQOypW5J102bScyoo= X-Google-Smtp-Source: APBJJlHDhmDWx6bNJEWWfUvg8aJr/XdUrClLx6cGOXpUK+QKMqOWYxaIy7idwFnetGCipoEacWl/Tg== X-Received: by 2002:a92:c841:0:b0:346:d51:9922 with SMTP id b1-20020a92c841000000b003460d519922mr15913929ilq.13.1689087600991; Tue, 11 Jul 2023 08:00:00 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id v6-20020a92cd46000000b00338a1272ce1sm658881ilq.52.2023.07.11.08.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 08:00:00 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Marek Vasut , Jan Kiszka , Simon Glass , Alper Nebi Yasak , Neha Malcom Francis , Peng Fan , Philippe Reynes , Stefan Herbrechtsmeier Subject: [PATCH v4 19/20] binman: Support writing symbols inside a mkimage image Date: Tue, 11 Jul 2023 08:59:21 -0600 Message-ID: <20230711145935.2289816-20-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.390.g38632f3daf-goog In-Reply-To: <20230711145935.2289816-1-sjg@chromium.org> References: <20230711145935.2289816-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.8 at phobos.denx.de X-Virus-Status: Clean Add support for writing symbols and determining the assumed position of binaries inside a mkimage image. This is useful as an example for other entry types which might want to do the same thing. Signed-off-by: Simon Glass --- (no changes since v3) Changes in v3: - Add new patch to support writing symbols inside a mkimage image tools/binman/entry.py | 2 - tools/binman/etype/mkimage.py | 36 +++++++++++++++ tools/binman/ftest.py | 64 +++++++++++++++++++++++++++ tools/binman/test/290_mkimage_sym.dts | 27 +++++++++++ 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 tools/binman/test/290_mkimage_sym.dts diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 0d4cb94f7002..42e0b7b91450 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -1314,8 +1314,6 @@ features to produce new behaviours. """ data = b'' for entry in entries: - # First get the input data and put it in a file - entry.ObtainContents(fake_size=fake_size) data += entry.GetData() uniq = self.GetUniqueName() fname = tools.get_output_filename(f'{prefix}.{uniq}') diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py index 493761da59f5..9d60c85722b3 100644 --- a/tools/binman/etype/mkimage.py +++ b/tools/binman/etype/mkimage.py @@ -268,3 +268,39 @@ class Entry_mkimage(Entry_section): def CheckEntries(self): pass + + def ProcessContents(self): + # The blob may have changed due to WriteSymbols() + ok = super().ProcessContents() + data = self.BuildSectionData(True) + ok2 = self.ProcessContentsUpdate(data) + return ok and ok2 + + def SetImagePos(self, image_pos): + """Set the position in the image + + This sets each subentry's offsets, sizes and positions-in-image + according to where they ended up in the packed mkimage file. + + NOTE: This assumes a legacy mkimage and assumes that the images are + written to the output in order. SoC-specific mkimage handling may not + conform to this, in which case these values may be wrong. + + Args: + image_pos (int): Position of this entry in the image + """ + # The mkimage header consists of 0x40 bytes, following by a table of + # offsets for each file + upto = 0x40 + + # Skip the 0-terminated list of offsets (assume a single image) + upto += 4 + 4 + for entry in self.GetEntries().values(): + entry.SetOffsetSize(upto, None) + + # Give up if any entries lack a size + if entry.size is None: + return + upto += entry.size + + super().SetImagePos(image_pos) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index e96223cbd892..e53181afb78a 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -6820,6 +6820,70 @@ fdt fdtmap Extract the devicetree blob from the fdtmap second = U_BOOT_DATA + b'#' + VGA_DATA + U_BOOT_DTB_DATA self.assertEqual(U_BOOT_IMG_DATA + first + second + first, data) + def testMkimageSymbols(self): + """Test using mkimage to build an image with symbols in it""" + self._SetupSplElf('u_boot_binman_syms') + data = self._DoReadFile('290_mkimage_sym.dts') + + image = control.images['image'] + entries = image.GetEntries() + self.assertIn('u-boot', entries) + u_boot = entries['u-boot'] + + mkim = entries['mkimage'] + mkim_entries = mkim.GetEntries() + self.assertIn('u-boot-spl', mkim_entries) + spl = mkim_entries['u-boot-spl'] + self.assertIn('u-boot-spl2', mkim_entries) + spl2 = mkim_entries['u-boot-spl2'] + + # skip the mkimage header and the area sizes + mk_data = data[mkim.offset + 0x40:] + size, term = struct.unpack('>LL', mk_data[:8]) + + # There should be only one image, so check that the zero terminator is + # present + self.assertEqual(0, term) + + content = mk_data[8:8 + size] + + # The image should contain the symbols from u_boot_binman_syms.c + # Note that image_pos is adjusted by the base address of the image, + # which is 0x10 in our test image + spl_data = content[:0x18] + content = content[0x1b:] + + # After the header is a table of offsets for each image. There should + # only be one image, then a 0 terminator, so figure out the real start + # of the image data + base = 0x40 + 8 + + # Check symbols in both u-boot-spl and u-boot-spl2 + for i in range(2): + vals = struct.unpack('; + #size-cells = <1>; + + binman { + u-boot-dtb { + }; + + mkimage { + args = "-n test -T script"; + + u-boot-spl { + }; + + u-boot-spl2 { + type = "u-boot-spl"; + }; + }; + + u-boot { + }; + }; +}; -- 2.41.0.390.g38632f3daf-goog