]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: correct efi_add_known_memory()
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Mon, 12 Nov 2018 17:55:24 +0000 (18:55 +0100)
committerAlexander Graf <agraf@suse.de>
Sun, 2 Dec 2018 20:59:37 +0000 (21:59 +0100)
If a memory bank is not EFI_PAGE_SIZE aligned efi_add_known_memory() the
number of memory pages may be incorrectly calculated.

We have to round up the start address and to round down the end address
to determine which complete pages are provided by the memory bank.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
lib/efi_loader/efi_memory.c

index 1ffcf92eb2e04eb12cb98c255af2474435008590..f225a9028c5d22296f7be6e0d8151e5756ca71e5 100644 (file)
@@ -555,13 +555,21 @@ __weak void efi_add_known_memory(void)
 
        /* Add RAM */
        for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
-               u64 ram_start = gd->bd->bi_dram[i].start;
-               u64 ram_size = gd->bd->bi_dram[i].size;
-               u64 start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
-               u64 pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
+               u64 ram_end, ram_start, pages;
 
-               efi_add_memory_map(start, pages, EFI_CONVENTIONAL_MEMORY,
-                                  false);
+               ram_start = gd->bd->bi_dram[i].start;
+               ram_end = ram_start + gd->bd->bi_dram[i].size;
+
+               /* Remove partial pages */
+               ram_end &= ~EFI_PAGE_MASK;
+               ram_start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
+
+               if (ram_end > ram_start) {
+                       pages = (ram_end - ram_start) >> EFI_PAGE_SHIFT;
+
+                       efi_add_memory_map(ram_start, pages,
+                                          EFI_CONVENTIONAL_MEMORY, false);
+               }
        }
 }