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>
Reviewed-on: https://review.coreboot.org/18350
Tested-by: build bot (Jenkins)
Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
Mathias Krause 2017-02-12 13:50:48 +01:00 committed by Martin Roth
parent 2b194d9741
commit 898de6111a
2 changed files with 41 additions and 15 deletions

View File

@ -34,8 +34,28 @@
extern unsigned long loader_eax; extern unsigned long loader_eax;
extern unsigned long loader_ebx; 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, 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 *start = (u8 *) phys_to_virt(table->mmap_addr);
u8 *ptr = start; u8 *ptr = start;
@ -45,25 +65,28 @@ static void mb_parse_mmap(struct multiboot_header *table,
while(ptr < (start + table->mmap_length)) { while(ptr < (start + table->mmap_length)) {
struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr; struct multiboot_mmap *mmap = (struct multiboot_mmap *) ptr;
#if IS_ENABLED(CONFIG_LP_MEMMAP_RAM_ONLY) if (mb_add_memrange(info, mmap->addr, mmap->length, mmap->type))
/* 1 == normal RAM. Ignore everything else for now */ return;
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
ptr += (mmap->size + sizeof(mmap->size)); 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;
unsigned long long mem_high = table->mem_higher;
info->n_memranges = 0;
if (mem_low)
mb_add_memrange(info, 0 * MiB, mem_low * KiB, 1);
if (mem_high)
mb_add_memrange(info, 1 * MiB, mem_high * KiB, 1);
}
static void mb_parse_cmdline(struct multiboot_header *table) static void mb_parse_cmdline(struct multiboot_header *table)
{ {
extern int main_argc; extern int main_argc;
@ -95,6 +118,8 @@ int get_multiboot_info(struct sysinfo_t *info)
if (table->flags & MULTIBOOT_FLAGS_MMAP) if (table->flags & MULTIBOOT_FLAGS_MMAP)
mb_parse_mmap(table, info); mb_parse_mmap(table, info);
else if (table->flags & MULTIBOOT_FLAGS_MEMINFO)
mb_parse_meminfo(table, info);
if (table->flags & MULTIBOOT_FLAGS_CMDLINE) if (table->flags & MULTIBOOT_FLAGS_CMDLINE)
mb_parse_cmdline(table); mb_parse_cmdline(table);

View File

@ -35,6 +35,7 @@
#define MULTIBOOT_MAGIC 0x2BADB002UL #define MULTIBOOT_MAGIC 0x2BADB002UL
#define MULTIBOOT_FLAGS_MMAP (1 << 6) #define MULTIBOOT_FLAGS_MMAP (1 << 6)
#define MULTIBOOT_FLAGS_CMDLINE (1 << 2) #define MULTIBOOT_FLAGS_CMDLINE (1 << 2)
#define MULTIBOOT_FLAGS_MEMINFO (1 << 0)
struct multiboot_header { struct multiboot_header {
u32 flags; u32 flags;
u32 mem_lower; u32 mem_lower;