|
|
1.1 ! root 1: /* ! 2: * Copyright (C) 2008 Michael Brown <[email protected]>. ! 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: ! 19: FILE_LICENCE ( GPL2_OR_LATER ); ! 20: ! 21: #include <errno.h> ! 22: #include <ipxe/efi/efi.h> ! 23: #include <ipxe/image.h> ! 24: #include <ipxe/init.h> ! 25: #include <ipxe/features.h> ! 26: ! 27: FEATURE ( FEATURE_IMAGE, "EFI", DHCP_EB_FEATURE_EFI, 1 ); ! 28: ! 29: /** ! 30: * Execute EFI image ! 31: * ! 32: * @v image EFI image ! 33: * @ret rc Return status code ! 34: */ ! 35: static int efi_image_exec ( struct image *image ) { ! 36: EFI_BOOT_SERVICES *bs = efi_systab->BootServices; ! 37: EFI_HANDLE handle; ! 38: UINTN exit_data_size; ! 39: CHAR16 *exit_data; ! 40: EFI_STATUS efirc; ! 41: int rc; ! 42: ! 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 ) ); ! 50: return -ENOEXEC; ! 51: } ! 52: ! 53: /* Start the image */ ! 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 ) ); ! 58: } ! 59: rc = EFIRC_TO_RC ( efirc ); ! 60: ! 61: /* Unload the image. We can't leave it loaded, because we ! 62: * have no "unload" operation. ! 63: */ ! 64: bs->UnloadImage ( handle ); ! 65: ! 66: return rc; ! 67: } ! 68: ! 69: /** ! 70: * Probe EFI image ! 71: * ! 72: * @v image EFI file ! 73: * @ret rc Return status code ! 74: */ ! 75: static int efi_image_probe ( struct image *image ) { ! 76: EFI_BOOT_SERVICES *bs = efi_systab->BootServices; ! 77: EFI_HANDLE handle; ! 78: EFI_STATUS efirc; ! 79: ! 80: /* Attempt loading image */ ! 81: if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL, ! 82: user_to_virt ( image->data, 0 ), ! 83: image->len, &handle ) ) != 0 ) { ! 84: /* Not an EFI image */ ! 85: DBGC ( image, "EFIIMAGE %p could not load: %s\n", ! 86: image, efi_strerror ( efirc ) ); ! 87: return -ENOEXEC; ! 88: } ! 89: ! 90: /* Unload the image. We can't leave it loaded, because we ! 91: * have no "unload" operation. ! 92: */ ! 93: bs->UnloadImage ( handle ); ! 94: ! 95: return 0; ! 96: } ! 97: ! 98: /** EFI image type */ ! 99: struct image_type efi_image_type __image_type ( PROBE_NORMAL ) = { ! 100: .name = "EFI", ! 101: .probe = efi_image_probe, ! 102: .exec = efi_image_exec, ! 103: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.