From patchwork Thu Nov 20 02:55:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 743 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607431; bh=WSmJ4sUFJR0vwsyHyFgJWMwSYXGFDvztAPnd09wdLOg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Z3BpbqNoxLPVVIH+mp/zyjpSSGI6JQ5vNLw8poEDkSHN2Og2hUzvH2wMgNOXvXasA yaI565vlolxw3/Oj+WL41iRGbSYu6Jo0/uhA5Xm19McgqEJR7bWyRa+xsb1ipyAClG YICS2g1MluBoDBBx0f0dMegnMC5AMs263LpTRzGuQHLE6+Noq3Vr0Bx3/2GBdMPMEH NPaMd0ISgNBpCGvB0uH0ERZb2IItmdEcmhG3kGJWC6lHjZ+B4PSQRToiv/xYPHbj47 H1B2KsAkAWV9GO0iFgkwPFoQYQb2xRGlDUIX9SieCGFHlJ8r5otI+rCb/Rr8TCZ7oC q1ZQZlmNJCX5w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F2A7B68657 for ; Wed, 19 Nov 2025 19:57:11 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id hPe0DY3I498R for ; Wed, 19 Nov 2025 19:57:11 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607431; bh=WSmJ4sUFJR0vwsyHyFgJWMwSYXGFDvztAPnd09wdLOg=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Z3BpbqNoxLPVVIH+mp/zyjpSSGI6JQ5vNLw8poEDkSHN2Og2hUzvH2wMgNOXvXasA yaI565vlolxw3/Oj+WL41iRGbSYu6Jo0/uhA5Xm19McgqEJR7bWyRa+xsb1ipyAClG YICS2g1MluBoDBBx0f0dMegnMC5AMs263LpTRzGuQHLE6+Noq3Vr0Bx3/2GBdMPMEH NPaMd0ISgNBpCGvB0uH0ERZb2IItmdEcmhG3kGJWC6lHjZ+B4PSQRToiv/xYPHbj47 H1B2KsAkAWV9GO0iFgkwPFoQYQb2xRGlDUIX9SieCGFHlJ8r5otI+rCb/Rr8TCZ7oC q1ZQZlmNJCX5w== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E02DD5E7DA for ; Wed, 19 Nov 2025 19:57:11 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607429; bh=YNjs6Sh16FYqNxOCSBkBDglkAfa9NuRdrPajLMYqDc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TjpB9oDyvE8qNEiw7fUr9f9M2H8tFNr+2SH/OT+x7k++Ren2EJb4+qsf+9/jO3OcQ MYZrXE6ZnCseN1Su3ZSWrHFMbkYY7EfKqwwYeo3XEw4FuiWI9Uo2OA9gZDzun+3Cxw lzZEyyQvLlBJrWUJ96vuOD29d8XmxaTPkgEl1sOlnJTMkc14zltHXxO6eyr50WAPPI V1EMuXlN3R34tIN3brV2oGbUYuoqmtHHElBdvNLpIHvr+m6bTg1AEtBg7/nvXPNU32 0uENWH8pQDozQoZln4ETnqnXvtxYsdoJx+J0nubFC+lCAQM7a25WsYOp/BjfEW8Ab2 lFfNUVrr7ehAg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 665F068657; Wed, 19 Nov 2025 19:57:09 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id 3FZjSWg5Ncez; Wed, 19 Nov 2025 19:57:09 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607427; bh=3F+7/6J6+L4jF0IkkA+5rutEsYigWc3pN+y1zYnQalw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qp6MODIOt7c1M9428nX1IeHYQ/shJE/IEVY8p007uXzsn3hW/cDsDBJw99TVsxlFD fD9E8Z9+y1Qk8V9j3meB2CDbrcBSs8t7/NRjkWXw3rLTUUic+sF9DFgD7F/WN5A8Mz kmTa+dUX84x86CZPWlVr/Y4DRGVczB1oicoa8j0808CaSncn7MZNwHbqbV+lM5gSu3 LCzvBM0sk0uELJUS+0ZWWT5VnjftMKmHNgOrSiJCb8vojteSQLya6WjWJ+HM8WhzAS e4M6Yq/EmP5A7AJt1kDkGcP0ApWUEvbR1CTc7AbN0VXbli2+YwckHIEruvU+J2M1Ny get4cZrSnQxuw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 3AA40686C8; Wed, 19 Nov 2025 19:57:07 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 19 Nov 2025 19:55:51 -0700 Message-ID: <20251120025614.2215587-17-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251120025614.2215587-1-sjg@u-boot.org> References: <20251120025614.2215587-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: J53CYNSLWWYITEX6PKDPVLYTBJ2YTJBU X-Message-ID-Hash: J53CYNSLWWYITEX6PKDPVLYTBJ2YTJBU X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 16/30] fit: Create some helpers for printing List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass 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 --- boot/fit_print.c | 42 +++++++++++++++++++++++++++++++++++++++--- include/image.h | 2 ++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/boot/fit_print.c b/boot/fit_print.c index 07454dcf5cf..b87526023b4 100644 --- a/boot/fit_print.c +++ b/boot/fit_print.c @@ -37,6 +37,42 @@ void fit_print_init(struct fit_print_ctx *ctx, const void *fit, { ctx->fit = fit; ctx->indent = indent; + ctx->tab = 16 + strlen(indent); +} + +/** + * emit_type() - print a label with indentation and padding + * @ctx: pointer to FIT print context + * @type: type prefix (e.g., "Hash" or "Sign") + * @label: label suffix (e.g., "algo" or "value") + * + * Prints the indentation from the context, followed by two spaces, the type, + * a space, the label, a colon, and padding to align values to ctx->tab. + */ +static void emit_type(struct fit_print_ctx *ctx, const char *type, + const char *label) +{ + int len; + + len = printf("%s %s %s:", ctx->indent, type, label); + printf("%*s", ctx->tab - len, ""); +} + +/** + * emit_label() - print a label with indentation and padding + * @ctx: pointer to FIT print context + * @type: type prefix (e.g., "Hash" or "Sign") + * @label: label suffix (e.g., "algo" or "value") + * + * Prints the indentation from the context, followed by two spaces, a space, + * the label, a colon, and padding to align values to ctx->tab. + */ +static void emit_label(struct fit_print_ctx *ctx, const char *label) +{ + int len; + + len = printf("%s %s:", ctx->indent, label); + printf("%*s", ctx->tab - len, ""); } /** @@ -63,7 +99,7 @@ static void fit_image_print_data(struct fit_print_ctx *ctx, int noffset, uint8_t *value; debug("%s %s node: '%s'\n", p, type, fit_get_name(fit, noffset)); - printf("%s %s algo: ", p, type); + emit_type(ctx, type, "algo"); if (fit_image_hash_get_algo(fit, noffset, &algo)) { printf("invalid/unsupported\n"); return; @@ -79,7 +115,7 @@ static void fit_image_print_data(struct fit_print_ctx *ctx, int noffset, printf("%s %s padding: %s\n", p, type, padding); ret = fit_image_hash_get_value(fit, noffset, &value, &value_len); - printf("%s %s value: ", p, type); + emit_type(ctx, type, "value"); if (ret) { printf("unavailable\n"); } else { @@ -94,7 +130,7 @@ static void fit_image_print_data(struct fit_print_ctx *ctx, int noffset, if (IMAGE_ENABLE_TIMESTAMP && keyname) { time_t timestamp; - printf("%s Timestamp: ", p); + emit_label(ctx, "Timestamp"); if (fit_get_timestamp(fit, noffset, ×tamp)) printf("unavailable\n"); else diff --git a/include/image.h b/include/image.h index 7a5ad29a3ec..d5c3cc03de5 100644 --- a/include/image.h +++ b/include/image.h @@ -1203,10 +1203,12 @@ int fit_get_subimage_count(const void *fit, int images_noffset); * struct fit_print_ctx - context for FIT printing * @fit: pointer to the FIT format image header * @indent: indentation string for printing + * @tab: amount of space to tab out for the label */ struct fit_print_ctx { const void *fit; const char *indent; + int tab; }; #if CONFIG_IS_ENABLED(FIT_PRINT)