1 /* 2 * Initialize machine setup information 3 * 4 * Copyright (C) 2017, Red Hat Inc, Andrew Jones <drjones@redhat.com> 5 * 6 * This work is licensed under the terms of the GNU LGPL, version 2. 7 */ 8 #include "libcflat.h" 9 #include "fwcfg.h" 10 #include "alloc_phys.h" 11 12 extern char edata; 13 14 struct mbi_bootinfo { 15 u32 flags; 16 u32 mem_lower; 17 u32 mem_upper; 18 u32 boot_device; 19 u32 cmdline; 20 u32 mods_count; 21 u32 mods_addr; 22 u32 reserved[5]; /* 28-47 */ 23 u32 mmap_addr; 24 u32 reserved0[3]; /* 52-63 */ 25 u32 bootloader; 26 u32 reserved1[5]; /* 68-87 */ 27 u32 size; 28 }; 29 30 struct mbi_module { 31 u32 start, end; 32 u32 cmdline; 33 u32 unused; 34 }; 35 36 #define ENV_SIZE 16384 37 38 extern void setup_env(char *env, int size); 39 40 char *initrd; 41 u32 initrd_size; 42 43 static char env[ENV_SIZE]; 44 45 void setup_multiboot(struct mbi_bootinfo *bootinfo) 46 { 47 struct mbi_module *mods; 48 49 if (bootinfo->mods_count != 1) 50 return; 51 52 mods = (struct mbi_module *)(uintptr_t) bootinfo->mods_addr; 53 54 initrd = (char *)(uintptr_t) mods->start; 55 initrd_size = mods->end - mods->start; 56 57 /* TODO: use e820 */ 58 u64 end_of_memory = bootinfo->mem_upper * 1024ull; 59 phys_alloc_init((uintptr_t) &edata, end_of_memory - (uintptr_t)edata); 60 } 61 62 void setup_libcflat(void) 63 { 64 if (initrd) { 65 /* environ is currently the only file in the initrd */ 66 u32 size = MIN(initrd_size, ENV_SIZE); 67 memcpy(env, initrd, size); 68 setup_env(env, size); 69 } 70 } 71