From patchwork Thu Nov 20 02:56:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 758 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=1763607477; bh=KzK9MITGL/DGetnLNaIz2ULVxUMXMfsJrIjL6KRUcEo=; 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=K7meiveRmaFpJ0ATbsl1DUWdrtl9e72V8Vn9egMSdnm+lAV9/5RYSuHfu5Mts0O9d do/zCxBtAH33MeZ13FjGC2m7CvbXVRQu6nw/DVZ0lOP0/nqeawFQJ4de+kkhAYQL3A XLKqQuQQ6KtaL9jRe69Ihm4f3hRTcbHilCwhWdzE9mgydRnZZIySbp9J8BrOmqBmny o7BzNSVl9Htpf0chxzarIJuKQA1VInWYtY/nvmlJCWebXbCZlP+7HAQ/OJgr7NCKDJ RjNUd12RrjMXdrR62mY2A6GjSaOjNUpK+BduE7EStByu0M3H8Cm7ZETTEl7lISUzCA DmkfHgXYBYtuQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2F9FB5E7DA for ; Wed, 19 Nov 2025 19:57:57 -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 BNJoO5yCTIy9 for ; Wed, 19 Nov 2025 19:57:57 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607477; bh=KzK9MITGL/DGetnLNaIz2ULVxUMXMfsJrIjL6KRUcEo=; 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=K7meiveRmaFpJ0ATbsl1DUWdrtl9e72V8Vn9egMSdnm+lAV9/5RYSuHfu5Mts0O9d do/zCxBtAH33MeZ13FjGC2m7CvbXVRQu6nw/DVZ0lOP0/nqeawFQJ4de+kkhAYQL3A XLKqQuQQ6KtaL9jRe69Ihm4f3hRTcbHilCwhWdzE9mgydRnZZIySbp9J8BrOmqBmny o7BzNSVl9Htpf0chxzarIJuKQA1VInWYtY/nvmlJCWebXbCZlP+7HAQ/OJgr7NCKDJ RjNUd12RrjMXdrR62mY2A6GjSaOjNUpK+BduE7EStByu0M3H8Cm7ZETTEl7lISUzCA DmkfHgXYBYtuQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1F36C68614 for ; Wed, 19 Nov 2025 19:57:57 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607474; bh=fPjCfmtJCqP+fyt/pSu+N9uM12NRSo+4dWQbjkA6yU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AALLbLxQtKeGYWyOfHAACE4o5BvhraO4f9BkCYXy8xYDpV2jUGhZCzPNeLyx7iFQ2 noelmFeuAndubKlko3Foow99BzCqFXmlJNl8YaEAo4sqrY8P2GRmaSsZsZn1LAI0nk Q6Jap2KjqAb2bvNyyqja1WSsUcL/xUJC4lnQ13I9fsDjKqO/114rrQG8DPu15Jkr9A 4DTkr2oA/iFAOpcpAXoIg47N5MM1ydZMAuEVfsftBJHBFtpW+diN5TYT23MEi3lkQV CunBStfDvwteCvkLbFPhJLhCGl05nuaR+zZAejtyXb7kZFLS3dOBvnXsqqFD5uKr0c 1GislwVoxDSxA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F34DA68614; Wed, 19 Nov 2025 19:57:54 -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 gAC0nDk9Q10L; Wed, 19 Nov 2025 19:57:54 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763607467; bh=0rSD14OvZmrbT+qKaMFO3EMgIjcB+rybqIUKNKZ4M28=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jXAKRy5PosdsS1mz3LnyBUQ3Cw9ExB2UYbV/7LIARRQjNfYL3GG22U+fYwqOf5N/l 6k+3PZQXqpfn78eR7sXOfQnJqYhKO0IisipNe31jFWt6PBfE7PmdR4D8igFX4YWTXn qULO65+15xvpZjy1twJnnDHdfFV8fivZ+6dQLyhHdUOAG96llZw4PiWEu2eW/DNz9C ql7KDVzz6OuCgHMOfpxRIP+4Gt6emVG9CWMNOllIsuQvT9+FLkex8Tptpb3qFQvV9U AodWQ7cxnIDFVwZcTiFYwOTuZUy0di8awCAnWFX4RhlcojX1cKODefrBMGUY6K5khN zeq7mrAi9UF8Q== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id E67EE5E7DA; Wed, 19 Nov 2025 19:57:46 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Wed, 19 Nov 2025 19:56:05 -0700 Message-ID: <20251120025614.2215587-31-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: TIDBAW623VTMN2S2JRTFQ453LJZ5P45W X-Message-ID-Hash: TIDBAW623VTMN2S2JRTFQ453LJZ5P45W 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 30/30] fit: Use the libfdt subnode iterator 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 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. Co-developed-by: Claude Signed-off-by: Simon Glass --- boot/fit_print.c | 70 +++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 42 deletions(-) diff --git a/boot/fit_print.c b/boot/fit_print.c index 638f66942e9..f4428d020e5 100644 --- a/boot/fit_print.c +++ b/boot/fit_print.c @@ -295,14 +295,9 @@ static void process_subnodes(struct fit_print_ctx *ctx, int parent) { const void *fit = ctx->fit; int noffset; - int ndepth; - for (ndepth = 0, noffset = fdt_next_node(fit, parent, &ndepth); - (noffset >= 0) && (ndepth > 0); - noffset = fdt_next_node(fit, noffset, &ndepth)) { - if (ndepth == 1) - fit_image_print_verification_data(ctx, noffset); - } + fdt_for_each_subnode(noffset, fit, parent) + fit_image_print_verification_data(ctx, noffset); } /** @@ -431,8 +426,7 @@ void fit_print(struct fit_print_ctx *ctx) int images_noffset; int confs_noffset; int noffset; - int ndepth; - int count = 0; + int count; /* Root node properties */ emit_desc(ctx, 0, "FIT description"); @@ -448,22 +442,18 @@ void fit_print(struct fit_print_ctx *ctx) } /* Process its subnodes, print out component images details */ - for (ndepth = 0, count = 0, - noffset = fdt_next_node(fit, images_noffset, &ndepth); - (noffset >= 0) && (ndepth > 0); - noffset = fdt_next_node(fit, noffset, &ndepth)) { - if (ndepth == 1) { - /* - * Direct child node of the images parent node, - * i.e. component image node. - */ - printf("%*s Image %u (%s)\n", p, "", count++, - fit_get_name(fit, noffset)); - - ctx->indent += 2; - fit_image_print(ctx, noffset); - ctx->indent -= 2; - } + count = 0; + fdt_for_each_subnode(noffset, fit, images_noffset) { + /* + * Direct child node of the images parent node, + * i.e. component image node. + */ + printf("%*s Image %u (%s)\n", p, "", count++, + fit_get_name(fit, noffset)); + + ctx->indent += 2; + fit_image_print(ctx, noffset); + ctx->indent -= 2; } /* Find configurations parent node offset */ @@ -475,27 +465,23 @@ 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); + uname = (char *)fdt_getprop(fit, confs_noffset, FIT_DEFAULT_PROP, NULL); if (uname) printf("%*s Default Configuration: '%s'\n", p, "", uname); /* Process its subnodes, print out configurations details */ - for (ndepth = 0, count = 0, - noffset = fdt_next_node(fit, confs_noffset, &ndepth); - (noffset >= 0) && (ndepth > 0); - noffset = fdt_next_node(fit, noffset, &ndepth)) { - if (ndepth == 1) { - /* - * Direct child node of the configurations parent node, - * i.e. configuration node. - */ - printf("%*s Configuration %u (%s)\n", p, "", count++, - fit_get_name(fit, noffset)); - - ctx->indent += 2; - fit_conf_print(ctx, noffset); - ctx->indent -= 2; - } + count = 0; + fdt_for_each_subnode(noffset, fit, confs_noffset) { + /* + * Direct child node of the configurations parent node, + * i.e. configuration node. + */ + printf("%*s Configuration %u (%s)\n", p, "", count++, + fit_get_name(fit, noffset)); + + ctx->indent += 2; + fit_conf_print(ctx, noffset); + ctx->indent -= 2; } }