public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
To: Simon Glass <sjg@chromium.org>,
	U-Boot Mailing List <u-boot@lists.denx.de>
Cc: huang lin <hl@rock-chips.com>,
	Jeffy Chen <jeffy.chen@rock-chips.com>,
	Kever Yang <kever.yang@rock-chips.com>,
	Tom Rini <trini@konsulko.com>,
	Philippe Reynes <philippe.reynes@softathome.com>,
	Ivan Mikhaylov <ivan.mikhaylov@siemens.com>,
	Jan Kiszka <jan.kiszka@siemens.com>
Subject: Re: [PATCH 17/24] binman: fit: Refactor to reduce function size
Date: Tue, 15 Feb 2022 14:45:59 +0300	[thread overview]
Message-ID: <25cb670b-523d-0db9-cf26-a9f29ae664fc@gmail.com> (raw)
In-Reply-To: <20220208114935.17.If9396449efcf221fff4e68e48264faf22b0ffc66@changeid>

On 08/02/2022 21:50, Simon Glass wrote:
> 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 <sjg@chromium.org>
> ---

I know this just moves code around a bit, but I think the code here
could be cleaned up much further with a bit of redesign. I'm not sure of
the details, but was thinking of at least:

- self._add_fit_image() to handle image/* subnodes
- self._add_fit_config() to handle configuration/* subnodes
- self._gen_fdt_nodes() to handle template nodes by calling the above
- Switching away from recursion to iterating subnodes of fixed nodes

> 
>  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):

I think the following functions could be moved out of this one into the
class scope, even including _AddNode.

> +        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)

  reply	other threads:[~2022-02-15 11:54 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-08 18:49 [PATCH 00/24] binman: rockchip: Migrate from rockchip SPL_FIT_GENERATOR script Simon Glass
2022-02-08 18:49 ` [PATCH 01/24] moveconfig: Show the config name rather than the defconfig Simon Glass
2022-02-15 11:40   ` Alper Nebi Yasak
2022-02-23  2:35     ` Simon Glass
2022-02-23  2:43       ` Simon Glass
2022-02-08 18:49 ` [PATCH 02/24] moveconfig: Allow regex matches when finding combinations Simon Glass
2022-02-15 11:41   ` Alper Nebi Yasak
2022-02-23  2:35     ` Simon Glass
2022-02-08 18:49 ` [PATCH 03/24] spl: x86: Correct the binman symbols for SPL Simon Glass
2022-02-15 11:42   ` Alper Nebi Yasak
2022-02-23  2:35     ` Simon Glass
2022-02-23 22:58     ` Simon Glass
2022-03-03 21:06       ` Alper Nebi Yasak
2022-03-06  3:07         ` Simon Glass
2022-02-08 18:49 ` [PATCH 04/24] spl: Allow disabling binman symbols in SPL Simon Glass
2022-02-15 11:42   ` Alper Nebi Yasak
2022-02-23  2:35     ` Simon Glass
2022-02-08 18:49 ` [PATCH 05/24] rockchip: evb-rk3288: Drop raw-image support Simon Glass
2022-02-08 18:49 ` [PATCH 06/24] dtoc: Support adding a string list to a device tree Simon Glass
2022-02-15 11:43   ` Alper Nebi Yasak
2022-02-23  2:35     ` Simon Glass
2022-02-23 22:58     ` Simon Glass
2022-03-03 21:07       ` Alper Nebi Yasak
2022-03-06  3:07         ` Simon Glass
2022-02-08 18:49 ` [PATCH 07/24] dtoc: Support deleting a node Simon Glass
2022-02-08 18:49 ` [PATCH 08/24] dtoc: Allow deleting nodes and adding them in the same sync Simon Glass
2022-02-08 18:49 ` [PATCH 09/24] dtoc: Support reading a list of arguments Simon Glass
2022-02-15 11:43   ` Alper Nebi Yasak
2022-02-23  2:35     ` Simon Glass
2022-02-23 22:58     ` Simon Glass
2022-03-03 21:07       ` Alper Nebi Yasak
2022-02-08 18:49 ` [PATCH 10/24] binman: Update docs to indicate mkimage is supported Simon Glass
2022-02-23  2:35   ` Simon Glass
2022-02-08 18:49 ` [PATCH 11/24] elf: Add a way to read segment information from an ELF file Simon Glass
2022-02-15 11:44   ` Alper Nebi Yasak
2022-02-23  2:35     ` Simon Glass
2022-02-23 22:58     ` Simon Glass
2022-02-08 18:49 ` [PATCH 12/24] WIP: binman: Add support for OP-TEE Simon Glass
2022-02-08 18:49 ` [PATCH 13/24] binman: Add to the TODO Simon Glass
2022-02-08 18:49 ` [PATCH 14/24] binman: Support a list of strings with the mkimage etype Simon Glass
2022-02-15 11:45   ` Alper Nebi Yasak
2022-02-23  2:34     ` Simon Glass
2022-02-23 22:59     ` Simon Glass
2022-02-08 18:49 ` [PATCH 15/24] binman: Add a ELF test file with disjoint text sections Simon Glass
2022-02-08 18:50 ` [PATCH 16/24] binman: Move entry-data collection into a Entry method Simon Glass
2022-02-15 11:45   ` Alper Nebi Yasak
2022-02-23  2:34     ` Simon Glass
2022-02-08 18:50 ` [PATCH 17/24] binman: fit: Refactor to reduce function size Simon Glass
2022-02-15 11:45   ` Alper Nebi Yasak [this message]
2022-02-23  2:34     ` Simon Glass
2022-02-23 22:59     ` Simon Glass
2022-02-08 18:50 ` [PATCH 18/24] binman: Tidy up the docs a little with fit Simon Glass
2022-02-08 18:50 ` [PATCH 19/24] binman: Allow different operations in FIT generator nodes Simon Glass
2022-02-23  2:34   ` Simon Glass
2022-02-08 18:50 ` [PATCH 20/24] binman: Support splitting an ELF file into multiple nodes Simon Glass
2022-02-15 11:46   ` Alper Nebi Yasak
2022-02-23 22:59     ` Simon Glass
2022-03-03 21:07       ` Alper Nebi Yasak
2022-03-06  3:07         ` Simon Glass
2022-02-08 18:50 ` [PATCH 21/24] rockchip: Include binman script in 64-bit boards Simon Glass
2022-02-08 18:50 ` [PATCH 22/24] rockchip: Support building the all output files in binman Simon Glass
2022-02-10 15:03   ` Peter Geis
2022-02-10 18:57     ` Simon Glass
2022-02-10 19:32       ` Peter Geis
2022-02-14  1:28         ` Peter Geis
2022-02-15 11:48   ` Alper Nebi Yasak
2022-02-08 18:50 ` [PATCH 23/24] rockchip: Convert all boards to use binman Simon Glass
2022-02-08 18:50 ` [PATCH 24/24] rockchip: Drop the FIT generator script Simon Glass
2022-02-11 15:22 ` [PATCH 00/24] binman: rockchip: Migrate from rockchip SPL_FIT_GENERATOR script Alper Nebi Yasak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25cb670b-523d-0db9-cf26-a9f29ae664fc@gmail.com \
    --to=alpernebiyasak@gmail.com \
    --cc=hl@rock-chips.com \
    --cc=ivan.mikhaylov@siemens.com \
    --cc=jan.kiszka@siemens.com \
    --cc=jeffy.chen@rock-chips.com \
    --cc=kever.yang@rock-chips.com \
    --cc=philippe.reynes@softathome.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox