init.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* init.c - generic EFI initialization and finalization */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2006,2007 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/efi/efi.h>
  20. #include <grub/efi/console.h>
  21. #include <grub/efi/disk.h>
  22. #include <grub/term.h>
  23. #include <grub/misc.h>
  24. #include <grub/env.h>
  25. #include <grub/mm.h>
  26. #include <grub/machine/kernel.h>
  27. void
  28. grub_efi_init (void)
  29. {
  30. /* First of all, initialize the console so that GRUB can display
  31. messages. */
  32. grub_console_init ();
  33. /* Initialize the memory management system. */
  34. grub_efi_mm_init ();
  35. grub_efidisk_init ();
  36. efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
  37. 0, 0, 0, 0);
  38. }
  39. void
  40. grub_efi_set_prefix (void)
  41. {
  42. grub_efi_loaded_image_t *image;
  43. image = grub_efi_get_loaded_image (grub_efi_image_handle);
  44. if (image)
  45. {
  46. char *device;
  47. char *file;
  48. char *prefix;
  49. device = grub_efidisk_get_device_name (image->device_handle);
  50. file = grub_efi_get_filename (image->file_path);
  51. if (file)
  52. {
  53. char *p;
  54. /* Get the directory. */
  55. p = grub_strrchr (file, '/');
  56. if (p)
  57. *p = '\0';
  58. }
  59. prefix = grub_xasprintf ("(%s)%s", (device) ? device : "net0",
  60. (file) ? file : "");
  61. if (prefix)
  62. {
  63. grub_env_set ("prefix", prefix);
  64. grub_free (prefix);
  65. }
  66. grub_free (device);
  67. grub_free (file);
  68. }
  69. }
  70. void
  71. grub_efi_fini (void)
  72. {
  73. grub_efidisk_fini ();
  74. grub_console_fini ();
  75. }