[U-Boot] [PATCH v2 07/11] sandbox: Map host memory for efi_loader

Alexander Graf
2018-06-14T18:22:28Z

With efi_loader we do not control payload applications, so we can not
teach them about the difference between virtual and physical addresses.

Instead, let's just always map host virtual addresses in the efi memory
map. That way we can be sure that all memory allocation functions always
return consumable pointers.

Signed-off-by: Alexander Graf <agraf@suse.de>

---

v1 -> v2:

- only compile efi_add_known_memory if efi_loader is enabled
---
arch/sandbox/cpu/cpu.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c
index cde0b055a6..23d8b70648 100644
--- a/arch/sandbox/cpu/cpu.c
+++ b/arch/sandbox/cpu/cpu.c
@@ -5,6 +5,7 @@
#define DEBUG
#include <common.h>
#include <dm.h>
+#include <efi_loader.h>
#include <errno.h>
#include <linux/libfdt.h>
#include <os.h>
@@ -177,3 +178,22 @@ void longjmp(jmp_buf jmp, int ret)
while (1)
;
}
+
+#ifdef CONFIG_EFI_LOADER
+
+/*
+ * In sandbox, we don't have a 1:1 map, so we need to expose
+ * process addresses instead of U-Boot addresses
+ */
+void efi_add_known_memory(void)
+{
+ u64 ram_start = (uintptr_t)map_sysmem(0, gd->ram_size);
+ u64 ram_size = gd->ram_size;
+ u64 start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
+ u64 pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
+
+ efi_add_memory_map(start, pages, EFI_CONVENTIONAL_MEMORY,
+ false);
+}
+
+#endif
--
2.12.3