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 AC6DCEB64DC for ; Tue, 11 Jul 2023 15:01:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 107BE868A2; Tue, 11 Jul 2023 17:00:21 +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="L/PaeZzV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 754C68681B; Tue, 11 Jul 2023 16:59:57 +0200 (CEST) Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) (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 83DE786887 for ; Tue, 11 Jul 2023 16:59:52 +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-x12d.google.com with SMTP id e9e14a558f8ab-3458a08310aso22450595ab.3 for ; Tue, 11 Jul 2023 07:59:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1689087591; x=1691679591; 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=QcfGMsK+9Yb6IKwIIWM0ZE576/7Njv8dv51p/ij1S0E=; b=L/PaeZzVwz061qFYc+BHw1FjVaRcmGzP8i2yMzYGGXWr1Rtjr0s1I7h+OuVcT34Kys g9u9/BHdboP0y55cFowViRfB1Q/1cTVJ891cn+ibacHkvMbGTpBdy3EEqirNG7iAYIq0 355v4ImxnorMfJh8DG2Rk07aq2IZ2EX/4Uiak= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689087591; x=1691679591; 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=QcfGMsK+9Yb6IKwIIWM0ZE576/7Njv8dv51p/ij1S0E=; b=E0ZdR6fOAHSqfdUUI3ozoIzxbv8ED2ibx8ZOxgX4kfbuTPac99ZM4Mo/gg8LsMqqY/ 4iF3O8vWR8FhCKSsX4RLBHrbvP925N0D72RarXqBYbSrFaoP7hOKhk+zi3SpQICgOdr3 50bzbUlnz2PYPxQAj8lEIr9fQaBMqSAxPW5IkLTe6byIdJy/mB/XxQGAnhk5nSLQ0b/B ZxG3v8HpzAbhD6FlNgjYT+bagFr/aPbPPWo5I9OFZb8zvQ/EiB8BigkP3lW1kBJnhd8C D72X/R1vNcCsBQWlkhBiEOimhRzsX1EDZDOWHEy2XIHfjt1TcJeWvpGLfuGpjjGvUQLD Ly/w== X-Gm-Message-State: ABy/qLYUQspKAQJ/mN1ay0gsOPkCfqqQCP+i46/fQ/Bwsh/aN+jFwzKM j8C4CcCFUYNOXnbwCW+ZDYP4ZmkxLQpIilLS3as= X-Google-Smtp-Source: APBJJlEyyo5VdZD+vVX41BEQJhdIEjyBeJw81zSxtDKC7qLIfbM5thke89fR/29QgkPepYQY5Z6qDg== X-Received: by 2002:a92:dc0f:0:b0:346:70cc:ac7e with SMTP id t15-20020a92dc0f000000b0034670ccac7emr2107068iln.9.1689087591026; Tue, 11 Jul 2023 07:59:51 -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.07.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 07:59:50 -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 07/20] binman: Update elf to return number of written symbols Date: Tue, 11 Jul 2023 08:59:09 -0600 Message-ID: <20230711145935.2289816-8-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 Update the LookupAndWriteSymbols() function to return the number of symbols written. Also add some logging for when debugging is not enabled. Signed-off-by: Simon Glass --- (no changes since v3) Changes in v3: - Add new patch for elf to return number of written symbols tools/binman/elf.py | 13 +++++++++++-- tools/binman/elf_test.py | 8 +++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/binman/elf.py b/tools/binman/elf.py index 5816284c32a2..4219001feac3 100644 --- a/tools/binman/elf.py +++ b/tools/binman/elf.py @@ -248,6 +248,9 @@ def LookupAndWriteSymbols(elf_fname, entry, section, is_elf=False, entry: Entry to process section: Section which can be used to lookup symbol values base_sym: Base symbol marking the start of the image + + Returns: + int: Number of symbols written """ if not base_sym: base_sym = '__image_copy_start' @@ -269,12 +272,13 @@ def LookupAndWriteSymbols(elf_fname, entry, section, is_elf=False, if not syms: tout.debug('LookupAndWriteSymbols: no syms') - return + return 0 base = syms.get(base_sym) if not base and not is_elf: tout.debug('LookupAndWriteSymbols: no base') - return + return 0 base_addr = 0 if is_elf else base.address + count = 0 for name, sym in syms.items(): if name.startswith('_binman'): msg = ("Section '%s': Symbol '%s'\n in entry '%s'" % @@ -307,6 +311,11 @@ def LookupAndWriteSymbols(elf_fname, entry, section, is_elf=False, (msg, name, offset, value, len(value_bytes))) entry.data = (entry.data[:offset] + value_bytes + entry.data[offset + sym.size:]) + count += 1 + if count: + tout.detail( + f"Section '{section.GetPath()}': entry '{entry.GetPath()}' : {count} symbols") + return count def GetSymbolValue(sym, data, msg): """Get the value of a symbol diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py index c98083961b53..2fb3f6f28ff1 100644 --- a/tools/binman/elf_test.py +++ b/tools/binman/elf_test.py @@ -141,7 +141,8 @@ class TestElf(unittest.TestCase): entry = FakeEntry(10) section = FakeSection() elf_fname = self.ElfTestFile('u_boot_binman_syms_bad') - elf.LookupAndWriteSymbols(elf_fname, entry, section) + count = elf.LookupAndWriteSymbols(elf_fname, entry, section) + self.assertEqual(0, count) def testBadSymbolSize(self): """Test that an attempt to use an 8-bit symbol are detected @@ -162,7 +163,7 @@ class TestElf(unittest.TestCase): def testNoValue(self): """Test the case where we have no value for the symbol - This should produce -1 values for all thress symbols, taking up the + This should produce -1 values for all three symbols, taking up the first 16 bytes of the image. """ if not elf.ELF_TOOLS: @@ -170,7 +171,8 @@ class TestElf(unittest.TestCase): entry = FakeEntry(28) section = FakeSection(sym_value=None) elf_fname = self.ElfTestFile('u_boot_binman_syms') - elf.LookupAndWriteSymbols(elf_fname, entry, section) + count = elf.LookupAndWriteSymbols(elf_fname, entry, section) + self.assertEqual(5, count) expected = (struct.pack('