a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * This program is free software; you can redistribute it and/or
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * modify it under the terms of the GNU General Public License as
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * published by the Free Software Foundation; either version 2 of the
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * License, or any later version.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * This program is distributed in the hope that it will be useful, but
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * WITHOUT ANY WARRANTY; without even the implied warranty of
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * General Public License for more details.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * You should have received a copy of the GNU General Public License
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * along with this program; if not, write to the Free Software
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncFEATURE ( FEATURE_IMAGE, "EFI", DHCP_EB_FEATURE_EFI, 1 );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/** EFI loaded image protocol GUID */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Create a Unicode command line for the image
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v image EFI image
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v devpath_out Device path to pass to image (output)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v cmdline_out Unicode command line (output)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v cmdline_len_out Length of command line in bytes (output)
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @ret rc Return status code
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic int efi_image_make_cmdline ( struct image *image,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Get the URI string of the image */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uri_len = unparse_uri ( NULL, 0, image->uri, URI_ALL ) + 1;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Compute final command line length */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Allocate space for the uri, final command line and device path */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync cmdline = malloc ( cmdline_len * sizeof ( CHAR16 ) + uri_len
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync + sizeof ( EFI_DEVICE_PATH ) );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync devpath = (FILEPATH_DEVICE_PATH *) ( uri + uri_len );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Build the iPXE device path */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Convert to Unicode */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync for ( i = 0 ; i < uri_len ; i++ ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync for ( i = 0 ; i < args_len ; i++ ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync *cmdline_len_out = cmdline_len * sizeof ( CHAR16 );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Execute EFI image
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v image EFI image
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @ret rc Return status code
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Attempt loading image */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Not an EFI image */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Get the loaded image protocol for the newly loaded image */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync efirc = bs->OpenProtocol ( handle, &efi_loaded_image_protocol_guid,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Should never happen */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Pass an iPXE download protocol to the image */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ( rc = efi_download_install ( &device_handle ) ) != 0 ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync DBGC ( image, "EFIIMAGE %p could not install iPXE download "
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ( rc = efi_image_make_cmdline ( image, &loaded.image->FilePath,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Start the image */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ( efirc = bs->StartImage ( handle, &exit_data_size,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync &exit_data ) ) != 0 ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync DBGC ( image, "EFIIMAGE %p returned with status %s\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Success */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Unload the image. We can't leave it loaded, because we
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * have no "unload" operation.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Probe EFI image
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @v image EFI file
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * @ret rc Return status code
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic int efi_image_probe ( struct image *image ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Attempt loading image */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, NULL,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Not an EFI image */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Unload the image. We can't leave it loaded, because we
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * have no "unload" operation.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/** EFI image type */