From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
To: Simon Glass <sjg@chromium.org>
Cc: Ivan Mikhaylov <ivan.mikhaylov@siemens.com>,
Tom Rini <trini@konsulko.com>,
Philippe Reynes <philippe.reynes@softathome.com>,
huang lin <hl@rock-chips.com>,
Jeffy Chen <jeffy.chen@rock-chips.com>,
Kever Yang <kever.yang@rock-chips.com>,
U-Boot Mailing List <u-boot@lists.denx.de>
Subject: Re: [PATCH v2 10/25] binman: Refactor fit to generate output at the end
Date: Fri, 4 Mar 2022 00:09:12 +0300 [thread overview]
Message-ID: <2e029792-0786-502c-273e-b92b67e95ea2@gmail.com> (raw)
In-Reply-To: <20220223230040.159317-11-sjg@chromium.org>
On 24/02/2022 02:00, Simon Glass wrote:
> At present the fit implementation creates the output tree while
> scanning the FIT description. Then it updates the tree later when the
> data is known.
>
> This works, but is a bit confusing, since it requires mixing the scanning
> code with the generation code, with a fix-up step at the end.
>
> It is actually possible to do this in two phases, one to scan everything
> and the other to generate the FIT. Thus the FIT is generated in one pass,
> when everything is known.
Doing it in one go makes sense to me as well. In general I like the way
distinct processing actions/steps are being split into their own blocks
or so, and I think this helps move things toward that.
> Update the code accordingly. The only functional change is that the 'data'
> property for each node are now last instead of first, which is really a
> more natural position. Update the affected test to deal with this.
>
> One wrinkle is that the calculated properties (image-pos, size and offset)
> are now added before the FIT is generated. so we must filter these out
> when copying properties from the binman description to the FIT.
>
> Most of the change here is splitting out some of the code from the
> ReadEntries() implementation into _BuildInput(). So despite the large
> diff, most of the code is the same. It is not feasible to split this patch
> up, so far as I can tell.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v2:
> - Add new patch to refactor fit to generate output at the end
>
> tools/binman/etype/fit.py | 178 ++++++++++++++-----------
> tools/binman/ftest.py | 13 +-
> tools/binman/test/224_fit_bad_oper.dts | 2 -
> 3 files changed, 109 insertions(+), 84 deletions(-)
Reviewed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
I still wrote some weird ideas below, mostly for the future, since this
patch is mostly moving code around which is fine as is.
> diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
> index 2d4c5f6545..61c72780e9 100644
> --- a/tools/binman/etype/fit.py
> +++ b/tools/binman/etype/fit.py
> @@ -209,6 +209,81 @@ class Entry_fit(Entry_section):
> return oper
>
> def ReadEntries(self):
> + def _add_entries(base_node, depth, node):
> + """Add entries for any nodes that need them
> +
> + Args:
> + base_node: Base Node of the FIT (with 'description' property)
> + depth: Current node depth (0 is the base 'fit' node)
> + node: Current node to process
> +
> + He we only need to provide binman entries which are used to define
He -> Here ?
> + the 'data' for each image. We create an entry_Section for each.
> + """
> + rel_path = node.path[len(base_node.path):]
> + in_images = rel_path.startswith('/images')
> + has_images = depth == 2 and in_images
> + if has_images:
> + # This node is a FIT subimage node (e.g. "/images/kernel")
> + # containing content nodes. We collect the subimage nodes and
> + # section entries for them here to merge the content subnodes
> + # together and put the merged contents in the subimage node's
> + # 'data' property later.
> + entry = Entry.Create(self.section, node, etype='section')
> + entry.ReadNode()
I plan to change 'self.section' to 'self' here later, fixes extracting
wrong contents for FIT subentries.
> + # The hash subnodes here are for mkimage, not binman.
> + entry.SetUpdateHash(False)
> + self._entries[rel_path] = entry
> +
I also plan to change this to a single-level node name instead of the
relative path, lets 'binman extract fit/u-boot' etc. run at all.
> + for subnode in node.subnodes:
> + _add_entries(base_node, depth + 1, subnode)
> +
> + _add_entries(self._node, 0, self._node)
I think it's especially visible here what I meant by switching away from
recursion: this recurses through every node but only does anything on
immediate subnodes of "/images" (for now?).
> +
> + def BuildSectionData(self, required):
> + """Build FIT entry contents
> +
> + This adds the 'data' properties to the input ITB (Image-tree Binary)
> + then runs mkimage to process it.
> +
> + Args:
> + required: True if the data must be present, False if it is OK to
> + return None
I forgot to handle 'required' while converting FIT to section...
> +
> + Returns:
> + Contents of the section (bytes)
> + """
> + data = self._BuildInput()
> + uniq = self.GetUniqueName()
> + input_fname = tools.get_output_filename('%s.itb' % uniq)
> + output_fname = tools.get_output_filename('%s.fit' % uniq)
> + tools.write_file(input_fname, data)
> + tools.write_file(output_fname, data)
> +
> + args = {}
> + ext_offset = self._fit_props.get('fit,external-offset')
> + if ext_offset is not None:
> + args = {
> + 'external': True,
> + 'pad': fdt_util.fdt32_to_cpu(ext_offset.value)
> + }
> + if self.mkimage.run(reset_timestamp=True, output_fname=output_fname,
> + **args) is None:
I have an idea for the far future, to let /image/* nodes sometimes be
Entry_collection to handle external offsets in binman so we can take
mkimage completely out of this, but no clue how feasible/desirable that
end goal is.
> + # Bintool is missing; just use empty data as the output
> + self.record_missing_bintool(self.mkimage)
> + return tools.get_bytes(0, 1024)
> +
> + return tools.read_file(output_fname)
> +
> + def _BuildInput(self):
> + """Finish the FIT by adding the 'data' properties to it
> +
> + Arguments:
> + fdt: FIT to update
> +
> + Returns:
> + New fdt contents (bytes)
> + """
> def _process_prop(pname, prop):
> """Process special properties
>
> @@ -236,9 +311,15 @@ class Entry_fit(Entry_section):
> val = val[1:].replace('DEFAULT-SEQ', str(seq + 1))
> fsw.property_string(pname, val)
> return
> + elif pname.startswith('fit,'):
> + # Ignore these, which are commands for binman to process
> + return
> + elif pname in ['offset', 'size', 'image-pos']:
> + # Don't add binman's calculated properties
> + return
This is one of the things I was thinking of doing, thanks. I encountered
the same issue when replacing a FIT entry with the same f"{uniq}.fit"
that was used to build it, will try adding a test for that later.
> fsw.property(pname, prop.bytes)
>
> - def _scan_gen_fdt_nodes(subnode, depth, in_images):
> + def _gen_fdt_nodes(subnode, depth, in_images):
> """Generate FDT nodes
>
> This creates one node for each member of self._fdts using the
> [...]
>
> diff --git a/tools/binman/test/224_fit_bad_oper.dts b/tools/binman/test/224_fit_bad_oper.dts
> index cee801e2ea..8a8014ea33 100644
> --- a/tools/binman/test/224_fit_bad_oper.dts
> +++ b/tools/binman/test/224_fit_bad_oper.dts
> @@ -21,7 +21,5 @@
> };
> };
> };
> - fdtmap {
> - };
This looked unrelated at first, but as I understand it, changing the
order of things made the bad-operation error happen later and exposed a
breakage from the fdtmap entry trying to parse the mock dtb data.
> };
> };
next prev parent reply other threads:[~2022-03-03 21:17 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 23:00 [PATCH v2 00/25] binman: rockchip: Migrate from rockchip SPL_FIT_GENERATOR script Simon Glass
2022-02-23 23:00 ` [PATCH v2 01/25] dtoc: Make GetArgs() more flexible Simon Glass
2022-03-03 21:07 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 02/25] moveconfig: Remove remove_defconfig() Simon Glass
2022-03-03 21:07 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 03/25] moveconfig: Use re.fullmatch() to avoid extra check Simon Glass
2022-03-03 21:07 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 04/25] spl: Correct Kconfig help for TPL_BINMAN_SYMBOLS Simon Glass
2022-03-03 21:08 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 05/25] dtoc: Tidy up implementation of AddStringList() Simon Glass
2022-03-03 21:08 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 06/25] elf: Rename load_segments() and module failure Simon Glass
2022-03-03 21:08 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 07/25] binman: Tweak collect_contents_to_file() and docs Simon Glass
2022-03-03 21:08 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 08/25] binman: Rename ExpandToLimit to extend_to_limit Simon Glass
2022-03-03 21:08 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 09/25] binman: Rename ExpandEntries to gen_entries Simon Glass
2022-03-03 21:09 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 10/25] binman: Refactor fit to generate output at the end Simon Glass
2022-03-03 21:09 ` Alper Nebi Yasak [this message]
2022-03-06 3:08 ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 11/25] binman: Rename tools parameter to btools Simon Glass
2022-03-03 21:09 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 12/25] binman: Change how faked blobs are created Simon Glass
2022-03-03 21:09 ` Alper Nebi Yasak
2022-03-06 3:08 ` Simon Glass
2022-03-10 19:29 ` Alper Nebi Yasak
2022-03-12 5:02 ` Simon Glass
2022-03-14 21:29 ` Alper Nebi Yasak
2022-03-14 22:20 ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 13/25] binman: Make fake blobs zero-sized by default Simon Glass
2022-03-03 21:09 ` Alper Nebi Yasak
2022-03-06 3:08 ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 14/25] binman: Allow mkimage to use a non-zero fake-blob size Simon Glass
2022-03-03 21:09 ` Alper Nebi Yasak
2022-03-06 3:08 ` Simon Glass
2022-03-10 19:30 ` Alper Nebi Yasak
2022-03-12 5:02 ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 15/25] binman: Read the fit entries only once Simon Glass
2022-03-03 21:10 ` Alper Nebi Yasak
2022-03-06 3:08 ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 16/25] binman: Fix some pylint warnings in fit Simon Glass
2022-03-03 21:10 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 17/25] binman: Add a consistent way to report errors with fit Simon Glass
2022-03-03 21:10 ` Alper Nebi Yasak
2022-03-06 3:08 ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 18/25] binman: Update fit to use node instead of subnode Simon Glass
2022-03-03 21:10 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 19/25] binman: Keep a separate list of entries for fit Simon Glass
2022-03-03 21:10 ` Alper Nebi Yasak
2022-03-06 3:08 ` Simon Glass
2022-03-10 19:30 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 20/25] binman: Support splitting an ELF file into multiple nodes Simon Glass
2022-03-03 21:10 ` Alper Nebi Yasak
2022-03-06 3:08 ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 21/25] rockchip: evb-rk3288: Drop raw-image support Simon Glass
2022-02-23 23:00 ` [PATCH v2 22/25] rockchip: Include binman script in 64-bit boards Simon Glass
2022-03-03 21:10 ` Alper Nebi Yasak
2022-02-23 23:00 ` [PATCH v2 23/25] rockchip: Support building the all output files in binman Simon Glass
2022-03-02 22:16 ` Peter Geis
2022-03-03 21:11 ` Alper Nebi Yasak
2022-03-03 22:34 ` Peter Geis
2022-03-06 3:08 ` Simon Glass
2022-02-23 23:00 ` [PATCH v2 24/25] rockchip: Convert all boards to use binman Simon Glass
2022-02-23 23:00 ` [PATCH v2 25/25] rockchip: Drop the FIT generator script Simon Glass
2022-03-01 2:48 ` [RFC] [PATCH] binman: support mkimage split files Peter Geis
2022-03-03 21:11 ` Alper Nebi Yasak
2022-03-04 17:47 ` Peter Geis
2022-03-04 19:56 ` [PATCH v2] binman: support mkimage separate files Peter Geis
2022-03-06 3:08 ` Simon Glass
2022-03-06 14:44 ` Peter Geis
2022-03-10 19:29 ` Alper Nebi Yasak
2022-03-10 23:19 ` Peter Geis
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=2e029792-0786-502c-273e-b92b67e95ea2@gmail.com \
--to=alpernebiyasak@gmail.com \
--cc=hl@rock-chips.com \
--cc=ivan.mikhaylov@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