From patchwork Sun Mar 7 19:31:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1448734 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: 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=BxovAqZ4; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dts8s4rtPz9sW5 for ; Mon, 8 Mar 2021 06:33:49 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1830F8284D; Sun, 7 Mar 2021 20:32:26 +0100 (CET) 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="BxovAqZ4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A03FD827E1; Sun, 7 Mar 2021 20:32:07 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) (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 E82BC82797 for ; Sun, 7 Mar 2021 20:32:00 +0100 (CET) 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-oi1-x233.google.com with SMTP id w195so2116146oif.11 for ; Sun, 07 Mar 2021 11:32:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cDmXQU0LpHGrmh8wWjQUQFSZFcoVPVP5tZL+8svizqc=; b=BxovAqZ48IRN85YkV6aKyEJABi/+0vGHMA0eRa2SOuBD1KWPEhS7artncxe9V8lJc5 O+RuZWdDakUP1+VvzdFzB8dXsYIEBsKaN3ClRJ6Bm3qYQVH4bvkNFS9Au0ZLaofFlUAU oJ5DTOMYyAAMFq1zqsXTXLLY1Gcw7kpeDkMJM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cDmXQU0LpHGrmh8wWjQUQFSZFcoVPVP5tZL+8svizqc=; b=AikkZyZOI2veav26zFsoR3cJiSD3l/lTmxvxjvhTkpN61QsgVLLArN43cSnktTKYo4 y8nJmPfxcrFn9dSskBTZF6HvZQIOs+eNs3i8gDJDD8A4NsDHl+1dDHFsfL5ETdUVlCXf 2U+8sbDfs2vsTz89Vyb2Mw45O+Zl7MWQynxnVDNiXo/FpLHEM9T2Lmz5aq7L+2Psw0v6 DGdn/Zs7PpzV0lh1vUgDIITWYh7/M2yEveMKsrPZikb10vnzvWFcxB0P2BMoEKTPTlhe ul8oUpLuL0Np9fTKp3QyEwRFHllOegz3To9xvwWbdbYWUoi0HLG+PeM2P9l6QGaF9tcr zCWQ== X-Gm-Message-State: AOAM53390t4jWOz/PIIGTNDbEyYXf8QW8MvbkYV1/umItZtZUXihAjSK syQlzUUk4ft7FjrSky6WxZ/PNBJKWsKTh9Vp X-Google-Smtp-Source: ABdhPJxClaG1yuu0a+vffnhR1uyX9vhdMqBsY0m/9yaw9O4udKC1zPtUumqE+Xl5A/lnLQj1iLCCjA== X-Received: by 2002:a05:6808:6cc:: with SMTP id m12mr14525947oih.129.1615145519585; Sun, 07 Mar 2021 11:31:59 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id z8sm891074otp.14.2021.03.07.11.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Mar 2021 11:31:59 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass Subject: [PATCH 08/20] binman: Allow using an an 'expanded' entry type Date: Sun, 7 Mar 2021 12:31:35 -0700 Message-Id: <20210307193148.1513733-9-sjg@chromium.org> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog In-Reply-To: <20210307193148.1513733-1-sjg@chromium.org> References: <20210307193148.1513733-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.4 at phobos.denx.de X-Virus-Status: Clean As the first step in supporting expanded entries, add a way for binman to automatically select an 'expanded' version of an entry type, if requested. This is controlled by a class method. Signed-off-by: Simon Glass --- tools/binman/entry.py | 60 ++++++++++++++++++++++++++++++++------ tools/binman/entry_test.py | 12 ++++++++ 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 507760e2a86..1651a38255e 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -102,22 +102,30 @@ class Entry(object): self.allow_missing = False @staticmethod - def Lookup(node_path, etype): + def Lookup(node_path, etype, expanded): """Look up the entry class for a node. Args: node_node: Path name of Node object containing information about the entry to create (used for errors) etype: Entry type to use + expanded: Use the expanded version of etype Returns: - The entry class object if found, else None + The entry class object if found, else None if not found and expanded + is True + + Raise: + ValueError if expanded is False and the class is not found """ # Convert something like 'u-boot@0' to 'u_boot' since we are only # interested in the type. module_name = etype.replace('-', '_') + if '@' in module_name: module_name = module_name.split('@')[0] + if expanded: + module_name += '_expanded' module = modules.get(module_name) # Also allow entry-type modules to be brought in from the etype directory. @@ -127,6 +135,8 @@ class Entry(object): try: module = importlib.import_module('binman.etype.' + module_name) except ImportError as e: + if expanded: + return None raise ValueError("Unknown entry type '%s' in node '%s' (expected etype/%s.py, error '%s'" % (etype, node_path, module_name, e)) modules[module_name] = module @@ -135,21 +145,31 @@ class Entry(object): return getattr(module, 'Entry_%s' % module_name) @staticmethod - def Create(section, node, etype=None): + def Create(section, node, etype=None, expanded=False): """Create a new entry for a node. Args: - section: Section object containing this node - node: Node object containing information about the entry to - create - etype: Entry type to use, or None to work it out (used for tests) + section: Section object containing this node + node: Node object containing information about the entry to + create + etype: Entry type to use, or None to work it out (used for tests) + expanded: True to use expanded versions of entries, where available Returns: A new Entry object of the correct type (a subclass of Entry) """ if not etype: etype = fdt_util.GetString(node, 'type', node.name) - obj = Entry.Lookup(node.path, etype) + obj = Entry.Lookup(node.path, etype, expanded) + if obj and expanded: + # Check whether to use the expanded entry + new_etype = etype + '-expanded' + if obj.UseExpanded(node, etype, new_etype): + etype = new_etype + else: + obj = None + if not obj: + obj = Entry.Lookup(node.path, etype, False) # Call its constructor to get the object we want. return obj(section, etype, node) @@ -648,7 +668,7 @@ features to produce new behaviours. modules.remove('_testing') missing = [] for name in modules: - module = Entry.Lookup('WriteDocs', name) + module = Entry.Lookup('WriteDocs', name, False) docs = getattr(module, '__doc__') if test_missing == name: docs = None @@ -907,3 +927,25 @@ features to produce new behaviours. self.uncomp_size = len(indata) data = tools.Compress(indata, self.compress) return data + + @classmethod + def UseExpanded(cls, node, etype, new_etype): + """Check whether to use an expanded entry type + + This is called by Entry.Create() when it finds an expanded version of + an entry type (e.g. 'u-boot-expanded'). If this method returns True then + it will be used (e.g. in place of 'u-boot'). If it returns False, it is + ignored. + + Args: + node: Node object containing information about the entry to + create + etype: Original entry type being used + new_etype: New entry type proposed + + Returns: + True to use this entry type, False to use the original one + """ + tout.Info("Node '%s': etype '%s': %s selected" % + (node.path, etype, new_etype)) + return True diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py index 80802f33de6..c3d5f3eef48 100644 --- a/tools/binman/entry_test.py +++ b/tools/binman/entry_test.py @@ -87,6 +87,18 @@ class TestEntry(unittest.TestCase): base = entry.Entry.Create(None, self.GetNode(), 'blob-dtb') self.assertIsNone(base.ReadChildData(base)) + def testExpandedEntry(self): + """Test use of an expanded entry when available""" + base = entry.Entry.Create(None, self.GetNode()) + self.assertEqual('u-boot', base.etype) + + expanded = entry.Entry.Create(None, self.GetNode(), expanded=True) + self.assertEqual('u-boot-expanded', expanded.etype) + + with self.assertRaises(ValueError) as e: + entry.Entry.Create(None, self.GetNode(), 'missing', expanded=True) + self.assertIn("Unknown entry type 'missing' in node '/binman/u-boot'", + str(e.exception)) if __name__ == "__main__": unittest.main()