efi: fdt: Provide a command to sync the reserve-memory node

Provide a command to sync reserved-memory with EFI's version of reserved
memory.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-08-27 15:44:57 -06:00
parent eb85d76a42
commit 8132f56189
2 changed files with 62 additions and 2 deletions

View File

@@ -213,9 +213,32 @@ 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 (!is_app() || IS_ENABLED(CONFIG_X86))
return CMD_RET_FAILURE;
if (argc > 1 && !strcmp(argv[1], "-v"))
verbose = true;
if (!working_fdt) {
printf("No working FDT set\n");
return CMD_RET_FAILURE;
}
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, "", ""),
};
@@ -238,9 +261,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"
);

View File

@@ -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