From: Vishvananda Ishaya <vish.ish...@oracle.com>

This patch adds a new setting to allow a uefi filename to be specified. The
parameter is uefi-filename and can be set in a script like so:

    set uefi-filename \EFI\vendor\file.efi

If specified, this filename will be used during the sanboot process in place of
the default efi filename.

---
 src/interface/efi/efi_block.c | 41 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/interface/efi/efi_block.c b/src/interface/efi/efi_block.c
index ab23094..6240c9b 100644
--- a/src/interface/efi/efi_block.c
+++ b/src/interface/efi/efi_block.c
@@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  */
 
 #include <stddef.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -46,6 +47,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/process.h>
 #include <ipxe/sanboot.h>
 #include <ipxe/iso9660.h>
+#include <ipxe/settings.h>
 #include <ipxe/efi/efi.h>
 #include <ipxe/efi/Protocol/BlockIo.h>
 #include <ipxe/efi/Protocol/SimpleFileSystem.h>
@@ -61,6 +63,14 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 /** Boot filename */
 static wchar_t efi_block_boot_filename[] = EFI_REMOVABLE_MEDIA_FILE_NAME;
 
+/** uefi filename setting */
+const struct setting uefi_filename_setting __setting ( SETTING_SANBOOT_EXTRA,
+                                                      uefi-filename ) = {
+       .name = "uefi-filename",
+       .description = "UEFI filename to boot",
+       .type = &setting_type_string,
+};
+
 /** iPXE EFI block device vendor device path GUID */
 #define IPXE_BLOCK_DEVICE_PATH_GUID                                    \
        { 0x8998b594, 0xf531, 0x4e87,                                   \
@@ -923,6 +933,9 @@ static int efi_block_boot_image ( struct efi_block *block,
        size_t boot_path_len;
        EFI_STATUS efirc;
        int rc;
+       char *uefi_filename = NULL;
+       int uefi_filename_len = 0;
+       int i;
 
        /* Identify device path */
        if ( ( efirc = bs->OpenProtocol ( handle,
@@ -948,10 +961,23 @@ static int efi_block_boot_image ( struct efi_block *block,
               block->drive, efi_devpath_text ( path.path ) );
 
        /* Construct device path for boot image */
+       /* get setting */
+       fetch_string_setting_copy ( NULL, &uefi_filename_setting,
+                                   &uefi_filename );
+       if ( uefi_filename != NULL ) {
+               uefi_filename_len = strlen ( uefi_filename );
+       }
        end = efi_devpath_end ( path.path );
        prefix_len = ( ( ( void * ) end ) - ( ( void * ) path.path ) );
-       filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
-                        sizeof ( efi_block_boot_filename ) );
+       if ( uefi_filename_len != 0 ) {
+               filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
+                                (uefi_filename_len + 1) * sizeof ( wchar_t ) );
+               printf ( "Booting from %s\n", uefi_filename );
+       } else {
+               filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
+                                sizeof ( efi_block_boot_filename ) );
+               printf ( "Booting from %ls\n", efi_block_boot_filename );
+       }
        boot_path_len = ( prefix_len + filepath_len + sizeof ( *end ) );
        boot_path = zalloc ( boot_path_len );
        if ( ! boot_path ) {
@@ -964,8 +990,14 @@ static int efi_block_boot_image ( struct efi_block *block,
        filepath->Header.SubType = MEDIA_FILEPATH_DP;
        filepath->Header.Length[0] = ( filepath_len & 0xff );
        filepath->Header.Length[1] = ( filepath_len >> 8 );
-       memcpy ( filepath->PathName, efi_block_boot_filename,
-                sizeof ( efi_block_boot_filename ) );
+       if ( uefi_filename_len != 0 ) {
+               for (i = 0; i <= uefi_filename_len; i++) {
+                       filepath->PathName[i] = uefi_filename[i];
+               }
+       } else {
+               memcpy ( filepath->PathName, efi_block_boot_filename,
+                        sizeof ( efi_block_boot_filename ) );
+       }
        end = ( ( ( void * ) filepath ) + filepath_len );
        end->Type = END_DEVICE_PATH_TYPE;
        end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
@@ -988,6 +1020,7 @@ static int efi_block_boot_image ( struct efi_block *block,
  err_load_image:
        free ( boot_path );
  err_alloc_path:
+       free ( uefi_filename );
  err_not_child:
  err_open_device_path:
        return rc;
-- 
2.5.0

_______________________________________________
ipxe-devel mailing list
ipxe-devel@lists.ipxe.org
https://lists.ipxe.org/mailman/listinfo.cgi/ipxe-devel

Reply via email to