[U-Boot] [PATCH] efi_loader: don't allocate unusable RAM

Stephen Warren swarren at wwwdotorg.org
Tue Jul 31 19:44:12 UTC 2018


From: Stephen Warren <swarren at nvidia.com>

Some boards define a maximum usable RAM top that's more restrictive than
the ranges defined by U-Boot's memory bank definitions[1]. In this case,
the unusable RAM isn't mapped in the page tables, and so the EFI code must
not attempt to allocate RAM from outside the usable regions. Fix
efi_find_free_memory() to detect when max_addr is unconstrained or out of
range, and substitue a valid value.

[1] For example, when some peripherals can't access RAM above 4GiB, it's
simplest to force U-Boot's ram_top to a smaller value to avoid dealing
with this issue more explicitly. However, the RAM bank definitions still
describe the unusable RAM so that the booted OS has access to it, since
the OS can typically deal with such restrictions in a more complex
manner.

Fixes: aa909462d018 "efi_loader: efi_allocate_pages is too restrictive"
Cc: Heinrich Schuchardt <xypron.glpk at gmx.de>
Cc: Alexander Graf <agraf at suse.de>
Signed-off-by: Stephen Warren <swarren at nvidia.com>
---
 lib/efi_loader/efi_memory.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 967c3f733e4c..5064ff2ccbe8 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -251,6 +251,9 @@ static uint64_t efi_find_free_memory(uint64_t len, uint64_t max_addr)
 {
 	struct list_head *lhandle;
 
+	if ((max_addr == -1ULL) || (max_addr > gd->ram_top))
+		max_addr = gd->ram_top;
+
 	list_for_each(lhandle, &efi_mem) {
 		struct efi_mem_list *lmem = list_entry(lhandle,
 			struct efi_mem_list, link);
-- 
2.18.0



More information about the U-Boot mailing list