setup.c 1009 B

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