From patchwork Thu Aug 28 02:07:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 160 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=1756346897; bh=bxAFgjfqttDLbsLnPfgTbZIf1qnYhYb8BC2Fx+34LTA=; 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=o3JZWfkK0bfRSWvzkGTG1Zkp7f+vX2g1ZwMM8cTDv1wVKIkcGZhNdJH2OxKTnPD2W lfbOtZY38cCkeisbg/frsYM3jzsKO0WLVRdpLAQyDlygcUtC8PAfv26s67p2YuvjmM JuXH4xvYFC5t44D6PEXRqtRoC8NAl8+QgSuaJ9EIVY82svAYEkR0Bbw4POcT1MozFf TbWZwUxClwaXr6tqL3oSudpWplyQASEc3nOWCWFq9Q6HgtauVIIFMmTkx3eZ8dQsZz DC6+SGy5O18vjn0r+8ixgR4dza7A4Ec6vJWE4igQam0FkTHKl9WfXnr061IfJV7Me2 DqPkI+A5N57wg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 007A76782F for ; Wed, 27 Aug 2025 20:08:17 -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 3hST2ctRbOie for ; Wed, 27 Aug 2025 20:08:16 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346896; bh=bxAFgjfqttDLbsLnPfgTbZIf1qnYhYb8BC2Fx+34LTA=; 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=X+bRZSMF//LCXESixeIkMyQVQLzpS9VE3IleApoRNeVLMkQ7jUw/EjmvSLVwvyWtL c2VlowZxUqUZ0619m7dmRQJFkjxpX9EtYOSKie31IA8BeYhee3OOI33OjNpa6lbT9n mcO+408g7z72yxC/WjqSLIdPXxkCpIMoGQIxh4TlHjybyPUhhfdtPDnaJPOk4rtGJv /kIkjte3gAwy9COMDaeiqTw/bB2JNd4TzY0yAC//BF9f0cDlkbaLQwEIGavBnBh+pH 2KGdWjynBYRyn1dc6DzWyaWr4SWExOXVq6nQj1xZ9K3TRm6pBcE+2nVkTt1HthPi8L 4Igmy5CR+trOg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E431A6776F for ; Wed, 27 Aug 2025 20:08:16 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346894; bh=M9Xa2CtYpuFTeuhWXNdpWwBNQXqDLXYuLTUjZ8Me9zE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IrkvB/dpINuqS7nPO04UTamdzmjsDNYQ4850N8P1MNQXezbt9vSeiZ/ojJrd2ZoD9 veGYOdA6FIHJxoPLXiZcaaIR0lK6lq3J0WE1DfIwmkk+aMsOex3bPnuIKbub6aZEyx Edr8pSQbl1YXLuWMCbQM3uqvtmIVgEI8wReJj7ug7nk4kpSviv8+VTwwxFmR3Ty4Kf sdUaIF0+ctL+i3zevx47kyecSjDmhegUNjZFkFFCTX2UtUhrIXQxKCyfukSuiYtwUu U8pBnoYOnFgjiiaYVIqbsgPdhGy81l9gA9hod9wTtB5tgnI/UzA3Mi54C5NW7Eb84K x3GstUZUqKjqA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7DEBD6777A; Wed, 27 Aug 2025 20:08:14 -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 c6w27XOOtclr; Wed, 27 Aug 2025 20:08:14 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346889; bh=/PHA0blrRqE3o9w5NXIdIF8pcJhDrUbb/RZ1Nx3o9zg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U0uCZLYBN35mThLnbLHoMXNhNN75IEX4EBwJO7XfW+SEL3vIWjrISRe/ddVJSIEBt 9fMzUL0Yw5mvWthFjPpniGujJLlr8mkYz4A7bq8+pDbiToFXH93dm3R44I3TP0wyw5 9Ou7Uuwa8Um7hbGfhJUY5DE959VL0F+WX4uCcJAohzv02LtC+RwqDtt1oLCI1i1AYv WC5O78CoGNwkc8QMxPj5k+JaG+7qbN4x0xmctIkmS31vnb3LaK6Da+h4X/Z9hw/sGq xCcw/LuQkuHmFu7sW9+TlWuE2n7X5wn1rzO/QzNvfvGq//5L4svN9aJNroX7tlsxXD HT6Uvi2e6lUkA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id F1531677B6; Wed, 27 Aug 2025 20:08:08 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 27 Aug 2025 20:07:19 -0600 Message-ID: <20250828020732.981415-17-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: 4D6L4UCVZA3RWJOFKDEHTXHEIIC3VXNQ X-Message-ID-Hash: 4D6L4UCVZA3RWJOFKDEHTXHEIIC3VXNQ 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 16/20] fdt: Add a command to show reserved-memory regions 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 'fdt reserved' subcommand that displays all reserved memory regions defined in the device tree's /reserved-memory node. This command provides a formatted table showing the ID, name, start address, and size of each reserved memory region. Avoid a conflict with the existing 'fdt resize' command. Update the docs and add a test. Co-developed-by: Claude Signed-off-by: Simon Glass --- cmd/fdt.c | 7 ++++++- doc/usage/cmd/fdt.rst | 26 ++++++++++++++++++++++++++ test/cmd/fdt.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/cmd/fdt.c b/cmd/fdt.c index 4aedac6116e..7fe0d9dc22c 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -768,8 +768,12 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_FAILURE; } #endif + /* print reserved memory regions */ + else if (strncmp(argv[1], "rese", 4) == 0) { + fdt_print_reserved(working_fdt); + /* resize the fdt */ - else if (strncmp(argv[1], "re", 2) == 0) { + } else if (strncmp(argv[1], "re", 2) == 0) { uint extrasize; if (argc > 2) extrasize = hextoul(argv[2], NULL); @@ -902,6 +906,7 @@ U_BOOT_LONGHELP(fdt, #endif "fdt move - Copy the fdt to and make it active\n" "fdt resize [] - Resize fdt to size + padding to 4k addr + some optional if needed\n" + "fdt reserved - Print reserved-memory regions\n" "fdt print [] - Recursive print starting at \n" "fdt list [] - Print one level starting at \n" "fdt get value [] - Get and store in \n" diff --git a/doc/usage/cmd/fdt.rst b/doc/usage/cmd/fdt.rst index 71a9fc627e5..2fbb50e5013 100644 --- a/doc/usage/cmd/fdt.rst +++ b/doc/usage/cmd/fdt.rst @@ -12,6 +12,7 @@ Synopsis :: fdt addr [-cq] [addr [len]] + fdt reserved Description ----------- @@ -48,6 +49,22 @@ If the `len` argument is provided, then the device tree is expanded to that size. This can be used to make space for more nodes and properties. It is assumed that there is enough space in memory for this expansion. +fdt reserved +~~~~~~~~~~~~ + +This command prints all reserved memory regions defined in the device tree's +`/reserved-memory` node. The output shows a formatted table with the following +columns: + +- **ID**: Sequential number for each region +- **Name**: Node name of the reserved memory region +- **Start**: Start address of the reserved memory region in hexadecimal +- **Size**: Size of the reserved memory region in hexadecimal + +If no `/reserved-memory` node exists in the device tree, the command will +display an appropriate message. This command is useful for debugging memory +layout issues and verifying that reserved memory regions are properly defined. + Example ------- @@ -67,6 +84,15 @@ address and expand it to 0xf000 in size:: => md 10000 4 00010000: edfe0dd0 00f00000 78000000 7c270000 ...........x..'| +Print all reserved memory regions:: + + => fdt reserved + ID Name Start Size + ---------------------------------------------------------------- + 0 secmon@1f000000 0x000000001f000000 0x0000000001000000 + 1 atf@40000000 0x0000000040000000 0x0000000000200000 + 2 linux,cma 0x0000000050000000 0x0000000008000000 + Return value ------------ diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index 9de79870c40..10a2f309a45 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -1464,3 +1464,43 @@ static int fdt_test_apply(struct unit_test_state *uts) return 0; } FDT_TEST(fdt_test_apply, UTF_CONSOLE); + +/* Test 'fdt reserved' reading reserved-memory nodes */ +static int fdt_test_reserved(struct unit_test_state *uts) +{ + struct fdt_header *old_working_fdt; + char fdt[8192]; + ulong addr; + + if (!IS_ENABLED(CONFIG_SANDBOX)) + return -EAGAIN; + + /* Save the original working_fdt */ + old_working_fdt = working_fdt; + + /* Set working_fdt to control FDT (sandbox has reserved memory) */ + working_fdt = (struct fdt_header *)gd->fdt_blob; + + ut_assertok(run_command("fdt reserved", 0)); + + /* Just verify we get the header */ + ut_assert_nextlinen("ID"); + ut_assert_nextlinen("------"); + + /* Verify we get a tcg_event_log entry with correct address/size */ + ut_assert_nextline("0 tcg_event_log 0x100000 0x2000 "); + + /* Test with FDT that has no reserved-memory node */ + ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr)); + ut_assertok(run_command("fdt reserved", 0)); + ut_assert_nextlinen("ID Name Start Size"); + ut_assert_nextline("----------------------------------------------------------------"); + ut_assert_nextline("No /reserved-memory node found in device tree"); + ut_assert_console_end(); + + /* Restore the original working_fdt */ + working_fdt = old_working_fdt; + + return 0; +} +FDT_TEST(fdt_test_reserved, UTF_CONSOLE);