From patchwork Thu Aug 28 02:07:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 161 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=1756346899; bh=LH6fwMpswn7xHWfOcHWu0XuVJ3/zZn9KFmK+v+xlsIE=; 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=LPZoUYCCfBZNIZGuioMYQsYDMxarvl4veSDBw4RV7in2WAkpD1yZyn2F6vMfx9mVZ L8WJ4vh2ROg+m09XvZxTL3QAYhjLbBytxuzannSJ28nZjoE7DPlGMrSNxVgoj0hyBf aeeP9is21uwNK91mirgF9mMAs1kNkGbB4NBChADmPSKyMR+bBkDzEZKvDyHvsgcd// jpPAB4VrgXDj+w5Y8RNHq0yEZkWcRbtCwvJlrQ155quxrYfn/ALFIESCtTo9TJ4b+e r9ZX12uS9UqShXz48f9MOlxI3VOPxgSAovhy8pI6+7fsAjrljcWDdRc4eaQHmaygEA HrQ6e0UYUHS4w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 41B496783A for ; Wed, 27 Aug 2025 20:08:19 -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 Kl7TUsnKlZ7K for ; Wed, 27 Aug 2025 20:08:19 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346897; bh=LH6fwMpswn7xHWfOcHWu0XuVJ3/zZn9KFmK+v+xlsIE=; 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=E7iwJOamlJpEpyicUNE7inOenJwjx1xh0q5vT/D2ITxnu7tP3y337WWsXnFDZwoz4 xQLMXN++IucOYaNr+AIY5FjMFruW4TZR47zvIWIb5j826Pz7AS7mGuHNxtHX5CsFwh cRstIVK1F9dbjU4CfWxaBJiV1TaRMxDnHXhp4WHfyMElVlL+wOKsF5nzftK/Q3+kTt Vxc6pR/3ohzsUDMQQFav+4e82Tw7wCnUxboNpEoKzNvktByEx8zGuOHP6QtpfR73Du 2ZXpso8U6APauTowe5KARyS+2uIQc1QFef6iHA76FkuT7uJS7xsK5xGJ2IEBe93x9b /KqBBiSVRc+8Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A9B3F6777A for ; Wed, 27 Aug 2025 20:08:17 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756346894; bh=xbtyvgrMVc69xROoLfVr4egJjyUTRs5l0poKwA46nkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ShVoW9TZjGAdeJiqkQ4gTT/2S33dvwWkJEDsXlpTDG1UzIaIjgbQevYzfF//nhsus KwnjRWKk8K5lh1CTlwUlW8zueAUI4dtAHWkPX2+WPjYYKy3Lz26ngeYeCYhHewNqzo Mm1w7PqF60ympA/i0I5H75eVONZg+pB3jhfKBOfsyXEE10vm0+RHW7U3LrZydR1Y1u LH74kOvqTWfDB3hwZGuY82imh5n7H4Bzy022z2BrVJ2lQIAYwDmiJUOdfcpcWDiBF/ 012OZWxY9niJuJFszTESJrYzbL6OENgCqwsZMlFGcx8uTJUj0QmMVXFDq9/U/T3VS1 bCnkfE8eQlTaw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8FDEC6777F; 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 2M4SXjAOchBb; 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=1756346891; bh=BbP7B5ZkoVkx6QFQDvaSNoJy0+VNnns7FFdhYwE7P00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YqzQUqSbYiETNQrqBxKyJ+25rO2xF6yUShXAvU9OQRA8lbfheNWMD77077pGg4qiA 3RTDQgHEhq5naGXuq0hOrQFEUFh3+uqU0JHilOAe11QfW6J4Y1UnzIlaa0dMd1SXh1 LiegbKoDE0bOUc2EjU/r7yaztuG6jYrlW15CHMjv0eDwcbpN85Fmj3e1XWJBRquMTn rkqplOjS++2JZMRzODOsfdvnctC5d5wY+QoWiGGVVCzgttT7pnXMSY2bWQurp/JaOm 0/0FhMSJaGsUc5ZQz2oVJZGzknCkoEHE32tmZ5uHPFnQo7xDK6yWuceYfHo5rnbeQn KpjbXoM8PlcPA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 08E766783A; Wed, 27 Aug 2025 20:08:10 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 27 Aug 2025 20:07:21 -0600 Message-ID: <20250828020732.981415-19-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: CHNKHGA72WEXLLRMTRTGBY65EMGFFUN2 X-Message-ID-Hash: CHNKHGA72WEXLLRMTRTGBY65EMGFFUN2 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 18/20] fdt: Provide a command to sync the reserve-memory node 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 command to sync reserved-memory with EFI's version of reserved memory. Co-developed-by: Claude Signed-off-by: Simon Glass --- cmd/efi.c | 22 ++++++++++++++++++++-- doc/usage/cmd/efi.rst | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/cmd/efi.c b/cmd/efi.c index c59219ddf01..c329e6eede8 100644 --- a/cmd/efi.c +++ b/cmd/efi.c @@ -198,9 +198,26 @@ static int do_efi_tables(struct cmd_tbl *cmdtp, int flag, int argc, return 0; } +static int do_efi_memsync(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + bool verbose = false; + int ret; + + if (argc > 1 && !strcmp(argv[1], "-v")) + verbose = true; + + ret = efi_mem_reserved_sync(working_fdt, verbose); + if (ret < 0) + return CMD_RET_FAILURE; + + return 0; +} + static struct cmd_tbl efi_commands[] = { U_BOOT_CMD_MKENT(image, 1, 1, do_efi_image, "", ""), U_BOOT_CMD_MKENT(mem, 1, 1, do_efi_mem, "", ""), + U_BOOT_CMD_MKENT(memsync, 2, 1, do_efi_memsync, "", ""), U_BOOT_CMD_MKENT(tables, 1, 1, do_efi_tables, "", ""), }; @@ -223,9 +240,10 @@ static int do_efi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } U_BOOT_CMD( - efi, 3, 1, do_efi, + efi, 4, 1, do_efi, "EFI access", "image Dump loaded-image info\n" "mem [all] Dump memory information [include boot services]\n" - "tables Dump tables" + "memsync [-v] Sync EFI memory map with DT reserved-memory\n" + "tables Dump tables" ); diff --git a/doc/usage/cmd/efi.rst b/doc/usage/cmd/efi.rst index e5d8913c94b..f91a2bd7bec 100644 --- a/doc/usage/cmd/efi.rst +++ b/doc/usage/cmd/efi.rst @@ -14,6 +14,7 @@ Synopsis efi image efi mem [all] + efi memsync [-v] efi tables Description @@ -69,6 +70,24 @@ Attributes Shows a code for memory attributes. The key for this is shown below the table. +efi memsync +~~~~~~~~~~~ + +This synchronizes EFI reserved memory regions with the device tree's +reserved-memory nodes. When running as an EFI application, U-Boot can access +the EFI memory map to identify regions that EFI considers reserved (such as +runtime services code/data, ACPI tables, etc.). This command compares these +EFI reserved regions with the device tree's /reserved-memory nodes and adds +any missing regions to prevent Linux from using memory that EFI has reserved. + +Use the optional '-v' flag for verbose output showing the detailed memory +map analysis. Without this flag, only errors are displayed. + +This is useful for ensuring proper memory management when transitioning from +EFI boot services to the operating system, particularly in complex firmware +environments where EFI may have reserved memory regions not explicitly +documented in the device tree. + efi tables ~~~~~~~~~~ @@ -234,3 +253,20 @@ Example 000000001fb7e000 eb9d2d30-2d88-11d3-9a16-0090273fc14d EFI_GUID_EFI_ACPI1 000000001fb7e014 8868e871-e4f1-11d3-bc22-0080c73c8881 ACPI table 000000001e654018 dcfa911d-26eb-469f-a220-38b7dc461220 (unknown) + + => efi memsync + Regions added: 2 + + => efi memsync -v + Comparing EFI memory-map with reserved-memory + EFI Memory Map Analysis: + ID Type Start End In DT? + ------------------------------------------------------------------------ + 0 EFI_RUNTIME_SERVICES_CODE 0x001f9ef000 0x001faef000 no -> adding + 1 EFI_ACPI_RECLAIM_MEMORY 0x001fb6f000 0x001fb7f000 no -> adding + 2 EFI_ACPI_MEMORY_NVS 0x001fb7f000 0x001fbff000 yes + Regions added: 2 + Reserved memory regions: + 0 tcg_event_log 0x100000 0x2000 + 1 efi-runtime-services-code@1f9ef000 0x1f9ef000 0x100000 + 2 efi-acpi-reclaim@1fb6f000 0x1fb6f000 0x10000