File 0034-efi_loader-Respect-DT-reserved-regi.patch of Package u-boot-turrisomnia.16979

From e5fba90ec88a1cc5ba81c526ac1e5cde7c58f8c0 Mon Sep 17 00:00:00 2001
From: Alexander Graf <agraf@suse.de>
Date: Fri, 6 Apr 2018 09:40:51 +0200
Subject: [PATCH] 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>
---
 cmd/bootefi.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index b4cb116a0b..3bff152a3f 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -160,6 +160,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;
+}
+
 /*
  * Load an EFI payload into a newly allocated piece of memory, register all
  * EFI objects it would want to access and jump to it.
@@ -215,6 +236,8 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,
 			return -EINVAL;
 		}
 
+		efi_carve_out_dt_rsv(fdt);
+
 		/* Link to it in the efi tables */
 		efi_install_configuration_table(&fdt_guid, fdt);
 
openSUSE Build Service is sponsored by