2 * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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.
19 FILE_LICENCE ( GPL2_OR_LATER
);
22 #include <gpxe/efi/efi.h>
23 #include <gpxe/image.h>
24 #include <gpxe/features.h>
26 FEATURE ( FEATURE_IMAGE
, "EFI", DHCP_EB_FEATURE_EFI
, 1 );
28 struct image_type efi_image_type
__image_type ( PROBE_NORMAL
);
34 * @ret rc Return status code
36 static int efi_image_exec ( struct image
*image
) {
37 EFI_BOOT_SERVICES
*bs
= efi_systab
->BootServices
;
43 /* Attempt loading image */
44 if ( ( efirc
= bs
->LoadImage ( FALSE
, efi_image_handle
, NULL
,
45 user_to_virt ( image
->data
, 0 ),
46 image
->len
, &handle
) ) != 0 ) {
47 /* Not an EFI image */
48 DBGC ( image
, "EFIIMAGE %p could not load: %s\n",
49 image
, efi_strerror ( efirc
) );
54 if ( ( efirc
= bs
->StartImage ( handle
, &exit_data_size
,
55 &exit_data
) ) != 0 ) {
56 DBGC ( image
, "EFIIMAGE %p returned with status %s\n",
57 image
, efi_strerror ( efirc
) );
62 /* Unload the image. We can't leave it loaded, because we
63 * have no "unload" operation.
65 bs
->UnloadImage ( handle
);
67 return EFIRC_TO_RC ( efirc
);
71 * Load EFI image into memory
74 * @ret rc Return status code
76 static int efi_image_load ( struct image
*image
) {
77 EFI_BOOT_SERVICES
*bs
= efi_systab
->BootServices
;
81 /* Attempt loading image */
82 if ( ( efirc
= bs
->LoadImage ( FALSE
, efi_image_handle
, NULL
,
83 user_to_virt ( image
->data
, 0 ),
84 image
->len
, &handle
) ) != 0 ) {
85 /* Not an EFI image */
86 DBGC ( image
, "EFIIMAGE %p could not load: %s\n",
87 image
, efi_strerror ( efirc
) );
91 /* This is an EFI image */
93 image
->type
= &efi_image_type
;
95 /* Unload the image. We can't leave it loaded, because we
96 * have no "unload" operation.
98 bs
->UnloadImage ( handle
);
103 /** EFI image type */
104 struct image_type efi_image_type
__image_type ( PROBE_NORMAL
) = {
106 .load
= efi_image_load
,
107 .exec
= efi_image_exec
,