From patchwork Sun Sep 25 15:02:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1682189 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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: legolas.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=FdE9pgxp; 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 ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mb8Mn6y05z1yq1 for ; Mon, 26 Sep 2022 01:05:41 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 26AE684C5B; Sun, 25 Sep 2022 17:03:54 +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="FdE9pgxp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0C87C84B06; Sun, 25 Sep 2022 17:03:29 +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.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) (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 AFF5C84AF7 for ; Sun, 25 Sep 2022 17:03:22 +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-xd2b.google.com with SMTP id n192so2242643iod.3 for ; Sun, 25 Sep 2022 08:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=HO3xXID79KvDPxQkbjkGcWbLppMgX19lIU/H8zaLHi0=; b=FdE9pgxpRScHZyuJgJQDprzg1l9nZjBO47vIB9VAffEKMBrUYVRAUU4FkJcHScaYfI wiAmyFsE2xOmiQrkhfzfnhRCTNCGU+BKhrVMzDB7qJp27UqPMjpurj48Y0WKgTHMxWqS HLRqiq5lr79WbH56W5PbPsnWPBD96u99YcmBc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=HO3xXID79KvDPxQkbjkGcWbLppMgX19lIU/H8zaLHi0=; b=IH0CcQku2H++5DkMBtVTN374XNwKaQgZjbqBJyNlbIniRgg5MKUe9XlwsKa13ASMRM G83vXxlso2nLCew5TZ24LhmIlu3d/4eErEBl++Neyl27V63G5UR5wELK1lbsDm2EDaf/ FgjnIaodWn+u1I90ojwwnTf28e4zxOeQFGIxCCVKIh5QGa5TP6Ovz9TxVlAoMI3JbEnU Cw23JNPFUxLcOSJAdn0DBF0fQby1fIDY2zg2srRYBXoNUP5PCjiKGdNkpKe34tzEmdmt 3FetTOKow6uK7OVdPaDE53j6HJ/uj7rNiaK618LQYvmvInhmJh779WzE++u7KfV+BioJ 6YMA== X-Gm-Message-State: ACrzQf3BmrPF+44GD3DXFPY4TRvGSG4XRVgqJBZ9oS9/fNNaJE0du9R3 Wm05ez4RrnAJh1VT0obyo5D9i+xQ37hQgA== X-Google-Smtp-Source: AMsMyM5ftgzgy/+k6iUlijd45gmkNnbmFC9I6Pd/cVxwsz6GJcdOa674eSPA5qVGOcURuM533CNhWg== X-Received: by 2002:a05:6638:2046:b0:35a:ce4a:13a2 with SMTP id t6-20020a056638204600b0035ace4a13a2mr9523918jaj.164.1664118200744; Sun, 25 Sep 2022 08:03:20 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id u19-20020a926013000000b002f19d9838c6sm5360578ilb.25.2022.09.25.08.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 08:03:20 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Alper Nebi Yasak , Heiko Thiery , Stefan Herbrechtsmeier Subject: [PATCH 11/45] binman: Split out looking up a symbol into a function Date: Sun, 25 Sep 2022 09:02:14 -0600 Message-Id: <20220925150248.2524421-12-sjg@chromium.org> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220925150248.2524421-1-sjg@chromium.org> References: <20220925150248.2524421-1-sjg@chromium.org> MIME-Version: 1.0 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.6 at phobos.denx.de X-Virus-Status: Clean Move this code into its own function so it can be used from tests. Signed-off-by: Simon Glass --- tools/binman/etype/section.py | 60 ++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 621950893f3..b68c6fd037b 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -510,6 +510,50 @@ class Entry_section(Entry): source_entry.Raise("Cannot find entry for node '%s'" % node.name) return entry.GetData(required) + def LookupEntry(self, entries, sym_name, msg): + """Look up the entry for an ELF symbol + + Args: + entries (dict): entries to search: + key: entry name + value: Entry object + sym_name: Symbol name in the ELF file to look up in the format + _binman__prop_ where is the name of + the entry and is the property to find (e.g. + _binman_u_boot_prop_offset). As a special case, you can append + _any to to have it search for any matching entry. E.g. + _binman_u_boot_any_prop_offset will match entries called u-boot, + u-boot-img and u-boot-nodtb) + msg: Message to display if an error occurs + + Returns: + tuple: + Entry: entry object that was found + str: name used to search for entries (uses '-' instead of the + '_' used by the symbol name) + str: property name the symbol refers to, e.g. 'image_pos' + + Raises: + ValueError:the symbol name cannot be decoded, e.g. does not have + a '_binman_' prefix + """ + m = re.match(r'^_binman_(\w+)_prop_(\w+)$', sym_name) + if not m: + raise ValueError("%s: Symbol '%s' has invalid format" % + (msg, sym_name)) + entry_name, prop_name = m.groups() + entry_name = entry_name.replace('_', '-') + entry = entries.get(entry_name) + if not entry: + if entry_name.endswith('-any'): + root = entry_name[:-4] + for name in entries: + if name.startswith(root): + rest = name[len(root):] + if rest in ['', '-img', '-nodtb']: + entry = entries[name] + return entry, entry_name, prop_name + def LookupSymbol(self, sym_name, optional, msg, base_addr, entries=None): """Look up a symbol in an ELF file @@ -547,23 +591,9 @@ class Entry_section(Entry): ValueError if the symbol is invalid or not found, or references a property which is not supported """ - m = re.match(r'^_binman_(\w+)_prop_(\w+)$', sym_name) - if not m: - raise ValueError("%s: Symbol '%s' has invalid format" % - (msg, sym_name)) - entry_name, prop_name = m.groups() - entry_name = entry_name.replace('_', '-') if not entries: entries = self._entries - entry = entries.get(entry_name) - if not entry: - if entry_name.endswith('-any'): - root = entry_name[:-4] - for name in entries: - if name.startswith(root): - rest = name[len(root):] - if rest in ['', '-img', '-nodtb']: - entry = entries[name] + entry, entry_name, prop_name = self.LookupEntry(entries, sym_name, msg) if not entry: err = ("%s: Entry '%s' not found in list (%s)" % (msg, entry_name, ','.join(entries.keys())))