From patchwork Thu Aug 28 02:07:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 158 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=1756346892; bh=xdse5vLq7j6SwL1IkTqPAf+FYO8/Ls8/vphUz0djCGw=; 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=jBuc7mnOQMIcQSEzo2ZrTX3Z+WykisSQJCjGVRi3PvGYtE2GhADKp2QD31AK1T+yP GkL5a7tdmB7/9okeK+iysBVXTcBLu88L+eRHV8Ttc97ZKzt67JRKEIUrxs6KCCNb8V ndDQsmnnMdk+iQ7RkrLqoSGjNKDqYSgRPf3SEp3CsPFbXCph1geiK59B3gfG/3rE6s hpXDYo8bnQgfcTJgBPpCvUFmu/s7s3tBeRhG4lUUZRzMniOYc1H3YstwY0oEcjrEDe Co/WZflRE0Q5IcDxKWkQD4Xjv5NwJlZGcaj6bcIemr6LleOrQXbtejAWfbVDfJIbfW h9bYIrnPm5ADw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3298D67828 for ; Wed, 27 Aug 2025 20:08:12 -0600 (MDT) 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 0Akxzw7CS04b for ; Wed, 27 Aug 2025 20:08:12 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346890; bh=xdse5vLq7j6SwL1IkTqPAf+FYO8/Ls8/vphUz0djCGw=; 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=B5UH7+AGdobOTq4v2yPa5qrKckYsr2YgxnyzDHMSSCKDga64Kyg27nMHMqyaXr1UN 7nPFsYw55QyGPKSEaruCf2Zrc1enkeJTuoRbLqOClbbACr3W20e5E6zfFC0STFGxqZ By0smDM2Y6k7+a5gD45pT//xD3liOqJZF/oxIR91IRcKoG089lzCaUahY88nW67WY/ d7T1/M45xh/7frcXFgQM4ZRCBl/xIfMTvL100a4l3a5s6m79RMJyTmYJRQtfxbIY1y jHGqdqf6LD67ucnR6rnQHuzmZ4x5hguh0ior3l5zttEYNXw/f4y5DfoCfwbPZaWD4k Owk4qlDtbXDsg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4ECEA67837 for ; Wed, 27 Aug 2025 20:08:10 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346888; bh=va+FYHfVW4FGPXxJXeIzfl5lDhFLvQWvd07eDe5EzQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bl8ydHMqx1klHb/yW9DjONhvit9zwgPpHmK+nqUnXYncHan9sovUXzuy5TZWHm5f8 eNWy+MVIsqpM80uuBYSbGILzNA61qqCKoFYzFpuda1K3KowacrXVhSEq35fZ00nge2 1tpPBEOfe7qjaixOCjCwRaeNJLBxJOOwuQXsOWj894RuFm4qhVsjl3sG7hTYjUFUFD 9SBvQqaiaP+PMLA774f0EL3+I7wRT1+c+PsaZX3X9R3mD+b3jpO5svvVACEIqgBQzq SDftbiXmVoUXM2EkMCNX+Oa1MgbCzD2gAgcHjHYp43T2huXF964r8p719Xk2GxBTQd FWrCwx1csX28w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BE8446777F; Wed, 27 Aug 2025 20:08:08 -0600 (MDT) 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 KZkUaNAfBmjk; Wed, 27 Aug 2025 20:08:08 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346888; bh=3kTf7+pZ5cY/zNv/ZF0cI/hKAr0dEAgOE0knYwYNTng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b8Pz6rs2h4DnsuQ406TpiLGKVkGs9ExAT6OKynPRrsLISoKNcwGsi6E5anx8Psi2J mkUljM0xbu6tWPEdsdmLAudhuyyURKSoUM7bRw7gT+iOOqaQPZQNHvn88GYO4gf40O kfELlC8pQA7aVVe8HiOTwvi9GBooKQVvhrMQMgtS63DjInsa2M3C0WoKcK5L/Zn2ut 4Izo+wYNtlKryvFUhH93u+QdhX77Gtirh7lpCP6VE47651GPhljITIZf+yyYQYwcIR cOlo3q1bdqiLaSQyqYizTgjwustpd7rFHvwpPdg8g/BNlL0XXBsb1IFiVhZ+OotIyI Ztz9miO0k1ibw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id F041D6777E; Wed, 27 Aug 2025 20:08:07 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 27 Aug 2025 20:07:18 -0600 Message-ID: <20250828020732.981415-16-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250828020732.981415-1-sjg@u-boot.org> References: <20250828020732.981415-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: FOVIYM4TWVGCSIRMJEHF5M3NZ737PZBG X-Message-ID-Hash: FOVIYM4TWVGCSIRMJEHF5M3NZ737PZBG 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 15/20] fdt: Add a function to show the reserved-memory nodes 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 Add a new helper which lists the subnodes of the reserved-memory node. This can be helpful when checking the devicetree before booting. Co-developed-by: Claude Signed-off-by: Simon Glass --- boot/fdt_support.c | 54 +++++++++++++++++++++++++++++++++++++++++++ include/fdt_support.h | 7 ++++++ 2 files changed, 61 insertions(+) diff --git a/boot/fdt_support.c b/boot/fdt_support.c index 92f2f534ee0..f42eaa488de 100644 --- a/boot/fdt_support.c +++ b/boot/fdt_support.c @@ -2259,3 +2259,57 @@ int fdt_fixup_pmem_region(void *fdt, u64 pmem_start, u64 pmem_size) return 0; } + +void fdt_print_reserved(void *fdt) +{ + int node, reserved, id; + int addr_cells, size_cells; + + printf("%-4s %-20s %-18s %-18s\n", "ID", "Name", "Start", "Size"); + printf("--------------------------------------------------------" + "--------\n"); + + reserved = fdt_path_offset(fdt, "/reserved-memory"); + if (reserved < 0) { + printf("No /reserved-memory node found in device tree\n"); + return; + } + + /* Get #address-cells and #size-cells from reserved-memory node */ + fdt_support_default_count_cells(fdt, reserved, &addr_cells, + &size_cells); + + id = 0; + fdt_for_each_subnode(node, fdt, reserved) { + const char *name = fdt_get_name(fdt, node, NULL); + const fdt32_t *reg; + u64 rsv_start = 0, rsv_size = 0; + int len; + + reg = fdt_getprop(fdt, node, "reg", &len); + if (reg && len >= (addr_cells + size_cells) * sizeof(fdt32_t)) { + int cells = 0; + + /* Parse address */ + for (int i = 0; i < addr_cells; i++) + rsv_start = (rsv_start << 32) | + fdt32_to_cpu(reg[cells++]); + + /* Parse size */ + for (int i = 0; i < size_cells; i++) + rsv_size = (rsv_size << 32) | + fdt32_to_cpu(reg[cells++]); + + printf("%-4d %-20s 0x%-16llx 0x%-16llx\n", + id++, name ? name : "(unnamed)", rsv_start, + rsv_size); + } else { + printf("%-4d %-20s %-18s %-18s\n", + id++, name ? name : "(unnamed)", "(no reg)", + "(no reg)"); + } + } + + if (!id) + printf("No reserved-memory regions found\n"); +} diff --git a/include/fdt_support.h b/include/fdt_support.h index eca9e7e3ac3..abd7504ad9b 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -529,4 +529,11 @@ int fdt_print(const void *fdt, int nodeoffset, int depth); */ int fdt_print_path(const char *pathp, char *prop, int depth); +/** + * fdt_print_reserved() - Print all device tree reserved-memory nodes + * + * @fdt: Device tree blob + */ +void fdt_print_reserved(void *fdt); + #endif /* ifndef __FDT_SUPPORT_H */