From patchwork Thu Nov 20 02:55:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 748 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=1763607440; bh=owBDPjczblDlYYPTsrhuA8J11dDOuzsl6CWxe1kt4mI=; 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=oNgeKsOF5F3Tgr/8bK+AOATQ9NKT7rEmDEIMhV+FdYSRecU9uZqBGct1EO16GAnKH EV0ZUhoE9aVEDcwoXaVzun1f3QE0KyZtLsKm0E0vKllrqkX/XPVxOKnWJcOuI3PCW4 0KbMjX1O2OTtmIBabpF2KuZlohczEzYRQJpgWfbEp2eQe8MF5oKqP8xFKBKFzgM96M qL1Ea+yM6IAUUKF/i3rrC3J14Xlp2cPzLzJgCopKlo+/9kReAz4UXMQtGwagB/s2Pj zjIn+/JlVw2URxHEbBRggLLhfVm47HXr+CNopEt0vQA3EKCV7T5Qgc9GmWHtzSxx2m hdHIKasEgB26w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B3F9A68657 for ; Wed, 19 Nov 2025 19:57:20 -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 CZUtZ95higb0 for ; Wed, 19 Nov 2025 19:57:20 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607440; bh=owBDPjczblDlYYPTsrhuA8J11dDOuzsl6CWxe1kt4mI=; 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=oNgeKsOF5F3Tgr/8bK+AOATQ9NKT7rEmDEIMhV+FdYSRecU9uZqBGct1EO16GAnKH EV0ZUhoE9aVEDcwoXaVzun1f3QE0KyZtLsKm0E0vKllrqkX/XPVxOKnWJcOuI3PCW4 0KbMjX1O2OTtmIBabpF2KuZlohczEzYRQJpgWfbEp2eQe8MF5oKqP8xFKBKFzgM96M qL1Ea+yM6IAUUKF/i3rrC3J14Xlp2cPzLzJgCopKlo+/9kReAz4UXMQtGwagB/s2Pj zjIn+/JlVw2URxHEbBRggLLhfVm47HXr+CNopEt0vQA3EKCV7T5Qgc9GmWHtzSxx2m hdHIKasEgB26w== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9A93F68631 for ; Wed, 19 Nov 2025 19:57:20 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607439; bh=Q26+RSZyA5DRCKs/aQtvTirUZfMOvYoqpBIKRXiETF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fmZVF95zOobFEjpwunejq2jjedZaRMfUMsNBT+E1N1FjYrh/ITy6cX6Dq1aVv/fbo m9+6OslMBy6nCWRfSuYF616KogM5h4BRKTMqzaP7yTr/PE/LriApnmCGoT1UUQnC8o QWJU1KC+4WY1KLsmtD7ZcOrIDsrooB/jYsMfZ1yBWJl7+pB4p9jmNl+tgNn+Gyk0zy MdVQquDJKGTMbh5QGuXBCFaZPddM50Uf+UlfwJHcZLgnCSrDED+NCfsSqsOEqWhMys UidhumGb6r3TwkAk7023EcJpGNQ0atdkhboCJWuDteUJJ6qbNsRL1vLUzzyZ9wrJ+V N0spDDX9R0/bw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1634668614; Wed, 19 Nov 2025 19:57:19 -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 ozvC84CynALT; Wed, 19 Nov 2025 19:57:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607435; bh=kQJ1bPkI8A+og0VJ0gWuUMlTx5Ofbxd/JZJQZST86Bg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Leo4WmdNnzlqHKIyOBAzkXW7mhsH77KoRU2aXmJj+kK+pbt+STIst/S7/SeZFRno0 mZ5fv7sN7AomgV/HAoegYHADBjfKqh4Jd7LrMT/HFwkCXKUWD7s2IqS3ZZsmmPJQJo rfbT3qrqMz46QJsuBa503j7KkX5NurCy1kzr5GaY1L9uSEWYlW78IwBN3+ssBgNV6R QDgaFWF5j5lR6HIPYu3R+uE01sDA2hsz9w1hVF861gLHL4+vK8QW6DuEm4ok4C/XAr Mlgd0EREI/MJVDMh6J7rwvy/oBzyprJOv/xFQDqY63eYpUZw2W083lZfy1Jb8zrXxY elpyzupE6rnCg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A52A9686BB; Wed, 19 Nov 2025 19:57:14 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 19 Nov 2025 19:55:55 -0700 Message-ID: <20251120025614.2215587-21-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: JUBKO6AQDOUB7O644DTLQPIT2UX7Q4WW X-Message-ID-Hash: JUBKO6AQDOUB7O644DTLQPIT2UX7Q4WW 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 , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 20/30] fit: Change indent from string to int 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 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 Signed-off-by: Simon Glass --- boot/fit_print.c | 47 +++++++++++++++++++++++------------------------ boot/image-fit.c | 2 +- include/image.h | 13 ++++++------- tools/fit_image.c | 10 +++++----- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/boot/fit_print.c b/boot/fit_print.c index 3ff53fceded..a361ec21b5e 100644 --- a/boot/fit_print.c +++ b/boot/fit_print.c @@ -28,16 +28,14 @@ * fit_print_init() - initialize FIT print context * @ctx: pointer to FIT print context to initialize * @fit: pointer to the FIT format image header - * @indent: indentation string for printing * * This initializes a fit_print_ctx structure with the given FIT image. */ -void fit_print_init(struct fit_print_ctx *ctx, const void *fit, - const char *indent) +void fit_print_init(struct fit_print_ctx *ctx, const void *fit) { ctx->fit = fit; - ctx->indent = indent; - ctx->tab = 16 + strlen(indent); + ctx->indent = IMAGE_INDENT; + ctx->tab = 16 + IMAGE_INDENT; } /** @@ -54,7 +52,7 @@ static void emit_type(struct fit_print_ctx *ctx, const char *type, { int len; - len = printf("%s %s %s:", ctx->indent, type, label); + len = printf("%*s%s %s:", ctx->indent, "", type, label); printf("%*s", ctx->tab - len, ""); } @@ -71,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:", ctx->indent, "", label); printf("%*s", ctx->tab - len, ""); } @@ -110,12 +108,11 @@ static void fit_image_print_data(struct fit_print_ctx *ctx, int noffset, const char *type) { const char *keyname, *padding, *algo; - const char *p = ctx->indent; + int p = ctx->indent; const void *fit = ctx->fit; int value_len, ret, i; uint8_t *value; - debug("%s %s node: '%s'\n", p, type, fit_get_name(fit, noffset)); emit_type(ctx, type, "algo"); if (fit_image_hash_get_algo(fit, noffset, &algo)) { printf("invalid/unsupported\n"); @@ -129,7 +126,7 @@ static void fit_image_print_data(struct fit_print_ctx *ctx, int noffset, padding = fdt_getprop(fit, noffset, "padding", NULL); if (padding) - printf("%s %s padding: %s\n", p, type, padding); + printf("%*s%s padding: %s\n", p, "", type, padding); ret = fit_image_hash_get_value(fit, noffset, &value, &value_len); emit_type(ctx, type, "value"); @@ -141,7 +138,7 @@ static void fit_image_print_data(struct fit_print_ctx *ctx, int noffset, printf("\n"); } - debug("%s %s len: %d\n", p, type, value_len); + debug("%s len: %d\n", type, value_len); /* Signatures have a time stamp */ if (IMAGE_ENABLE_TIMESTAMP && keyname) { @@ -317,12 +314,10 @@ 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; - const char *p = ctx->indent; + int p = ctx->indent; const char *uname, *desc; int ret, ndepth, i; - ctx->tab = 19; - /* Mandatory properties */ ret = fit_get_desc(fit, noffset, &desc); emit_label_val(ctx, "Description", ret ? "unavailable" : desc); @@ -346,7 +341,7 @@ static void fit_conf_print(struct fit_print_ctx *ctx, int noffset) if (!i) emit_label(ctx, "FDT"); else - printf("%s ", p); + printf("%*s ", p, ""); printf("%s\n", uname); } @@ -362,7 +357,7 @@ static void fit_conf_print(struct fit_print_ctx *ctx, int noffset) if (!i) emit_label(ctx, "Loadables"); else - printf("%s ", p); + printf("%*s ", p, ""); printf("%s\n", uname); } @@ -372,7 +367,7 @@ static void fit_conf_print(struct fit_print_ctx *ctx, int noffset) if (!i) emit_label(ctx, "Compatible"); else - printf("%s ", p); + printf("%*s ", p, ""); printf("%s\n", uname); } @@ -390,7 +385,7 @@ static void fit_conf_print(struct fit_print_ctx *ctx, int noffset) void fit_print(struct fit_print_ctx *ctx) { const void *fit = ctx->fit; - const char *p = ctx->indent; + int p = ctx->indent; const char *desc; char *uname; int images_noffset; @@ -403,7 +398,7 @@ void fit_print(struct fit_print_ctx *ctx) /* Root node properties */ ret = fit_get_desc(fit, 0, &desc); - printf("%sFIT description: ", p); + printf("%*sFIT description: ", p, ""); if (ret) printf("unavailable\n"); else @@ -411,7 +406,7 @@ void fit_print(struct fit_print_ctx *ctx) if (IMAGE_ENABLE_TIMESTAMP) { ret = fit_get_timestamp(fit, 0, ×tamp); - printf("%sCreated: ", p); + printf("%*sCreated: ", p, ""); if (ret) printf("unavailable\n"); else @@ -436,10 +431,12 @@ void fit_print(struct fit_print_ctx *ctx) * Direct child node of the images parent node, * i.e. component image node. */ - printf("%s Image %u (%s)\n", p, count++, + printf("%*s Image %u (%s)\n", p, "", count++, fit_get_name(fit, noffset)); + ctx->indent += 2; fit_image_print(ctx, noffset); + ctx->indent -= 2; } } @@ -454,7 +451,7 @@ void fit_print(struct fit_print_ctx *ctx) /* get default configuration unit name from default property */ uname = (char *)fdt_getprop(fit, noffset, FIT_DEFAULT_PROP, NULL); if (uname) - printf("%s Default Configuration: '%s'\n", p, uname); + printf("%*s Default Configuration: '%s'\n", p, "", uname); /* Process its subnodes, print out configurations details */ for (ndepth = 0, count = 0, @@ -466,10 +463,12 @@ void fit_print(struct fit_print_ctx *ctx) * Direct child node of the configurations parent node, * i.e. configuration node. */ - printf("%s Configuration %u (%s)\n", p, count++, + printf("%*s Configuration %u (%s)\n", p, "", count++, fit_get_name(fit, noffset)); + ctx->indent += 2; fit_conf_print(ctx, noffset); + ctx->indent -= 2; } } } @@ -478,6 +477,6 @@ void fit_print_contents(const void *fit) { struct fit_print_ctx ctx; - fit_print_init(&ctx, fit, IMAGE_INDENT_STRING); + fit_print_init(&ctx, fit); fit_print(&ctx); } diff --git a/boot/image-fit.c b/boot/image-fit.c index bb8a96fe39e..defe45b1df0 100644 --- a/boot/image-fit.c +++ b/boot/image-fit.c @@ -1557,7 +1557,7 @@ static int print_and_verify(const void *fit, int rd_noffset, int verify) { struct fit_print_ctx ctx; - fit_print_init(&ctx, fit, " "); + fit_print_init(&ctx, fit); fit_image_print(&ctx, rd_noffset); if (verify) { diff --git a/include/image.h b/include/image.h index d5c3cc03de5..476f35128f4 100644 --- a/include/image.h +++ b/include/image.h @@ -26,6 +26,7 @@ struct fdt_region; #include #include +#define IMAGE_INDENT 0 #define IMAGE_INDENT_STRING "" #define BIT(nr) (1UL << (nr)) @@ -37,6 +38,7 @@ struct fdt_region; #include #include +#define IMAGE_INDENT 3 #define IMAGE_INDENT_STRING " " #endif /* USE_HOSTCC */ @@ -1202,12 +1204,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 + * @indent: indentation level for printing * @tab: amount of space to tab out for the label */ struct fit_print_ctx { const void *fit; - const char *indent; + int indent; int tab; }; @@ -1217,12 +1219,10 @@ struct fit_print_ctx { * fit_print_init() - initialize FIT print context * @ctx: pointer to FIT print context to initialize * @fit: pointer to the FIT format image header - * @indent: indentation string for printing * * This inits a fit_print_ctx structure with the given FIT image. */ -void fit_print_init(struct fit_print_ctx *ctx, const void *fit, - const char *indent); +void fit_print_init(struct fit_print_ctx *ctx, const void *fit); /** * fit_print() - prints out the contents of the FIT format image @@ -1268,8 +1268,7 @@ void fit_print_contents(const void *fit); #else /* !FIT_PRINT */ -static inline void fit_print_init(struct fit_print_ctx *ctx, const void *fit, - const char *indent) +static inline void fit_print_init(struct fit_print_ctx *ctx, const void *fit) { } static inline void fit_print(const void *fit) {} diff --git a/tools/fit_image.c b/tools/fit_image.c index 10815e8f4d3..2e08b68d479 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -940,10 +940,10 @@ static int fit_extract_contents(void *ptr, struct imgtool *itl) int ndepth; const void *fit = ptr; int count = 0; - const char *p; + int p; - /* Indent string is defined in header image.h */ - p = IMAGE_INDENT_STRING; + /* Indent value is defined in header image.h */ + p = 5; /* Find images parent node offset */ images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); @@ -973,10 +973,10 @@ static int fit_extract_contents(void *ptr, struct imgtool *itl) if (itl->pflag == count) { struct fit_print_ctx ctx; - printf("Extracted:\n%s Image %u (%s)\n", p, + printf("Extracted:\n%*s Image %u (%s)\n", p, "", count, fit_get_name(fit, noffset)); - fit_print_init(&ctx, fit, p); + fit_print_init(&ctx, fit); fit_image_print(&ctx, noffset); return fit_image_extract(fit, noffset,