19
19
FILE_LICENCE ( GPL2_OR_LATER );
20
20
21
21
#include <errno.h>
22
+ #include <stdlib.h>
22
23
#include <ipxe/efi/efi.h>
23
24
#include <ipxe/image.h>
24
25
#include <ipxe/init.h>
25
26
#include <ipxe/features.h>
27
+ #include <ipxe/uri.h>
26
28
27
29
FEATURE ( FEATURE_IMAGE , "EFI" , DHCP_EB_FEATURE_EFI , 1 );
28
30
31
+ /** EFI loaded image protocol GUID */
32
+ static EFI_GUID efi_loaded_image_protocol_guid
33
+ = EFI_LOADED_IMAGE_PROTOCOL_GUID ;
34
+
29
35
/**
30
36
* Execute EFI image
31
37
*
@@ -34,7 +40,10 @@ FEATURE ( FEATURE_IMAGE, "EFI", DHCP_EB_FEATURE_EFI, 1 );
34
40
*/
35
41
static int efi_image_exec ( struct image * image ) {
36
42
EFI_BOOT_SERVICES * bs = efi_systab -> BootServices ;
43
+ EFI_LOADED_IMAGE_PROTOCOL * loaded_image = NULL ;
44
+ void * loaded_image_void ;
37
45
EFI_HANDLE handle ;
46
+ EFI_HANDLE device_handle = NULL ;
38
47
UINTN exit_data_size ;
39
48
CHAR16 * exit_data ;
40
49
EFI_STATUS efirc ;
@@ -50,13 +59,29 @@ static int efi_image_exec ( struct image *image ) {
50
59
return - ENOEXEC ;
51
60
}
52
61
62
+ /* Get the loaded image protocol for the newly loaded image */
63
+ efirc = bs -> OpenProtocol ( handle , & efi_loaded_image_protocol_guid ,
64
+ & loaded_image_void , efi_image_handle , NULL ,
65
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL );
66
+ if ( efirc ) {
67
+ /* Should never happen */
68
+ rc = EFIRC_TO_RC ( efirc );
69
+ }
70
+ loaded_image = loaded_image_void ;
71
+
72
+ /* Pass a GPXE download protocol to the image */
73
+ rc = efi_download_install ( & device_handle );
74
+
53
75
/* Start the image */
54
76
if ( ( efirc = bs -> StartImage ( handle , & exit_data_size ,
55
77
& exit_data ) ) != 0 ) {
56
78
DBGC ( image , "EFIIMAGE %p returned with status %s\n" ,
57
79
image , efi_strerror ( efirc ) );
58
80
}
59
81
rc = EFIRC_TO_RC ( efirc );
82
+ if ( device_handle ) {
83
+ efi_download_uninstall ( device_handle );
84
+ }
60
85
61
86
/* Unload the image. We can't leave it loaded, because we
62
87
* have no "unload" operation.
0 commit comments