summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorAlexander Graf <agraf@suse.de>2018-04-06 10:40:51 +0300
committerAlexander Graf <agraf@suse.de>2018-04-06 10:40:53 +0300
commit806d2fa8e3c4ebaa1a2b1854ee4569ccc056d238 (patch)
treecb0e0d7c89b80fc4524ea9e82772cd7516bb9198 /cmd
parent61a5ced6ad9376a0755ea2a920667e3a9072990c (diff)
downloadu-boot-806d2fa8e3c4ebaa1a2b1854ee4569ccc056d238.tar.xz
efi_loader: Respect DT reserved regions
With legacy boot (booti, bootz), people can declare memory regions as reserved using device tree memory reservations. This feature is some times used to indicate memory regions that should not be touched. Since in a UEFI world, the DT memory reservations do not get honored, let's copy them into the UEFI memory map so everyone has a coherent view of the world and we give people the chance to add reservations on demand. Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/bootefi.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 2a31a914cd..5a2a81005f 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -178,6 +178,27 @@ static efi_status_t efi_run_in_el2(EFIAPI efi_status_t (*entry)(
}
#endif
+/* Carve out DT reserved memory ranges */
+static efi_status_t efi_carve_out_dt_rsv(void *fdt)
+{
+ int nr_rsv, i;
+ uint64_t addr, size, pages;
+
+ nr_rsv = fdt_num_mem_rsv(fdt);
+
+ /* Look for an existing entry and add it to the efi mem map. */
+ for (i = 0; i < nr_rsv; i++) {
+ if (fdt_get_mem_rsv(fdt, i, &addr, &size) != 0)
+ continue;
+
+ pages = ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT;
+ efi_add_memory_map(addr, pages, EFI_RESERVED_MEMORY_TYPE,
+ false);
+ }
+
+ return EFI_SUCCESS;
+}
+
static efi_status_t efi_install_fdt(void *fdt)
{
bootm_headers_t img = { 0 };
@@ -199,6 +220,11 @@ static efi_status_t efi_install_fdt(void *fdt)
return EFI_LOAD_ERROR;
}
+ if (efi_carve_out_dt_rsv(fdt) != EFI_SUCCESS) {
+ printf("ERROR: failed to carve out memory\n");
+ return EFI_LOAD_ERROR;
+ }
+
/* Link to it in the efi tables */
ret = efi_install_configuration_table(&efi_guid_fdt, fdt);
if (ret != EFI_SUCCESS)