efi_image.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <errno.h>
00022 #include <gpxe/efi/efi.h>
00023 #include <gpxe/image.h>
00024 #include <gpxe/features.h>
00025
00026 FEATURE ( FEATURE_IMAGE, "EFI", DHCP_EB_FEATURE_EFI, 1 );
00027
00028 struct image_type efi_image_type __image_type ( PROBE_NORMAL );
00029
00030
00031
00032
00033
00034
00035
00036 static int efi_image_exec ( struct image *image ) {
00037 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
00038 EFI_HANDLE handle;
00039 UINTN exit_data_size;
00040 CHAR16 *exit_data;
00041 EFI_STATUS efirc;
00042
00043
00044 if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL,
00045 user_to_virt ( image->data, 0 ),
00046 image->len, &handle ) ) != 0 ) {
00047
00048 DBGC ( image, "EFIIMAGE %p could not load: %s\n",
00049 image, efi_strerror ( efirc ) );
00050 return -ENOEXEC;
00051 }
00052
00053
00054 if ( ( efirc = bs->StartImage ( handle, &exit_data_size,
00055 &exit_data ) ) != 0 ) {
00056 DBGC ( image, "EFIIMAGE %p returned with status %s\n",
00057 image, efi_strerror ( efirc ) );
00058 goto done;
00059 }
00060
00061 done:
00062
00063
00064
00065 bs->UnloadImage ( handle );
00066
00067 return EFIRC_TO_RC ( efirc );
00068 }
00069
00070
00071
00072
00073
00074
00075
00076 static int efi_image_load ( struct image *image ) {
00077 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
00078 EFI_HANDLE handle;
00079 EFI_STATUS efirc;
00080
00081
00082 if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL,
00083 user_to_virt ( image->data, 0 ),
00084 image->len, &handle ) ) != 0 ) {
00085
00086 DBGC ( image, "EFIIMAGE %p could not load: %s\n",
00087 image, efi_strerror ( efirc ) );
00088 return -ENOEXEC;
00089 }
00090
00091
00092 if ( ! image->type )
00093 image->type = &efi_image_type;
00094
00095
00096
00097
00098 bs->UnloadImage ( handle );
00099
00100 return 0;
00101 }
00102
00103
00104 struct image_type efi_image_type __image_type ( PROBE_NORMAL ) = {
00105 .name = "EFI",
00106 .load = efi_image_load,
00107 .exec = efi_image_exec,
00108 };