aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2023-03-10 16:50:16 +0000
committerMichael Brown <mcb30@ipxe.org>2023-03-10 16:50:16 +0000
commit99aad3903716ec9b01270d84b96ac5f1cb736265 (patch)
tree2702fb83531e809588e34715c2c6d1a6b2473c09
parentb123d3287009df4b50fd38c266072fefe677a0bf (diff)
downloadipxe-99aad3903716ec9b01270d84b96ac5f1cb736265.zip
ipxe-99aad3903716ec9b01270d84b96ac5f1cb736265.tar.gz
ipxe-99aad3903716ec9b01270d84b96ac5f1cb736265.tar.bz2
WIP - shim
-rw-r--r--src/hci/commands/shim_cmd.c26
-rw-r--r--src/interface/efi/efi_file.c18
2 files changed, 26 insertions, 18 deletions
diff --git a/src/hci/commands/shim_cmd.c b/src/hci/commands/shim_cmd.c
index efefb5b..4252fc7 100644
--- a/src/hci/commands/shim_cmd.c
+++ b/src/hci/commands/shim_cmd.c
@@ -51,13 +51,13 @@ static struct option_descriptor shim_opts[] = {
struct shim_options, keep, parse_flag ),
OPTION_DESC ( "timeout", 't', required_argument,
struct shim_options, timeout, parse_timeout ),
- OPTION_DESC ( "second", 's', required_argument,
+ OPTION_DESC ( "altname", 'a', required_argument,
struct shim_options, altname, parse_string ),
};
/** "shim" command descriptor */
static struct command_descriptor shim_cmd =
- COMMAND_DESC ( struct shim_options, shim_opts, 1, 1, NULL );
+ COMMAND_DESC ( struct shim_options, shim_opts, 0, 1, NULL );
/**
* The "shim" command
@@ -68,29 +68,35 @@ static struct command_descriptor shim_cmd =
*/
static int shim_exec ( int argc, char **argv ) {
struct shim_options opts;
- struct image *image;
+ struct image *image = NULL;
+ char *name_uri = NULL;
int rc;
/* Parse options */
if ( ( rc = parse_options ( argc, argv, &shim_cmd, &opts ) ) != 0 )
goto err_parse;
- /* Acquire image */
- if ( ( rc = imgacquire ( argv[optind], opts.timeout, &image ) ) != 0 )
+ /* Parse name/URI string */
+ name_uri = argv[optind];
+
+ /* Acquire image, if applicable */
+ if ( name_uri &&
+ ( rc = imgacquire ( name_uri, opts.timeout, &image ) ) != 0 ) {
goto err_acquire;
+ }
- /* Record second stage, if any */
- if ( ( rc = image_set_cmdline ( image, opts.altname ) ) != 0 )
+ /* Record second stage alternative name, if any */
+ if ( image && ( rc = image_set_cmdline ( image, opts.altname ) ) != 0 )
goto err_cmdline;
- /* Register as shim */
+ /* (Un)register as shim */
efi_set_shim ( image );
/* Success */
rc = 0;
- /* Discard original image unless --keep was specified */
- if ( ! opts.keep )
+ /* Unregister original image unless --keep was specified */
+ if ( image && ( ! opts.keep ) )
unregister_image ( image );
err_cmdline:
err_acquire:
diff --git a/src/interface/efi/efi_file.c b/src/interface/efi/efi_file.c
index 5afdf68..6fcc61e 100644
--- a/src/interface/efi/efi_file.c
+++ b/src/interface/efi/efi_file.c
@@ -120,10 +120,10 @@ static const char * efi_file_name ( struct efi_file *file ) {
if ( file == &efi_file_root ) {
return "<root>";
- } else if ( file->name != NULL ) {
- return file->name;
} else if ( file->image != NULL ) {
return file->image->name;
+ } else if ( file->name != NULL ) {
+ return file->name;
} else {
return "<UNKNOWN>";
}
@@ -290,10 +290,11 @@ static size_t efi_file_read_initrd ( struct efi_file_reader *reader ) {
* Open fixed file
*
* @v file EFI file
+ * @v wname Filename
* @v new New EFI file
* @ret efirc EFI status code
*/
-static EFI_STATUS efi_file_open_fixed ( struct efi_file *file,
+static EFI_STATUS efi_file_open_fixed ( struct efi_file *file, const char *name,
EFI_FILE_PROTOCOL **new ) {
/* Increment reference count */
@@ -302,7 +303,8 @@ static EFI_STATUS efi_file_open_fixed ( struct efi_file *file,
/* Return opened file */
*new = &file->file;
- DBGC ( file, "EFIFILE %s opened\n", efi_file_name ( file ) );
+ DBGC ( file, "EFIFILE %s opened via %s\n",
+ efi_file_name ( file ), name );
return 0;
}
@@ -350,7 +352,7 @@ efi_file_open ( EFI_FILE_PROTOCOL *this, EFI_FILE_PROTOCOL **new,
/* Allow root directory itself to be opened */
if ( ( name[0] == '\0' ) || ( name[0] == '.' ) )
- return efi_file_open_fixed ( &efi_file_root, new );
+ return efi_file_open_fixed ( &efi_file_root, name, new );
/* Fail unless opening from the root */
if ( file != &efi_file_root ) {
@@ -371,12 +373,12 @@ efi_file_open ( EFI_FILE_PROTOCOL *this, EFI_FILE_PROTOCOL **new,
( ( strcasecmp ( name, efi_file_second.image->name ) == 0 ) ||
( ( efi_file_second.name != NULL ) &&
( strcasecmp ( name, efi_file_second.name ) == 0 ) ) ) ) {
- return efi_file_open_fixed ( &efi_file_second, new );
+ return efi_file_open_fixed ( &efi_file_second, name, new );
}
/* Allow magic initrd to be opened */
if ( strcasecmp ( name, efi_file_initrd.name ) == 0 )
- return efi_file_open_fixed ( &efi_file_initrd, new );
+ return efi_file_open_fixed ( &efi_file_initrd, name, new );
/* Identify image */
image = efi_file_find ( name );
@@ -849,7 +851,7 @@ efi_file_open_volume ( EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *filesystem __unused,
EFI_FILE_PROTOCOL **file ) {
DBGC ( &efi_file_root, "EFIFILE open volume\n" );
- return efi_file_open_fixed ( &efi_file_root, file );
+ return efi_file_open_fixed ( &efi_file_root, "volume", file );
}
/** EFI simple file system protocol */