Mathias Krause (minipli@googlemail.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/18350
-gerrit
commit 0372aef6b5fbc8121ca6fcfde96b9281c89bd372 Author: Mathias Krause minipli@googlemail.com Date: Sun Feb 12 13:50:48 2017 +0100
libpayload: multiboot - support meminfo flag
Some simple implementation of the MultiBoot protocol may not pass a memory map (MULTIBOOT_FLAGS_MMAP missing in the flags) but just the two values for low and high memory, indicated by the MULTIBOOT_FLAGS_MEMINFO flag.
Support those kind of boot loaders too, instead of falling back to the hard-coded values in lib_get_sysinfo().
Tested with a multiboot enhanced version of FILO.
Change-Id: I22cf9e3ec0075aff040390bd177c5cd22d439b81 Signed-off-by: Mathias Krause minipli@googlemail.com --- payloads/libpayload/arch/x86/multiboot.c | 55 +++++++++++++++++++------- payloads/libpayload/include/multiboot_tables.h | 1 + 2 files changed, 41 insertions(+), 15 deletions(-)
diff --git a/payloads/libpayload/arch/x86/multiboot.c b/payloads/libpayload/arch/x86/multiboot.c index 5fff453..0a3785f 100644 --- a/payloads/libpayload/arch/x86/multiboot.c +++ b/payloads/libpayload/arch/x86/multiboot.c @@ -34,8 +34,28 @@ extern unsigned long loader_eax; extern unsigned long loader_ebx;
+static int mb_add_memrange(struct sysinfo_t *info, unsigned long long base, + unsigned long long size, unsigned int type) +{ + if (info->n_memranges >= SYSINFO_MAX_MEM_RANGES) + return -1; + +#if IS_ENABLED(CONFIG_LP_MEMMAP_RAM_ONLY) + /* 1 == normal RAM. Ignore everything else for now */ + if (type != 1) + return 0; +#endif + + info->memrange[info->n_memranges].base = base; + info->memrange[info->n_memranges].size = size; + info->memrange[info->n_memranges].type = type; + info->n_memranges++; + + return 0; +} + static void mb_parse_mmap(struct multiboot_header *table, - struct sysinfo_t *info) + struct sysinfo_t *info) { u8 *start = (u8 *) phys_to_virt(table->mmap_addr); u8 *ptr = start; @@ -45,25 +65,28 @@ static void mb_parse_mmap(struct multiboot_header *table, while(ptr < (start + table->mmap_length)) { struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr;
-#if IS_ENABLED(CONFIG_LP_MEMMAP_RAM_ONLY) - /* 1 == normal RAM. Ignore everything else for now */ - - if (mmap->type == 1) { -#endif - info->memrange[info->n_memranges].base = mmap->addr; - info->memrange[info->n_memranges].size = mmap->length; - info->memrange[info->n_memranges].type = mmap->type; - - if (++info->n_memranges == SYSINFO_MAX_MEM_RANGES) - return; -#if IS_ENABLED(CONFIG_LP_MEMMAP_RAM_ONLY) - } -#endif + if (mb_add_memrange(info, mmap->addr, mmap->length, mmap->type)) + return;
ptr += (mmap->size + sizeof(mmap->size)); } }
+static void mb_parse_meminfo(struct multiboot_header *table, + struct sysinfo_t *info) +{ + unsigned long long mem_low = table->mem_lower * 1024ULL; + unsigned long long mem_high = table->mem_higher * 1024ULL; + + info->n_memranges = 0; + + if (mem_low) + mb_add_memrange(info, 0, mem_low, 1); + + if (mem_high) + mb_add_memrange(info, 1 * 1024 * 1024, mem_high, 1); +} + static void mb_parse_cmdline(struct multiboot_header *table) { extern int main_argc; @@ -95,6 +118,8 @@ int get_multiboot_info(struct sysinfo_t *info)
if (table->flags & MULTIBOOT_FLAGS_MMAP) mb_parse_mmap(table, info); + else if (table->flags & MULTIBOOT_FLAGS_MEMINFO) + mb_parse_meminfo(table, info);
if (table->flags & MULTIBOOT_FLAGS_CMDLINE) mb_parse_cmdline(table); diff --git a/payloads/libpayload/include/multiboot_tables.h b/payloads/libpayload/include/multiboot_tables.h index ac27f8a..d72d1d6 100644 --- a/payloads/libpayload/include/multiboot_tables.h +++ b/payloads/libpayload/include/multiboot_tables.h @@ -35,6 +35,7 @@ #define MULTIBOOT_MAGIC 0x2BADB002UL #define MULTIBOOT_FLAGS_MMAP (1 << 6) #define MULTIBOOT_FLAGS_CMDLINE (1 << 2) +#define MULTIBOOT_FLAGS_MEMINFO (1 << 0) struct multiboot_header { u32 flags; u32 mem_lower;