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.
20 #include <gpxe/efi/efi.h>
21 #include <gpxe/image.h>
22 #include <gpxe/features.h>
24 FEATURE ( FEATURE_IMAGE
, "EFI", DHCP_EB_FEATURE_EFI
, 1 );
26 struct image_type efi_image_type
__image_type ( PROBE_NORMAL
);
32 * @ret rc Return status code
34 static int efi_image_exec ( struct image
*image
) {
35 EFI_BOOT_SERVICES
*bs
= efi_systab
->BootServices
;
41 /* Attempt loading image */
42 if ( ( efirc
= bs
->LoadImage ( FALSE
, efi_image_handle
, NULL
,
43 user_to_virt ( image
->data
, 0 ),
44 image
->len
, &handle
) ) != 0 ) {
45 /* Not an EFI image */
46 DBGC ( image
, "EFIIMAGE %p could not load: %s\n",
47 image
, efi_strerror ( efirc
) );
52 if ( ( efirc
= bs
->StartImage ( handle
, &exit_data_size
,
53 &exit_data
) ) != 0 ) {
54 DBGC ( image
, "EFIIMAGE %p returned with status %s\n",
55 image
, efi_strerror ( efirc
) );
60 /* Unload the image. We can't leave it loaded, because we
61 * have no "unload" operation.
63 bs
->UnloadImage ( handle
);
65 return EFIRC_TO_RC ( efirc
);
69 * Load EFI image into memory
72 * @ret rc Return status code
74 static int efi_image_load ( struct image
*image
) {
75 EFI_BOOT_SERVICES
*bs
= efi_systab
->BootServices
;
79 /* Attempt loading image */
80 if ( ( efirc
= bs
->LoadImage ( FALSE
, efi_image_handle
, NULL
,
81 user_to_virt ( image
->data
, 0 ),
82 image
->len
, &handle
) ) != 0 ) {
83 /* Not an EFI image */
84 DBGC ( image
, "EFIIMAGE %p could not load: %s\n",
85 image
, efi_strerror ( efirc
) );
89 /* This is an EFI image */
91 image
->type
= &efi_image_type
;
93 /* Unload the image. We can't leave it loaded, because we
94 * have no "unload" operation.
96 bs
->UnloadImage ( handle
);
101 /** EFI image type */
102 struct image_type efi_image_type
__image_type ( PROBE_NORMAL
) = {
104 .load
= efi_image_load
,
105 .exec
= efi_image_exec
,