<p dir="ltr">It needs some fixes before merge, but have not gotten around to it</p>
<div class="gmail_quote">On 18 May 2017 11:41, "Ladi Prosek" <<a href="mailto:lprosek@redhat.com">lprosek@redhat.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, Dec 11, 2016 at 2:10 AM, Christian Nilsson <<a href="mailto:nikize@gmail.com">nikize@gmail.com</a>> wrote:<br>
> cmdline part is copied over from pcbios functionallity<br>
><br>
> Signed-off-by: Christian Nilsson <<a href="mailto:nikize@gmail.com">nikize@gmail.com</a>><br>
> ---<br>
> src/config/config_efi.c | 2 +<br>
> src/include/ipxe/errfile.h | 1 +<br>
> src/interface/efi/efi_runtime.<wbr>c | 177 ++++++++++++++++++++++++++++++<wbr>++++++++++<br>
> 3 files changed, 180 insertions(+)<br>
> create mode 100644 src/interface/efi/efi_runtime.<wbr>c<br>
><br>
> diff --git a/src/config/config_efi.c b/src/config/config_efi.c<br>
> index 92678d1..161019a 100644<br>
> --- a/src/config/config_efi.c<br>
> +++ b/src/config/config_efi.c<br>
> @@ -49,3 +49,5 @@ REQUIRE_OBJECT ( efi_fbcon );<br>
> #ifdef DOWNLOAD_PROTO_FILE<br>
> REQUIRE_OBJECT ( efi_local );<br>
> #endif<br>
> +<br>
> +REQUIRE_OBJECT ( efi_runtime );<br>
> diff --git a/src/include/ipxe/errfile.h b/src/include/ipxe/errfile.h<br>
> index d0b93d0..a8ea9d1 100644<br>
> --- a/src/include/ipxe/errfile.h<br>
> +++ b/src/include/ipxe/errfile.h<br>
> @@ -361,6 +361,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );<br>
> #define ERRFILE_efi_local ( ERRFILE_OTHER | 0x004d0000 )<br>
> #define ERRFILE_efi_entropy ( ERRFILE_OTHER | 0x004e0000 )<br>
> #define ERRFILE_cert_cmd ( ERRFILE_OTHER | 0x004f0000 )<br>
> +#define ERRFILE_efi_runtime ( ERRFILE_OTHER | 0x00500000 )<br>
><br>
> /** @} */<br>
><br>
> diff --git a/src/interface/efi/efi_<wbr>runtime.c b/src/interface/efi/efi_<wbr>runtime.c<br>
> new file mode 100644<br>
> index 0000000..bc7ff82<br>
> --- /dev/null<br>
> +++ b/src/interface/efi/efi_<wbr>runtime.c<br>
> @@ -0,0 +1,177 @@<br>
> +/*<br>
> + * Copyright (C) 2011 Michael Brown <<a href="mailto:mbrown@fensystems.co.uk">mbrown@fensystems.co.uk</a>>.<br>
> + *<br>
> + * This program is free software; you can redistribute it and/or<br>
> + * modify it under the terms of the GNU General Public License as<br>
> + * published by the Free Software Foundation; either version 2 of the<br>
> + * License, or any later version.<br>
> + *<br>
> + * This program is distributed in the hope that it will be useful, but<br>
> + * WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
> + * General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU General Public License<br>
> + * along with this program; if not, write to the Free Software<br>
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA<br>
> + * 02110-1301, USA.<br>
> + *<br>
> + * You can also choose to distribute this program under the terms of<br>
> + * the Unmodified Binary Distribution Licence (as given in the file<br>
> + * COPYING.UBDL), provided that you have satisfied its requirements.<br>
> + */<br>
> +<br>
> +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );<br>
> +<br>
> +/** @file<br>
> + *<br>
> + * Command line passed to iPXE at runtime<br>
> + *<br>
> + */<br>
> +<br>
> +#include <stdio.h><br>
> +#include <stdlib.h><br>
> +#include <ctype.h><br>
> +#include <errno.h><br>
> +#include <ipxe/init.h><br>
> +#include <ipxe/image.h><br>
> +#include <ipxe/script.h><br>
> +#include <ipxe/efi/efi.h><br>
> +<br>
> +/** Internal copy of the command line */<br>
> +static char *cmdline_copy;<br>
> +<br>
> +/** Free command line image */<br>
> +static void cmdline_image_free ( struct refcnt *refcnt ) {<br>
> + struct image *image = container_of ( refcnt, struct image, refcnt );<br>
> +<br>
> + DBGC ( image, "RUNTIME freeing command line\n" );<br>
> + free ( cmdline_copy );<br>
> +}<br>
> +<br>
> +/** Embedded script representing the command line */<br>
> +static struct image cmdline_image = {<br>
> + .refcnt = REF_INIT ( cmdline_image_free ),<br>
> + .name = "<CMDLINE>",<br>
> + .type = &script_image_type,<br>
> +};<br>
> +<br>
> +/** Colour for debug messages */<br>
> +#define colour &cmdline_image<br>
> +<br>
> +/**<br>
> + * Strip unwanted cruft from command line<br>
> + *<br>
> + * @v cmdline Command line<br>
> + * @v cruft Initial substring of cruft to strip<br>
> + */<br>
> +static void cmdline_strip ( char *cmdline, const char *cruft ) {<br>
> + char *strip;<br>
> + char *strip_end;<br>
> +<br>
> + /* Find unwanted cruft, if present */<br>
> + if ( ! ( strip = strstr ( cmdline, cruft ) ) )<br>
> + return;<br>
> +<br>
> + /* Strip unwanted cruft */<br>
> + strip_end = strchr ( strip, ' ' );<br>
> + if ( strip_end ) {<br>
> + *strip_end = '\0';<br>
> + DBGC ( colour, "RUNTIME stripping \"%s\"\n", strip );<br>
> + strcpy ( strip, ( strip_end + 1 ) );<br>
> + } else {<br>
> + DBGC ( colour, "RUNTIME stripping \"%s\"\n", strip );<br>
> + *strip = '\0';<br>
> + }<br>
> +}<br>
> +<br>
> +/**<br>
> + * Initialise command line<br>
> + *<br>
> + * @ret rc Return status code<br>
> + */<br>
> +static int cmdline_init ( void ) {<br>
> + EFI_LOADED_IMAGE_PROTOCOL *loaded = efi_loaded_image;<br>
> + size_t cmdline_len = ( loaded->LoadOptionsSize / sizeof ( wchar_t ) );<br>
> + char cmdline_efi[ cmdline_len + 1 /* NUL */ ];<br>
> + const wchar_t *wcmdline = loaded->LoadOptions;<br>
> + char *cmdline;<br>
> + size_t len;<br>
> + int rc;<br>
> +<br>
> + /* Convert command line to ASCII */<br>
> + snprintf ( cmdline_efi, sizeof ( cmdline_efi ), "%ls", wcmdline );<br>
> +<br>
> + /* Do nothing if no command line was specified */<br>
> + if ( ! cmdline_efi ) {<br>
> + DBGC ( colour, "RUNTIME found no command line\n" );<br>
> + return 0;<br>
> + }<br>
> + len = ( strlen ( cmdline_efi ) + 1 /* NUL */ );<br>
> +<br>
> + /* Allocate and copy command line */<br>
> + cmdline_copy = malloc ( len );<br>
> + if ( ! cmdline_copy ) {<br>
> + DBGC ( colour, "RUNTIME could not allocate %zd bytes for "<br>
> + "command line\n", len );<br>
> + rc = -ENOMEM;<br>
> + goto err_alloc_cmdline_copy;<br>
> + }<br>
> + cmdline = cmdline_copy;<br>
> + strcpy ( cmdline, cmdline_efi );<br>
> + DBGC ( colour, "RUNTIME found command line \"%s\"\n",<br>
> + cmdline );<br>
> +<br>
> + /* Check for unwanted cruft in the command line */<br>
> + while ( isspace ( *cmdline ) )<br>
> + cmdline++;<br>
> + /* skip program name, efi always add it first */<br>
> + while ( ! isspace ( *cmdline ) )<br>
> + cmdline++;<br>
> + /* Strip unwanted cruft from the command line */<br>
> + cmdline_strip ( cmdline, "BOOT_IMAGE=" );<br>
> + cmdline_strip ( cmdline, "initrd=" );<br>
> + while ( isspace ( *cmdline ) )<br>
> + cmdline++;<br>
> + DBGC ( colour, "RUNTIME using command line \"%s\"\n", cmdline );<br>
> +<br>
> + /* Prepare and register image */<br>
> + cmdline_image.data = virt_to_user ( cmdline );<br>
> + cmdline_image.len = strlen ( cmdline );<br>
> + if ( cmdline_image.len ) {<br>
> + if ( ( rc = register_image ( &cmdline_image ) ) != 0 ) {<br>
> + DBGC ( colour, "RUNTIME could not register command "<br>
> + "line: %s\n", strerror ( rc ) );<br>
> + goto err_register_image;<br>
> + }<br>
> + }<br>
> +<br>
> + /* Drop our reference to the image */<br>
> + image_put ( &cmdline_image );<br>
> +<br>
> + return 0;<br>
> +<br>
> + err_register_image:<br>
> + image_put ( &cmdline_image );<br>
> + err_alloc_cmdline_copy:<br>
> + return rc;<br>
> +}<br>
> +<br>
> +/**<br>
> + * Initialise command line<br>
> + *<br>
> + */<br>
> +static void runtime_init ( void ) {<br>
> + int rc;<br>
> +<br>
> + /* Initialise command line */<br>
> + if ( ( rc = cmdline_init() ) != 0 ) {<br>
> + /* No way to report failure */<br>
> + return;<br>
> + }<br>
> +}<br>
> +<br>
> +/** Command line initialisation function */<br>
> +struct startup_fn efi_runtime_startup_fn __startup_fn ( STARTUP_NORMAL ) = {<br>
> + .startup = runtime_init,<br>
> +};<br>
> --<br>
> 2.0.5<br>
<br>
Any reason why this patch was ignored? Maybe it can be done with less<br>
code duplication but the idea seems legit. It's clearly a gap in EFI<br>
functionality as compared to BIOS.<br>
<br>
Thanks,<br>
Ladi<br>
</blockquote></div>