Commit Graph

19 Commits

Author SHA1 Message Date
Simon Glass
9aa0a53db6 fit: Use the libfdt subnode iterator
Replace fdt_next_node() with depth tracking with fdt_for_each_subnode()
which has been available for some time.

This also fixes a latent bug where the default configuration was being
read from the wrong node offset. It happened to work before because
noffset ended up at the right value after the images loop.

Series-to: concept
Series-cc: heinrich
Cover-letter:
fit: Improve and test the code to print FIT info
The code for printing information about FITs is fairly old and not that
easy to maintain. It also lacks tests.

This series adds some tests, moves the code into its own file and then
adds a series of helpers to deal with the intricacies of printing each
item.

This provides a binary-size reduction of about 320 bytes on aarch64.
END

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
a1429a036a fit: Add a helper to iterate through hash/signature nodes
The pattern for iterating through and processing hash/signature subnodes
is repeated in two places. Add a new process_subnodes() helper to reduce
code duplication.

Drop the now-unused ndepth and noffset local variables.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
b6674168b9 fit: Use a boolean to simplify type checks
Add a boolean variable 'loadable' that combines the common type check
for kernel, standalone, and ramdisk images.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
8f5e311f3b fit: Add a helper for address printing
Add emit_addr() to handle printing load an entry addresses.

The helper takes a 'valid' boolean parameter to determine whether to
print the address value or 'unavailable'.

Combine the two separate if() blocks for the load address.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
47953a00bb fit: Add a helper for printing descriptions
Add emit_desc() which handles getting and printing descriptions from FIT
nodes. Handle the "unavailable" case when a description is missing.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
0d5a23344d fit: Add a helper for stringlist properties
Add a emit_stringlist() helper function to simplify printing stringlist
properties in FIT configurations.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
b0a3ebd1fd fit: Add a helper for timestamp printing
Add a new emit_timestamp() helper function to handle printing timestamps
in FITs.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
79388f8fe8 fit: Add a helper to output optional properties
Add a new emit_prop() helper function to simplify printing optional
properties in FIT configurations.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
6329055745 fit: Use emit_label_val() where possible
Refactor the printing of multi-line properties to use the
emit_label_val() helper function instead of custom formatting.

Update emit_label() to deal with an empty label and not show a colon in
that case.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
819ef32f87 fit: Move values one column to the right
Line up the values witht the FIT Description and Created items at the
top. This looks a little nicer.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
192c586a5d fit: Change indent from string to int
Change the indent field in fit_print_ctx from a string pointer to an int
number of spaces to indent.

Set the initial indent value to 3 to match IMAGE_INDENT_STRING

Drop indentation from the debug() calls since these are not visible to
users.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
e18f514654 fit: Add a a function to print labels with values
Add a new emit_label_val() helper function that combines emit_label()
and printf() for simple label-value pairs.

Make use of it where appropriate.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
4669924871 fit: Use emit_label() helper in fit_conf_print()
Update fit_conf_print() to use the emit_label() helper function for
printing labels.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:46 -07:00
Simon Glass
9515fa96e6 fit: Use emit_label() helper in fit_image_print()
Update fit_image_print() to use the emit_label() helper function for
printing labels. This avoids various manual printf() calls and spacing
logic.

Set ctx->tab to 19 to align values at the correct column position.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:51:45 -07:00
Simon Glass
9b875f54ef fit: Create some helpers for printing
The current code is quite fiddly with manually spaced labels. Add helper
functions for printing labels (with or without a type prefix) with a
cofigurable tab width for the value that folows.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:50:10 -07:00
Simon Glass
62a4c7e10a fit: Put the indent string into print context
Move the indent string into struct fit_print_ctx so it is available to
the printing functions. This avoids having to pass it as a separate
parameter.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:50:10 -07:00
Simon Glass
6b6f03c388 fit: Add a context struct for FIT-printing
Create a struct fit_print_ctx to hold the FIT pointer and pass it to all
printing functions instead of passing the FIT pointer directly. This
provides a foundation for adding additional context in the future.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:50:10 -07:00
Simon Glass
5cb5809acd fit: Drop showing an unused 'required' property
This is actually not defined by the spec. The 'required' property is for
use by the verifying code. Having it in the FIT does not help size an
attacker could potentially remove it.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:50:10 -07:00
Simon Glass
0b51f99bf0 fit: Move printing code to its own file
There is enough code here that it makes sense to put it in its own file.
Create a new fit_print.c file, before undertaking future refactoring.

Printing is only included in the main build if CONFIG_FIT_PRINT is
enabled, although it is always included in the tools build.

Add static inlines for existing callers.

Make a few small code-style adjustments, including fixing checkpatch
warnings about over-use of brackets.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-19 19:50:09 -07:00