From patchwork Tue Sep 2 15:21:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 182 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=1756826560; bh=7Ny49F4cxoxID6l4I7DE0VCjZvbhf4sUP8XTQ8uhTs0=; 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=SG/mu9QKDzMH7WjyHaE/z8vfqa+ugp70dLijHfWEGvV32JUy2zKkPhN6+HsnnaDRZ nPmqBtUF28s1cmtNBJmjMZMI11R4V7YB5BL/vgyc/KrIPGnm5bmX6dUmfXNQGQVaLy 3AmvLJselwuqaBAWXTh0s7aGu/6DoVeYjV2eS36KXmCn2rCAhkX1JRHvbZwfF0vFdW e01EY1Pbza8mMG6rdu36xMS2WhAG3sVE43JA8kak/yn+rPKXSmXUCuPSO19EPQQkXu n/OM5hICwFihtPmknfsyvHS9q3+4xuPnUg2NeXGF+h6lVOe1cJQfBSnxoLfwaqSq2z 8+eH0Uq/yaWaQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 22C92678CB for ; Tue, 2 Sep 2025 09:22:40 -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 TS-9GLuZQetZ for ; Tue, 2 Sep 2025 09:22:40 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756826558; bh=7Ny49F4cxoxID6l4I7DE0VCjZvbhf4sUP8XTQ8uhTs0=; 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=IcTarRndWvA/Wvm5ZRqnDf7Ox8ebwJVCucb8qDyIADOvvBbby03i+oYHeNmyZD7AH ntiGdMTz5nbQKJVp1utY7NatFYYz8zg8yIbCEdwoRz7ezW2G7TQb9pydw3qTxN0e3/ 4uDP3yPZbMrJlnMo4NwQVO77xzusxDzlLW/d24H7FlDzhSMd6jAvXpdeIRc8P01oPx VU4HCEeKMQou4WeYDbA8vZzFq1jh8H1LM7BsFVNJeZ6InsxcS1IioqGjjHY/qSpmfn 9TTPVDDUNYf1CcSQk9uan11xFF2G3m4Asb309q4pnbPvtUexgG+PKGiej5dCbjzf17 4KzOZVdJh+C6g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1D1E2678E9 for ; Tue, 2 Sep 2025 09:22:38 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756826555; bh=EnmhVPAqzoVt3SY/HCT69JokzOg2BKgzwu5ScK0bz0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iprgniwi5ledal0sikveOZ1gygWKVmYFsdeLDwqsnczT4cgfuYg5/+9RJTZM/HDWQ IdawM70osyO47wrSFeuuAiDjnwKg2qdGDLe3idOLuThCa2T7jGMQbnoPjtNMKRqTwX 1mntAfKXZC3SvRLacARNon4qzIerNasgyoZQ8IyoEO/WOD/VuXCnOgRxS7xpSUVjea CF4qYgoqePQ9wAcvxuvmFmpl0eMBL3SettTT3u1aH6l3bIMDlep7iW98RFU3l6AD+x uvC4hxzNKncpsIdmebC2VHqN7OqlNZmUrzirKSQ7IXM/BmqnRb/b5kSmfPYmMZ0zzs RirpA0mK3QgKQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6B302678CB; Tue, 2 Sep 2025 09:22:35 -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 ZpET25UOC1Y6; Tue, 2 Sep 2025 09:22:35 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756826553; bh=I1XwoZmykTsanboPJ8oRl+K3SuVXsZNsOLEcInPvZH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RtTl3tS1KtGwvWnoEO1FdXpe4D9Pu75dfbouZB7KZvel1J/j0DLwUqaR9RP0GiQSo aCS78juVK9IbDQCpa/SK6qvP99j849ROTkmZtsnOXTcto7yYRFx8D8/s4/Tovlf9Li TuIqUwXFtGu+pMr+NKCzi3EhbWf5D0w6Si4L+HXlSnz49kUYoDuva/wAnpFz3NCXGf CBZbRuOBPEDBH2STE4mFDQpjpwkXHornnYSniNcxYr1W7dzgbknZ/TPbt/vcy8GWLb kjtbWpUFXa+MZc6v44ZdXpofWB5Voj6jaaBYZ6BFqevJoDxqyVJe2sTXazcuReTHVO n+Ufu+TOxoyUQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id B83845FE1B; Tue, 2 Sep 2025 09:22:32 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 2 Sep 2025 09:21:43 -0600 Message-ID: <20250902152158.2285264-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250902152158.2285264-1-sjg@u-boot.org> References: <20250902152158.2285264-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: X5ANWX2ZM5PI2L7ADWB4PE7IGWKIIXZZ X-Message-ID-Hash: X5ANWX2ZM5PI2L7ADWB4PE7IGWKIIXZZ 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 11/18] 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 | 51 +++++++++++++++++++-- doc/usage/cmd/efidebug.rst | 92 +++++++++++++++++++++++++++++++++++++- 2 files changed, 139 insertions(+), 4 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index f88da42c2c4..627045a295e 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -655,6 +656,26 @@ 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 +697,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; + + argc--; + argv++; + while (argc > 0 && *argv[0] == '-') { + if (!strcmp(argv[0], "-s")) { + sort_by_addr = true; + } else { + printf("Unknown option: %s\n", argv[0]); + return CMD_RET_USAGE; + } + argc--; + } + + if (argc > 0) { + printf("Too many arguments\n"); + return CMD_RET_USAGE; + } if (IS_ENABLED(CONFIG_EFI_APP)) { uint key, version; @@ -692,6 +732,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 +1640,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 +1852,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::