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 10 #define MBI_MODS_COUNT 20 11 #define MBI_MODS_ADDR 24 12 #define MB_MOD_START 0 13 #define MB_MOD_END 4 14 15 #define ENV_SIZE 16384 16 17 extern void setup_env(char *env, int size); 18 19 char *initrd; 20 u32 initrd_size; 21 22 static char env[ENV_SIZE]; 23 24 void setup_get_initrd(u8 *bootinfo) 25 { 26 u32 *mods_addr, *mod_start, *mod_end; 27 28 if (*((u32 *)&bootinfo[MBI_MODS_COUNT]) != 1) 29 return; 30 31 mods_addr = (u32 *)&bootinfo[MBI_MODS_ADDR]; 32 mod_start = (u32 *)(ulong)(*mods_addr + MB_MOD_START); 33 mod_end = (u32 *)(ulong)(*mods_addr + MB_MOD_END); 34 35 initrd = (char *)(ulong)*mod_start; 36 initrd_size = *mod_end - *mod_start; 37 } 38 39 void setup_environ(void) 40 { 41 if (initrd) { 42 /* environ is currently the only file in the initrd */ 43 u32 size = MIN(initrd_size, ENV_SIZE); 44 memcpy(env, initrd, size); 45 setup_env(env, size); 46 } 47 } 48