Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <errno.h>
  19. #include <gpxe/efi/efi.h>
  20. #include <gpxe/image.h>
  21. #include <gpxe/features.h>
  22. FEATURE ( FEATURE_IMAGE, "EFI", DHCP_EB_FEATURE_EFI, 1 );
  23. struct image_type efi_image_type __image_type ( PROBE_NORMAL );
  24. /**
  25. * Execute EFI image
  26. *
  27. * @v image EFI image
  28. * @ret rc Return status code
  29. */
  30. static int efi_image_exec ( struct image *image ) {
  31. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  32. EFI_HANDLE handle;
  33. UINTN exit_data_size;
  34. CHAR16 *exit_data;
  35. EFI_STATUS efirc;
  36. /* Attempt loading image */
  37. if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL,
  38. user_to_virt ( image->data, 0 ),
  39. image->len, &handle ) ) != 0 ) {
  40. /* Not an EFI image */
  41. DBGC ( image, "EFIIMAGE %p could not load: %s\n",
  42. image, efi_strerror ( efirc ) );
  43. return -ENOEXEC;
  44. }
  45. /* Start the image */
  46. if ( ( efirc = bs->StartImage ( handle, &exit_data_size,
  47. &exit_data ) ) != 0 ) {
  48. DBGC ( image, "EFIIMAGE %p returned with status %s\n",
  49. image, efi_strerror ( efirc ) );
  50. goto done;
  51. }
  52. done:
  53. /* Unload the image. We can't leave it loaded, because we
  54. * have no "unload" operation.
  55. */
  56. bs->UnloadImage ( handle );
  57. return EFIRC_TO_RC ( efirc );
  58. }
  59. /**
  60. * Load EFI image into memory
  61. *
  62. * @v image EFI file
  63. * @ret rc Return status code
  64. */
  65. static int efi_image_load ( struct image *image ) {
  66. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  67. EFI_HANDLE handle;
  68. EFI_STATUS efirc;
  69. /* Attempt loading image */
  70. if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL,
  71. user_to_virt ( image->data, 0 ),
  72. image->len, &handle ) ) != 0 ) {
  73. /* Not an EFI image */
  74. DBGC ( image, "EFIIMAGE %p could not load: %s\n",
  75. image, efi_strerror ( efirc ) );
  76. return -ENOEXEC;
  77. }
  78. /* This is an EFI image */
  79. if ( ! image->type )
  80. image->type = &efi_image_type;
  81. /* Unload the image. We can't leave it loaded, because we
  82. * have no "unload" operation.
  83. */
  84. bs->UnloadImage ( handle );
  85. return 0;
  86. }
  87. /** EFI image type */
  88. struct image_type efi_image_type __image_type ( PROBE_NORMAL ) = {
  89. .name = "EFI",
  90. .load = efi_image_load,
  91. .exec = efi_image_exec,
  92. };