From patchwork Thu Nov 20 02:55:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 742 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=1763607427; bh=veB1xuhh6x1ImT+Ug6auPeYGWfHrNwCdtlnnfJtBgOk=; 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=SiaX0ZhEgn4IOFyXLM1b7mszVGFa5d9w8Na08dmI4CwTSvwpo5AwPrmKI4SjppRtm mREEWBxyMRYz1VJiegVKYUICKRqpxr7JjxbYn1eI36Bw1lY0bFMPKXyhWrEW81Z1pm ooUca0s8tG2ApBzvuueEkeg+d+gjAs+styLhN9RiEKNZhNNDI6xmT16oouWFI53si/ ikLt8tNWu71pYwBro91pgs60CN+JaNjT+kIfMqWNu5SpkKzZI/OmWu1SfWHA+yBFjD SDRUE5kKxzjOMsG1h3gWXp3kY2TPne8C7OJbkr9hCZxpvHB1n97Mi1yd9ITWHj2PDy ZavosENe9V+dA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 28AFF68631 for ; Wed, 19 Nov 2025 19:57:07 -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 hTjvjFqKAj6C for ; Wed, 19 Nov 2025 19:57:07 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607425; bh=veB1xuhh6x1ImT+Ug6auPeYGWfHrNwCdtlnnfJtBgOk=; 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=DwwUSK0/Lp1oug0cuK8z9xqXpomxqE4nyMKIKSkrECgqgIUPDiY/wU3xQOmhd0MP9 P4VlrCa7uU0vJ1Kx9YMgIiveIGzpNE787g5J9rW3wvb+No78Ld80oY4QWtAkrphbI0 SJBu5L7rO4j0wsLx2mDUJO3akbkrWQPrI9Q76fStfl9uZsH89TxCRad0CUr8i9G/e/ QB4QmEvLmChNU5XXv3iJuvWT1w0Ggon972VticxsjO2AcUPkzQC+rpvoltm0vTPCqv 4Qgk9bfr3c2fjqPpHxibquCnANOCfVaIWjs82diypwmCccNL+4d9XXz/wqA9OeUO+L Dh2Lx3kmCKIyg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 39455686C8 for ; Wed, 19 Nov 2025 19:57:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607422; bh=HPpPwMJVYDH7l54agyFrvRubTZOl+ncs/5yw/Vb12xI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vG6N7Jz0e1J/2D5Du2eTv0jSq72s/D6V3baA26QEXt8iyZpsu1Er/qjdr/W8jT/mh wna/FpCxkuWFIKQMA3FkGVv9ZvrEWIZod46JU2ITPby2DqGXzE1nBugcIpJw/Sy+fa iTN47yuAI2r/aU1oGcX3VVseIPL1brdmjwBCMuxd847qzI9B/J0cGm69Xk7XKkuS+R rlG7NaVqY+R+zhVN1sabaGMthzaUeziqwfXOfqdT95RBsvaD3ONEl/1bnIFpjOI6Ig ay5UO7k/wBSZZ7uDz42d3/4rLQbXKmXiUuxVNhVq/lhJv9LwUkXVq73mZAKstn/7l2 c4JVLesEXcQMA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 54BAE686E2; Wed, 19 Nov 2025 19:57:02 -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 DT388UoSaQU2; Wed, 19 Nov 2025 19:57:02 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607421; bh=5c5XE+friOPkH3hEAc3wfi5PhrMpDjOXiQRl76yN4PI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GdV5QDlGEQ0qwyrZCv/mYbgkoFcu0BZXqFKDRFYxFpVvNwLmPyXUQDtjTCmF7S+My G6X7QEpNxOycF23i032d5M/RfEDZl2gfcpB4TAwgh1lBDVsxd6GQf259MYI1ZM2z4A O0HmFbXuswKVhW14rDqNCAjf3NosBhQS2GvwH/wBr51QCthrVGUVxsMWcyiqBXpXtx eH//vJ9NUXbjUGN7OF79v5bpJATvXVpkpilmxi0RBQduxxN2tmFzkABopHERN2vaYU pmdMyv8W/Hofty2pPL7ekoVlGvA73liia1mQ4LVxa/hBq8cq52OWOIxrHrHIVEqqI4 mtn05s9xz37sA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 7092468668; Wed, 19 Nov 2025 19:57:01 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 19 Nov 2025 19:55:49 -0700 Message-ID: <20251120025614.2215587-15-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: VL5FHAJNLUDNKIYTCKCZV5BECQHUJPLL X-Message-ID-Hash: VL5FHAJNLUDNKIYTCKCZV5BECQHUJPLL 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 14/30] fit: Add a context struct for FIT-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 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 Signed-off-by: Simon Glass --- boot/fit_print.c | 58 +++++++++++++++++++++++++++++++---------------- boot/image-fit.c | 5 +++- include/image.h | 30 ++++++++++++++++++------ tools/fit_image.c | 5 +++- 4 files changed, 69 insertions(+), 29 deletions(-) diff --git a/boot/fit_print.c b/boot/fit_print.c index bea2e176f17..bb6dc140e34 100644 --- a/boot/fit_print.c +++ b/boot/fit_print.c @@ -25,8 +25,20 @@ #include /** - * fit_image_print_data() - prints out the hash node details + * fit_print_init() - initialize FIT print context + * @ctx: pointer to FIT print context to initialize * @fit: pointer to the FIT format image header + * + * This initializes a fit_print_ctx structure with the given FIT image. + */ +void fit_print_init(struct fit_print_ctx *ctx, const void *fit) +{ + ctx->fit = fit; +} + +/** + * fit_image_print_data() - prints out the hash node details + * @ctx: pointer to FIT print context * @noffset: offset of the hash node * @p: pointer to prefix string * @type: Type of information to print ("hash" or "sign") @@ -39,10 +51,11 @@ * returns: * no returned results */ -static void fit_image_print_data(const void *fit, int noffset, const char *p, - const char *type) +static void fit_image_print_data(struct fit_print_ctx *ctx, int noffset, + const char *p, const char *type) { const char *keyname, *padding, *algo; + const void *fit = ctx->fit; int value_len, ret, i; uint8_t *value; @@ -88,7 +101,7 @@ static void fit_image_print_data(const void *fit, int noffset, const char *p, /** * fit_image_print_verification_data() - prints out the hash/signature details - * @fit: pointer to the FIT format image header + * @ctx: pointer to FIT print context * @noffset: offset of the hash or signature node * @p: pointer to prefix string * @@ -97,9 +110,10 @@ static void fit_image_print_data(const void *fit, int noffset, const char *p, * returns: * no returned results */ -static void fit_image_print_verification_data(const void *fit, int noffset, - const char *p) +static void fit_image_print_verification_data(struct fit_print_ctx *ctx, + int noffset, const char *p) { + const void *fit = ctx->fit; const char *name; /* @@ -109,13 +123,14 @@ static void fit_image_print_verification_data(const void *fit, int noffset, */ name = fit_get_name(fit, noffset); if (!strncmp(name, FIT_HASH_NODENAME, strlen(FIT_HASH_NODENAME))) - fit_image_print_data(fit, noffset, p, "Hash"); + fit_image_print_data(ctx, noffset, p, "Hash"); else if (!strncmp(name, FIT_SIG_NODENAME, strlen(FIT_SIG_NODENAME))) - fit_image_print_data(fit, noffset, p, "Sign"); + fit_image_print_data(ctx, noffset, p, "Sign"); } -void fit_image_print(const void *fit, int image_noffset, const char *p) +void fit_image_print(struct fit_print_ctx *ctx, int image_noffset, const char *p) { + const void *fit = ctx->fit; uint8_t type, arch, os, comp = IH_COMP_NONE; const char *desc; size_t size; @@ -125,9 +140,6 @@ void fit_image_print(const void *fit, int image_noffset, const char *p) int ndepth; int ret; - if (!CONFIG_IS_ENABLED(FIT_PRINT)) - return; - /* Mandatory properties */ ret = fit_get_desc(fit, image_noffset, &desc); printf("%s Description: ", p); @@ -218,14 +230,14 @@ void fit_image_print(const void *fit, int image_noffset, const char *p) noffset = fdt_next_node(fit, noffset, &ndepth)) { if (ndepth == 1) { /* Direct child node of the component image node */ - fit_image_print_verification_data(fit, noffset, p); + fit_image_print_verification_data(ctx, noffset, p); } } } /** * fit_conf_print - prints out the FIT configuration details - * @fit: pointer to the FIT format image header + * @ctx: pointer to FIT print context * @noffset: offset of the configuration node * @p: pointer to prefix string * @@ -235,8 +247,10 @@ void fit_image_print(const void *fit, int image_noffset, const char *p) * returns: * no returned results */ -static void fit_conf_print(const void *fit, int noffset, const char *p) +static void fit_conf_print(struct fit_print_ctx *ctx, int noffset, + const char *p) { + const void *fit = ctx->fit; const char *uname, *desc; int ret, ndepth, i; @@ -307,13 +321,14 @@ static void fit_conf_print(const void *fit, int noffset, const char *p) noffset = fdt_next_node(fit, noffset, &ndepth)) { if (ndepth == 1) { /* Direct child node of the component config node */ - fit_image_print_verification_data(fit, noffset, p); + fit_image_print_verification_data(ctx, noffset, p); } } } -void fit_print(const void *fit) +void fit_print(struct fit_print_ctx *ctx) { + const void *fit = ctx->fit; const char *desc; char *uname; int images_noffset; @@ -366,7 +381,7 @@ void fit_print(const void *fit) printf("%s Image %u (%s)\n", p, count++, fit_get_name(fit, noffset)); - fit_image_print(fit, noffset, p); + fit_image_print(ctx, noffset, p); } } @@ -396,12 +411,15 @@ void fit_print(const void *fit) printf("%s Configuration %u (%s)\n", p, count++, fit_get_name(fit, noffset)); - fit_conf_print(fit, noffset, p); + fit_conf_print(ctx, noffset, p); } } } void fit_print_contents(const void *fit) { - fit_print(fit); + struct fit_print_ctx ctx; + + fit_print_init(&ctx, fit); + fit_print(&ctx); } diff --git a/boot/image-fit.c b/boot/image-fit.c index 5eef9479781..ed77a5e09c5 100644 --- a/boot/image-fit.c +++ b/boot/image-fit.c @@ -1555,7 +1555,10 @@ int fit_get_data_conf_prop(const void *fit, const char *prop_name, static int print_and_verify(const void *fit, int rd_noffset, int verify) { - fit_image_print(fit, rd_noffset, " "); + struct fit_print_ctx ctx; + + fit_print_init(&ctx, fit); + fit_image_print(&ctx, rd_noffset, " "); if (verify) { puts(" Verifying Hash Integrity ... "); diff --git a/include/image.h b/include/image.h index 17dd68e7048..9b5a1815df9 100644 --- a/include/image.h +++ b/include/image.h @@ -1199,26 +1199,41 @@ int fit_parse_subimage(const char *spec, ulong addr_curr, 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 + */ +struct fit_print_ctx { + const void *fit; +}; + #if CONFIG_IS_ENABLED(FIT_PRINT) /** - * fit_print() - prints out the contents of the FIT format image + * fit_print_init() - initialize FIT print context + * @ctx: pointer to FIT print context to initialize * @fit: pointer to the FIT format image header - * @p: pointer to prefix string * - * This formats a multi line FIT image contents description. + * This inits a fit_print_ctx structure with the given FIT image. + */ +void fit_print_init(struct fit_print_ctx *ctx, const void *fit); + +/** + * fit_print() - prints out the contents of the FIT format image + * @ctx: pointer to FIT print context + * * The routine prints out FIT image properties (root node level) followed by * the details of each component image. * * returns: * no returned results */ -void fit_print(const void *fit); +void fit_print(struct fit_print_ctx *ctx); /** * fit_image_print - prints out the FIT component image details - * @fit: pointer to the FIT format image header - * @image_noffset: offset of the component image node + * @ctx: pointer to FIT print context + * @noffset: offset of the component image node * @p: pointer to prefix string * * fit_image_print() lists all mandatory properties for the processed component @@ -1230,7 +1245,7 @@ void fit_print(const void *fit); * returns: * no returned results */ -void fit_image_print(const void *fit, int noffset, const char *p); +void fit_image_print(struct fit_print_ctx *ctx, int noffset, const char *p); /** * fit_print_contents() - prints out the contents of the FIT format image @@ -1248,6 +1263,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) {} static inline void fit_print(const void *fit) {} static inline void fit_image_print(const void *fit, int noffset, const char *p) { diff --git a/tools/fit_image.c b/tools/fit_image.c index 80f9020d29d..017a2d212e9 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -971,10 +971,13 @@ static int fit_extract_contents(void *ptr, struct imgtool *itl) * i.e. component image node. */ if (itl->pflag == count) { + struct fit_print_ctx ctx; + printf("Extracted:\n%s Image %u (%s)\n", p, count, fit_get_name(fit, noffset)); - fit_image_print(fit, noffset, p); + fit_print_init(&ctx, fit); + fit_image_print(&ctx, noffset, p); return fit_image_extract(fit, noffset, itl->outfile);