From patchwork Thu Aug 28 22:16: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: 166 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=1756419466; bh=butLb6FUxrc1ttTlkNzEw0T4j3j0fpuHfIud2/BKdMg=; 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=d9xlqQzHJqy+ixJwyZofgMwyHKlP9DaDARGnBgNuZLcSUdupRlFgi6vljvw900lq9 ZNQbsj4uVhTuBhrluKZyFNcNIhgZtOWXNHLS+tr9iF8AGxsX82wZVVXK0IJFNXTYbn mxTYGwhV3lce61pBNZWOXagoDBWaJsEUKKjHOKPYWmkSvClU4IQrpMoDRp9QwQV1Zt kLxA0cp5CKxCTMtMACXLeS1SnyYRw8DDXpDf1KSjYYA2epJzoAF3HLwxGkxpyOIj7e FQFRhvc9OVKhcsoGnwgxuzGoZhDsOWD1W6vAWcbnNs5wYi/t+P3gz1cixjvM7k+LnP KtGu+jkbH9KEw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2A7BF67853 for ; Thu, 28 Aug 2025 16:17:46 -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 JqXcnmeN1ovP for ; Thu, 28 Aug 2025 16:17:46 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756419464; bh=butLb6FUxrc1ttTlkNzEw0T4j3j0fpuHfIud2/BKdMg=; 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=r/VTUIDPPWWFwP2nMPZHy4iStp/P8a7h6QrhgIYq9CnCIPnMjE0V0YuzUS750gtPk gKtEKJGdt+/8yTyGSWRjpIheNW0MoNElwOX9mzL5sFOY0DmwW1EkVfXAQUwKVqfp9X nhDBvUPlcYAtpK7IFsl1d1xOHmy2maqBqTcl2goFpHXXpe5p6veloktnTJu1wWsceo HSvdD1lOhk1wV49fHZ2v6y0+YFnTGYrG62sFoZkl528W2kYu/wJpMNlRXuMtWlE6AY +kpPIyGSopqPHFFYLKDqZSRCvYa8EH9iWvDU6GQ/PNIDwAlkX570TV61m1uHwn7sQJ 8ZQk3u2ApEJ9g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2A87D6783F for ; Thu, 28 Aug 2025 16:17:44 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756419461; bh=kEJZUJ5oP4yKzMvCdtgrFqREXV4pPoA7js3DxpJn8ao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qsRoN2eniXhRuvUM0kZbjHJkdFbJWWu5iXXduRlbbC84SUWlytkAfa364/3pOS/hU znCUKzZs4LPBN/wrFSSXgKmzS4h52OQ2rmEKE2gg6FdYLkNy9sn7JFpalgIUpFUo3e 2LvqxzCVr3z0LAU8DySycppS4gpzuWHOmlzIpVJXqn3TEvd1Pvo60xq5jbdn1WtQXA RY3mRY4DcoPwc612+Wm73C2W7NtMaSPHWNz4KTgOYX9L+ex6v4IHA/EG5uwDgBqX2n Q5JBhW42pgt4+5+WtRgaKW5hZBkyg6Z0CDb680SyjIZ2Y4HNnpE+aA4a+TEWFHG4Nc aVCNdxqR3lJuA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5F0DD67764; Thu, 28 Aug 2025 16:17:41 -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 uP1To7l5Ltmb; Thu, 28 Aug 2025 16:17:41 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756419459; bh=wsh07aTKHJWSgNLkZWMd1K3DXOl0fVqp+ndk9F0axHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PVsPpOw1WXFhR5DHaQfsvGZhudkh9+LgQhLbo3teOLUreqeaT/2aFl7+oAO+OsU4D XTqT4xwFK51neJYST+EVQpYeqzuDowbYUq2GOdUeb44FQBxoKBpbIc/IpmkMkNZKVH ws0rYfCNfENqlFjE5gRNY0gaP98l8Z1DcQYFzbKiInevWzB60Rih2++lHyQU83okLI VdV54VK/t/+LjaKThYkqLaUm0BclMktV3TBuyRkfpqBJF3HAgIAfrNeD4ix2xRQ4r3 wa2LCgDQ8RmUSv9oC4JRV+3YD54GvFMgURWhis123RU2XTdbN5ahmxspTSvkIexKDD 4vSY7eH+CSa1w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 8BD9F675BB; Thu, 28 Aug 2025 16:17:39 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 28 Aug 2025 16:16:49 -0600 Message-ID: <20250828221713.3218908-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250828221713.3218908-1-sjg@u-boot.org> References: <20250828221713.3218908-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: R45I7LGRSX3HPK4BYZO23Z6KJQJ26EHE X-Message-ID-Hash: R45I7LGRSX3HPK4BYZO23Z6KJQJ26EHE 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 3/8] doc: efidebug: Support sorting with efidebug memmap 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 Provide a -s option to sort the memory map in order of address. Add documentation while we are here. Also fix an errant extra line before do_efi_show_media() Co-developed-by: Claude Signed-off-by: Simon Glass --- cmd/efidebug.c | 50 +++++++++++++++++++-- doc/usage/cmd/efidebug.rst | 92 +++++++++++++++++++++++++++++++++++++- 2 files changed, 138 insertions(+), 4 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index f88da42c2c4..71b99f9c8d7 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -655,6 +656,25 @@ static void print_memory_attributes(u64 attributes) #define EFI_PHYS_ADDR_WIDTH (int)(sizeof(efi_physical_addr_t) * 2) +/** + * efi_memmap_sort_by_addr() - compare two memory descriptors by address + * + * @a: first memory descriptor + * @b: second memory descriptor + * Return: -1 if a < b, 0 if a == b, 1 if a > b + */ +static int efi_memmap_sort_by_addr(const void *a, const void *b) +{ + const struct efi_mem_desc *desc_a = a; + const struct efi_mem_desc *desc_b = b; + + if (desc_a->physical_start < desc_b->physical_start) + return -1; + else if (desc_a->physical_start > desc_b->physical_start) + return 1; + return 0; +} + /** * do_efi_show_memmap() - show UEFI memory map * @@ -676,6 +696,25 @@ static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int flag, int desc_size, i; efi_status_t eret; int ret; + bool sort_by_addr = false; + int num_entries; + + /* Parse arguments */ + argc--; argv++; /* skip command name */ + while (argc > 0 && argv[0][0] == '-') { + if (!strcmp(argv[0], "-s")) { + sort_by_addr = true; + } else { + printf("Unknown option: %s\n", argv[0]); + return CMD_RET_USAGE; + } + argc--; argv++; + } + + if (argc > 0) { + printf("Too many arguments\n"); + return CMD_RET_USAGE; + } if (IS_ENABLED(CONFIG_EFI_APP)) { uint key, version; @@ -692,6 +731,12 @@ static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int flag, desc_size = sizeof(*map); } + /* Sort entries by address if requested */ + if (sort_by_addr) { + num_entries = map_size / desc_size; + qsort(memmap, num_entries, desc_size, efi_memmap_sort_by_addr); + } + printf("Type Start%.*s End%.*s Attributes\n", EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc); printf("================ %.*s %.*s ==========\n", @@ -1594,7 +1639,6 @@ static int do_efi_test(struct cmd_tbl *cmdtp, int flag, return cp->cmd(cmdtp, flag, argc, argv); } - /** * do_efi_show_media() - show EFI media devices * @@ -1807,8 +1851,8 @@ U_BOOT_LONGHELP(efidebug, " - show UEFI log\n" "efidebug media\n" " - show EFI media devices\n" - "efidebug memmap\n" - " - show UEFI memory map\n" + "efidebug memmap [-s]\n" + " - show UEFI memory map (use -s to sort by address)\n" "efidebug tables\n" " - show UEFI configuration tables\n" #ifdef CONFIG_EFI_BOOTMGR diff --git a/doc/usage/cmd/efidebug.rst b/doc/usage/cmd/efidebug.rst index 5dd68a689a6..8c8a4895197 100644 --- a/doc/usage/cmd/efidebug.rst +++ b/doc/usage/cmd/efidebug.rst @@ -15,6 +15,7 @@ Synopsis efidebug log efidebug media + efidebug memmap [-s] Description ----------- @@ -22,7 +23,7 @@ Description The *efidebug* command provides access to debugging features for the EFI-loader subsystem. -Only two of the subcommands are documented at present. +Only three of the subcommands are documented at present. efidebug log ~~~~~~~~~~~~ @@ -43,6 +44,15 @@ driver subsystem would likely handle the device (e.g., "ahci" for SATA drives, device, which can be useful for debugging boot issues or understanding the system topology. +efidebug memmap +~~~~~~~~~~~~~~~ + +This shows the UEFI memory map, which displays all memory regions and their +types as known to the EFI loader subsystem. This includes information about +memory allocation, reserved regions, and available memory. + +The command supports an optional '-s' flag to sort the memory map entries by +address, making it easier to visualize the memory layout in ascending order. Example ------- @@ -55,6 +65,86 @@ This shows checking the EFI media devices:: efi_media_1 ahci PciRoot(0x0)/Pci(0x3,0x0)/Sata(0x0,0xFFFF,0x0) efi_media_2 pci PciRoot(0x0)/Pci(0x5,0x0) +This shows checking the UEFI memory map, first unsorted and then sorted by +address:: + + => efidebug mem + Type Start End Attributes + ================ ================ ================ ========== + CONVENTIONAL 0000000040000000-0000000044000000 WB + BOOT DATA 0000000044000000-0000000044020000 WB + CONVENTIONAL 0000000044020000-00000000475ee000 WB + BOOT DATA 00000000475ee000-0000000047610000 WB + BOOT CODE 0000000047610000-0000000047647000 WB + BOOT DATA 0000000047647000-0000000047ef2000 WB + BOOT CODE 0000000047ef2000-0000000047ef6000 WB + BOOT DATA 0000000047ef6000-0000000047ff7000 WB + BOOT CODE 0000000047ff7000-0000000047ffa000 WB + BOOT DATA 0000000047ffa000-0000000048000000 WB + CONVENTIONAL 0000000048000000-00000000e0000000 WB + LOADER DATA 00000000e0000000-0000000100000000 WB + CONVENTIONAL 0000000100000000-000000013c278000 WB + LOADER DATA 000000013c278000-000000013c27c000 WB + LOADER CODE 000000013c27c000-000000013c3e0000 WB + ACPI RECLAIM MEM 000000013c3e0000-000000013c3f0000 WB + RUNTIME CODE 000000013c3f0000-000000013c470000 WB|RT + RUNTIME DATA 000000013c470000-000000013c630000 WB|RT + RUNTIME CODE 000000013c630000-000000013c730000 WB|RT + CONVENTIONAL 000000013c730000-000000013dc2a000 WB + BOOT DATA 000000013dc2a000-000000013e9f1000 WB + CONVENTIONAL 000000013e9f1000-000000013e9fe000 WB + BOOT DATA 000000013e9fe000-000000013ea1c000 WB + CONVENTIONAL 000000013ea1c000-000000013ea1e000 WB + BOOT DATA 000000013ea1e000-000000013ea47000 WB + CONVENTIONAL 000000013ea47000-000000013ea48000 WB + BOOT DATA 000000013ea48000-000000013f624000 WB + CONVENTIONAL 000000013f624000-000000013f731000 WB + BOOT CODE 000000013f731000-000000013fc00000 WB + RUNTIME CODE 000000013fc00000-000000013fd90000 WB|RT + RUNTIME DATA 000000013fd90000-000000013ffe0000 WB|RT + CONVENTIONAL 000000013ffe0000-000000013ffff000 WB + BOOT DATA 000000013ffff000-0000000140000000 WB + IO 0000000004000000-0000000008000000 UC|RT + IO 0000000009010000-0000000009011000 UC|RT + => efidebug mem -s + Type Start End Attributes + ================ ================ ================ ========== + IO 0000000004000000-0000000008000000 UC|RT + IO 0000000009010000-0000000009011000 UC|RT + CONVENTIONAL 0000000040000000-0000000044000000 WB + BOOT DATA 0000000044000000-0000000044020000 WB + CONVENTIONAL 0000000044020000-00000000475ee000 WB + BOOT DATA 00000000475ee000-0000000047610000 WB + BOOT CODE 0000000047610000-0000000047647000 WB + BOOT DATA 0000000047647000-0000000047ef2000 WB + BOOT CODE 0000000047ef2000-0000000047ef6000 WB + BOOT DATA 0000000047ef6000-0000000047ff7000 WB + BOOT CODE 0000000047ff7000-0000000047ffa000 WB + BOOT DATA 0000000047ffa000-0000000048000000 WB + CONVENTIONAL 0000000048000000-00000000e0000000 WB + LOADER DATA 00000000e0000000-0000000100000000 WB + CONVENTIONAL 0000000100000000-000000013c278000 WB + LOADER DATA 000000013c278000-000000013c27c000 WB + LOADER CODE 000000013c27c000-000000013c3e0000 WB + ACPI RECLAIM MEM 000000013c3e0000-000000013c3f0000 WB + RUNTIME CODE 000000013c3f0000-000000013c470000 WB|RT + RUNTIME DATA 000000013c470000-000000013c630000 WB|RT + RUNTIME CODE 000000013c630000-000000013c730000 WB|RT + CONVENTIONAL 000000013c730000-000000013dc2a000 WB + BOOT DATA 000000013dc2a000-000000013e9f1000 WB + CONVENTIONAL 000000013e9f1000-000000013e9fe000 WB + BOOT DATA 000000013e9fe000-000000013ea1c000 WB + CONVENTIONAL 000000013ea1c000-000000013ea1e000 WB + BOOT DATA 000000013ea1e000-000000013ea47000 WB + CONVENTIONAL 000000013ea47000-000000013ea48000 WB + BOOT DATA 000000013ea48000-000000013f624000 WB + CONVENTIONAL 000000013f624000-000000013f731000 WB + BOOT CODE 000000013f731000-000000013fc00000 WB + RUNTIME CODE 000000013fc00000-000000013fd90000 WB|RT + RUNTIME DATA 000000013fd90000-000000013ffe0000 WB|RT + CONVENTIONAL 000000013ffe0000-000000013ffff000 WB + BOOT DATA 000000013ffff000-0000000140000000 WB + => This shows checking the log, then using 'efidebug tables' to fully set up the EFI-loader subsystem, then checking the log again::