[Concept,22/30] fit: Use emit_label_val() where possible

Message ID 20251120025614.2215587-23-sjg@u-boot.org
State New
Headers
Series fit: Improve and test the code to print FIT info |

Commit Message

Simon Glass Nov. 20, 2025, 2:55 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

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

 boot/fit_print.c | 36 ++++++++----------------------------
 1 file changed, 8 insertions(+), 28 deletions(-)
  

Patch

diff --git a/boot/fit_print.c b/boot/fit_print.c
index e26f2294229..628d6108bea 100644
--- a/boot/fit_print.c
+++ b/boot/fit_print.c
@@ -69,7 +69,7 @@  static void emit_label(struct fit_print_ctx *ctx, const char *label)
 {
 	int len;
 
-	len = printf("%*s%s:", ctx->indent, "", label);
+	len = printf("%*s%s%c", ctx->indent, "", label, *label ? ':' : ' ');
 	printf("%*s", ctx->tab - len, "");
 }
 
@@ -315,7 +315,6 @@  void fit_image_print(struct fit_print_ctx *ctx, int image_noffset)
 static void fit_conf_print(struct fit_print_ctx *ctx, int noffset)
 {
 	const void *fit = ctx->fit;
-	int p = ctx->indent;
 	const char *uname, *desc;
 	int ret, ndepth, i;
 
@@ -338,13 +337,8 @@  static void fit_conf_print(struct fit_print_ctx *ctx, int noffset)
 	for (i = 0;
 	     uname = fdt_stringlist_get(fit, noffset, FIT_FDT_PROP,
 					i, NULL), uname;
-	     i++) {
-		if (!i)
-			emit_label(ctx, "FDT");
-		else
-			printf("%*s               ", p, "");
-		printf("%s\n", uname);
-	}
+	     i++)
+		emit_label_val(ctx, i ? "" : "FDT", uname);
 
 	uname = fdt_getprop(fit, noffset, FIT_FPGA_PROP, NULL);
 	if (uname)
@@ -354,23 +348,13 @@  static void fit_conf_print(struct fit_print_ctx *ctx, int noffset)
 	for (i = 0;
 	     uname = fdt_stringlist_get(fit, noffset, FIT_LOADABLE_PROP,
 					i, NULL), uname;
-	     i++) {
-		if (!i)
-			emit_label(ctx, "Loadables");
-		else
-			printf("%*s               ", p, "");
-		printf("%s\n", uname);
-	}
+	     i++)
+		emit_label_val(ctx, i ? "" : "Loadables", uname);
 
 	/* Show the list of compatible strings */
 	for (i = 0; uname = fdt_stringlist_get(fit, noffset,
-				FIT_COMPATIBLE_PROP, i, NULL), uname; i++) {
-		if (!i)
-			emit_label(ctx, "Compatible");
-		else
-			printf("%*s               ", p, "");
-		printf("%s\n", uname);
-	}
+				FIT_COMPATIBLE_PROP, i, NULL), uname; i++)
+		emit_label_val(ctx, i ? "" : "Compatible", uname);
 
 	/* Process all hash subnodes of the component configuration node */
 	for (ndepth = 0, noffset = fdt_next_node(fit, noffset, &ndepth);
@@ -399,11 +383,7 @@  void fit_print(struct fit_print_ctx *ctx)
 
 	/* Root node properties */
 	ret = fit_get_desc(fit, 0, &desc);
-	printf("%*sFIT description: ", p, "");
-	if (ret)
-		printf("unavailable\n");
-	else
-		printf("%s\n", desc);
+	emit_label_val(ctx, "FIT description", ret ? "unavailable" : desc);
 
 	if (IMAGE_ENABLE_TIMESTAMP) {
 		ret = fit_get_timestamp(fit, 0, &timestamp);