init.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/kernel.h>
  27. grub_addr_t grub_modbase;
  28. void
  29. grub_efi_init (void)
  30. {
  31. grub_modbase = grub_efi_modules_addr ();
  32. /* First of all, initialize the console so that GRUB can display
  33. messages. */
  34. grub_console_init ();
  35. /* Initialize the memory management system. */
  36. grub_efi_mm_init ();
  37. efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
  38. 0, 0, 0, NULL);
  39. grub_efidisk_init ();
  40. }
  41. void (*grub_efi_net_config) (grub_efi_handle_t hnd,
  42. char **device,
  43. char **path);
  44. void
  45. grub_machine_get_bootlocation (char **device, char **path)
  46. {
  47. grub_efi_loaded_image_t *image = NULL;
  48. char *p;
  49. image = grub_efi_get_loaded_image (grub_efi_image_handle);
  50. if (!image)
  51. return;
  52. *device = grub_efidisk_get_device_name (image->device_handle);
  53. if (!*device && grub_efi_net_config)
  54. {
  55. grub_efi_net_config (image->device_handle, device, path);
  56. return;
  57. }
  58. *path = grub_efi_get_filename (image->file_path);
  59. if (*path)
  60. {
  61. /* Get the directory. */
  62. p = grub_strrchr (*path, '/');
  63. if (p)
  64. *p = '\0';
  65. }
  66. }
  67. void
  68. grub_efi_fini (void)
  69. {
  70. grub_efidisk_fini ();
  71. grub_console_fini ();
  72. }