From patchwork Tue Feb 8 18:50:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1590047 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=C1UteXU+; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JtXG33Tnkz9s0B for ; Wed, 9 Feb 2022 05:53:15 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6138B83DF6; Tue, 8 Feb 2022 19:51:13 +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="C1UteXU+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 649FD83DCC; Tue, 8 Feb 2022 19:50:51 +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.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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 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 92ABC83DA9 for ; Tue, 8 Feb 2022 19:50:42 +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-il1-x12d.google.com with SMTP id o10so14823709ilh.0 for ; Tue, 08 Feb 2022 10:50:42 -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=nB7CS1GC1S+FoS1ihIKEXCs8n0MormBXdSlrnJs38vY=; b=C1UteXU+v6G8Ts34ewWL9vcEuVTvdHivqOA6y86fTrBXPJTOrVpiJkAMsb0WVu49Bm ndo+iiuRjX+ngOGozKrEV0kR+QI/9Vw8Z0Ebw0oFBgQo/4rMYfMhzx1UJ6l1xaa8o+1J WLeRpWwFstiuCHOYoWEqBoDKifqfctZKE+n0U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nB7CS1GC1S+FoS1ihIKEXCs8n0MormBXdSlrnJs38vY=; b=oP43c0EHr8ykgC4i+73smvE7+Idtl49cXZeH2dPJa+jGnlb8oVanWl1n1X4T9GkzrW sY1LDim1639oEuRuW/x9UPYxl/RsqGYMN8reKni0afNXUvhMlmNlJu+noZjXctVKp1vF V1NktkB2oRhhf1B0HQPfW+zJKNDx9oQZ2DjQNRfpVNJF2b2YBSA//HJe35qJjypb1FoM zGZeGhNnnTMQU3Kfi0KXEPTe9Qlae+uWYb6cvo/9ZMyGjZZQu7V9B6cBEKkD4bYO+fc+ 8kXTVWVxRrz3ZuS4m2GxQRR9Qi6wFuEH2Pbdj4ESKTUaSpIijuR811Uv/6kf9hw0ucBS OVrQ== X-Gm-Message-State: AOAM531eK7A3HEtQePA2GZDxVNYmFzRSfCKRpV1R6s9dzn1WJmRugXwV pT4wAAOJyiRWITRktWpH2HcFjIfUjbQJuQ== X-Google-Smtp-Source: ABdhPJy+baL4tr7IEuUWtzZDONBZPjQFVrrlNmy3ZqNQHDDchYScVG9klQdk+BsI/qBAc2nN7LArpg== X-Received: by 2002:a05:6e02:1c06:: with SMTP id l6mr2980892ilh.48.1644346241101; Tue, 08 Feb 2022 10:50:41 -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 q2sm2911844ilt.33.2022.02.08.10.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 10:50:40 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: huang lin , Jeffy Chen , Simon Glass , Kever Yang , Philipp Tomsich , Alper Nebi Yasak , Tom Rini , Roger Quadros , Philippe Reynes , Ivan Mikhaylov , Jan Kiszka Subject: [PATCH 17/24] binman: fit: Refactor to reduce function size Date: Tue, 8 Feb 2022 11:50:01 -0700 Message-Id: <20220208114935.17.If9396449efcf221fff4e68e48264faf22b0ffc66@changeid> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208185008.35843-1-sjg@chromium.org> References: <20220208185008.35843-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.5 at phobos.denx.de X-Virus-Status: Clean Split subnode and property processing into separate functions to make the _AddNode() function a little smaller. Tweak a few comments. This does not change any functionality. Signed-off-by: Simon Glass --- tools/binman/etype/fit.py | 116 ++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 43 deletions(-) diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py index 6ad4a686df..b159844960 100644 --- a/tools/binman/etype/fit.py +++ b/tools/binman/etype/fit.py @@ -141,12 +141,82 @@ class Entry_fit(Entry): super().ReadNode() def ReadEntries(self): + def _process_prop(pname, prop): + """Process special properties + + Handles properties with generated values. At present the only + supported property is 'default', i.e. the default device tree in + the configurations node. + + Args: + pname (str): Name of property + prop (Prop): Property to process + """ + if pname == 'default': + val = prop.value + # Handle the 'default' property + if val.startswith('@'): + if not self._fdts: + return + if not self._fit_default_dt: + self.Raise("Generated 'default' node requires default-dt entry argument") + if self._fit_default_dt not in self._fdts: + self.Raise("default-dt entry argument '%s' not found in fdt list: %s" % + (self._fit_default_dt, + ', '.join(self._fdts))) + seq = self._fdts.index(self._fit_default_dt) + val = val[1:].replace('DEFAULT-SEQ', str(seq + 1)) + fsw.property_string(pname, val) + return + fsw.property(pname, prop.bytes) + + def _generate_node(subnode, depth, in_images): + """Generate nodes from a template + + This creates one node for each member of self._fdts using the + provided template. If a property value contains 'NAME' it is + replaced with the filename of the FDT. If a property value contains + SEQ it is replaced with the node sequence number, where 1 is the + first. + + Args: + subnode (None): Generator node to process + depth: Current node depth (0 is the base 'fit' node) + in_images: True if this is inside the 'images' node, so that + 'data' properties should be generated + """ + if self._fdts: + # Generate nodes for each FDT + for seq, fdt_fname in enumerate(self._fdts): + node_name = subnode.name[1:].replace('SEQ', + str(seq + 1)) + fname = tools.GetInputFilename(fdt_fname + '.dtb') + with fsw.add_node(node_name): + for pname, prop in subnode.props.items(): + val = prop.bytes.replace( + b'NAME', tools.ToBytes(fdt_fname)) + val = val.replace( + b'SEQ', tools.ToBytes(str(seq + 1))) + fsw.property(pname, val) + + # Add data for 'images' nodes (but not 'config') + if depth == 1 and in_images: + fsw.property('data', + tools.ReadFile(fname)) + else: + if self._fdts is None: + if self._fit_list_prop: + self.Raise("Generator node requires '%s' entry argument" % + self._fit_list_prop.value) + else: + self.Raise("Generator node requires 'fit,fdt-list' property") + def _AddNode(base_node, depth, node): """Add a node to the FIT Args: base_node: Base Node of the FIT (with 'description' property) - depth: Current node depth (0 is the base node) + depth: Current node depth (0 is the base 'fit' node) node: Current node to process There are two cases to deal with: @@ -156,23 +226,7 @@ class Entry_fit(Entry): """ for pname, prop in node.props.items(): if not pname.startswith('fit,'): - if pname == 'default': - val = prop.value - # Handle the 'default' property - if val.startswith('@'): - if not self._fdts: - continue - if not self._fit_default_dt: - self.Raise("Generated 'default' node requires default-dt entry argument") - if self._fit_default_dt not in self._fdts: - self.Raise("default-dt entry argument '%s' not found in fdt list: %s" % - (self._fit_default_dt, - ', '.join(self._fdts))) - seq = self._fdts.index(self._fit_default_dt) - val = val[1:].replace('DEFAULT-SEQ', str(seq + 1)) - fsw.property_string(pname, val) - continue - fsw.property(pname, prop.bytes) + _process_prop(pname, prop) rel_path = node.path[len(base_node.path):] in_images = rel_path.startswith('/images') @@ -195,31 +249,7 @@ class Entry_fit(Entry): # fsw.add_node() or _AddNode() for it. pass elif self.GetImage().generate and subnode.name.startswith('@'): - if self._fdts: - # Generate notes for each FDT - for seq, fdt_fname in enumerate(self._fdts): - node_name = subnode.name[1:].replace('SEQ', - str(seq + 1)) - fname = tools.GetInputFilename(fdt_fname + '.dtb') - with fsw.add_node(node_name): - for pname, prop in subnode.props.items(): - val = prop.bytes.replace( - b'NAME', tools.ToBytes(fdt_fname)) - val = val.replace( - b'SEQ', tools.ToBytes(str(seq + 1))) - fsw.property(pname, val) - - # Add data for 'fdt' nodes (but not 'config') - if depth == 1 and in_images: - fsw.property('data', - tools.ReadFile(fname)) - else: - if self._fdts is None: - if self._fit_list_prop: - self.Raise("Generator node requires '%s' entry argument" % - self._fit_list_prop.value) - else: - self.Raise("Generator node requires 'fit,fdt-list' property") + _generate_node(subnode, depth, in_images) else: with fsw.add_node(subnode.name): _AddNode(base_node, depth + 1, subnode)