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 BA4D4C4332F for ; Thu, 13 Oct 2022 12:31:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7717C84F68; Thu, 13 Oct 2022 14:30:53 +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="cRqk6Ofs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 272D684F4A; Thu, 13 Oct 2022 14:30:26 +0200 (CEST) Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) (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 C307384F37 for ; Thu, 13 Oct 2022 14:30:16 +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-x133.google.com with SMTP id o13so853117ilc.7 for ; Thu, 13 Oct 2022 05:30:16 -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 :message-id:reply-to; bh=bocrXlTCcpASSaMnfi741104ppw5vsWo37PFH8x7KNc=; b=cRqk6OfsTxPvlIKGERkzfiOWq/iqHFfhDNQzummctnjLh7V8qwfLkinq0bk/KuK/p/ 4qgchKVdbrQLjwxkPJurm/9ej/2kyNNrs3e5L6Odk41202sxFE40R7JSLkCubKpZfxYF BMfrO4Zc8rUDiCDGlxP1FQf4JlfPKbhXjGkXQ= 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:message-id:reply-to; bh=bocrXlTCcpASSaMnfi741104ppw5vsWo37PFH8x7KNc=; b=SGheU5NyE9+oQkXElvi8R9WzMDwV53p6SDFi0ZnOsnB36SEmjhuBVgUPrYnBzoFZBV Fh/L9IqNfDnYeeJrDQWYbpszm2IYwKYztqs5KFhH1KvlShtuUG1Us91whaA9x5efxEmi w8IV6lrbPo+TuwkYgk7riDAONDWACTHqDG35yYzNT9QEJgs5uZtD8yZpZuattOOdqx8l W7kHng7X13b5WVeJ5Apb5u7r4uLHycJ3awu/v1qOx+VyHIUrTnGFlryRFcYp+0mec6Sq h85ErbTpvnKxHQ8R4c6vSalSS+JLgM+4vWb/mAACJSZuHKZRIlpp90FJkMFRToBEtZ4l vGyw== X-Gm-Message-State: ACrzQf3tnTpDUX9IRYjb6qnWRExKNcxUubRyX0P0EStDjnwaw3Z7aq2x kzozalw3Sb43Gl9aE7xK93J4cYxZUKB+OA== X-Google-Smtp-Source: AMsMyM7kdgt/N9j/IrqK9J89zu+5gsNzCnSnuYFJiMSLag/sSWWf8NTl001IiFikl71sAdpEAm76dg== X-Received: by 2002:a05:6e02:180e:b0:2fc:6e7e:e491 with SMTP id a14-20020a056e02180e00b002fc6e7ee491mr8230156ilv.139.1665664215949; Thu, 13 Oct 2022 05:30:15 -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 a9-20020a027a09000000b003635ab4a7b7sm7321626jac.3.2022.10.13.05.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 05:30:15 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Alper Nebi Yasak , Heiko Thiery , Stefan Herbrechtsmeier Subject: [PATCH v2 09/45] binman: Split out looking up a symbol into a function Date: Thu, 13 Oct 2022 06:28:51 -0600 Message-Id: <20221013122927.636867-10-sjg@chromium.org> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog In-Reply-To: <20221013122927.636867-1-sjg@chromium.org> References: <20221013122927.636867-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.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 --- (no changes since v1) 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..f7ef5f89837 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 ENF 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()))) -- 2.38.0.rc1.362.ged0d419d3c-goog