[2/5] efi_loader: bootmgr: allow for running a given load option

Message ID 20181218050257.20142-3-takahiro.akashi@linaro.org
State Superseded
Headers show
Series
  • efi_loader: run a specific efi application more easily
Related show

Commit Message

AKASHI Takahiro Dec. 18, 2018, 5:02 a.m.
With an extra argument, efi_bootmgr_load() can now load an efi binary
based on a "BootXXXX" variable specified.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 cmd/bootefi.c                | 2 +-
 include/efi_loader.h         | 3 ++-
 lib/efi_loader/efi_bootmgr.c | 9 ++++++++-
 3 files changed, 11 insertions(+), 3 deletions(-)

Comments

Alexander Graf Dec. 23, 2018, 2:05 a.m. | #1
On 18.12.18 06:02, AKASHI Takahiro wrote:
> With an extra argument, efi_bootmgr_load() can now load an efi binary
> based on a "BootXXXX" variable specified.
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>  cmd/bootefi.c                | 2 +-
>  include/efi_loader.h         | 3 ++-
>  lib/efi_loader/efi_bootmgr.c | 9 ++++++++-
>  3 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/cmd/bootefi.c b/cmd/bootefi.c
> index 7012d72ab50d..3ebae1cdad08 100644
> --- a/cmd/bootefi.c
> +++ b/cmd/bootefi.c
> @@ -452,7 +452,7 @@ static int do_bootefi_bootmgr_exec(void)
>  	void *addr;
>  	efi_status_t r;
>  
> -	addr = efi_bootmgr_load(&device_path, &file_path);
> +	addr = efi_bootmgr_load(-1, &device_path, &file_path);

Please make the -1 a special #define that is more verbose to readers.
Something like EFI_BOOTMGR_DEFAULT_ORDER.


Alex
AKASHI Takahiro Dec. 25, 2018, 9:44 a.m. | #2
On Sun, Dec 23, 2018 at 03:05:42AM +0100, Alexander Graf wrote:
> 
> 
> On 18.12.18 06:02, AKASHI Takahiro wrote:
> > With an extra argument, efi_bootmgr_load() can now load an efi binary
> > based on a "BootXXXX" variable specified.
> > 
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > ---
> >  cmd/bootefi.c                | 2 +-
> >  include/efi_loader.h         | 3 ++-
> >  lib/efi_loader/efi_bootmgr.c | 9 ++++++++-
> >  3 files changed, 11 insertions(+), 3 deletions(-)
> > 
> > diff --git a/cmd/bootefi.c b/cmd/bootefi.c
> > index 7012d72ab50d..3ebae1cdad08 100644
> > --- a/cmd/bootefi.c
> > +++ b/cmd/bootefi.c
> > @@ -452,7 +452,7 @@ static int do_bootefi_bootmgr_exec(void)
> >  	void *addr;
> >  	efi_status_t r;
> >  
> > -	addr = efi_bootmgr_load(&device_path, &file_path);
> > +	addr = efi_bootmgr_load(-1, &device_path, &file_path);
> 
> Please make the -1 a special #define that is more verbose to readers.
> Something like EFI_BOOTMGR_DEFAULT_ORDER.

OK
Add it to efi_loader.h

-Takahiro Akashi

> 
> Alex

Patch

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 7012d72ab50d..3ebae1cdad08 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -452,7 +452,7 @@  static int do_bootefi_bootmgr_exec(void)
 	void *addr;
 	efi_status_t r;
 
-	addr = efi_bootmgr_load(&device_path, &file_path);
+	addr = efi_bootmgr_load(-1, &device_path, &file_path);
 	if (!addr)
 		return 1;
 
diff --git a/include/efi_loader.h b/include/efi_loader.h
index dd68cfce5c65..5a6321122c9c 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -551,7 +551,8 @@  struct efi_load_option {
 
 void efi_deserialize_load_option(struct efi_load_option *lo, u8 *data);
 unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data);
-void *efi_bootmgr_load(struct efi_device_path **device_path,
+void *efi_bootmgr_load(int boot_id,
+		       struct efi_device_path **device_path,
 		       struct efi_device_path **file_path);
 
 #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index a54ae28343ce..db391147fb2d 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -180,7 +180,8 @@  error:
  * available load-options, finding and returning the first one that can
  * be loaded successfully.
  */
-void *efi_bootmgr_load(struct efi_device_path **device_path,
+void *efi_bootmgr_load(int boot_id,
+		       struct efi_device_path **device_path,
 		       struct efi_device_path **file_path)
 {
 	u16 bootnext, *bootorder;
@@ -195,6 +196,12 @@  void *efi_bootmgr_load(struct efi_device_path **device_path,
 	bs = systab.boottime;
 	rs = systab.runtime;
 
+	/* specified boot option */
+	if (boot_id != -1) {
+		image = try_load_entry(boot_id, device_path, file_path);
+		goto error;
+	}
+
 	/* BootNext */
 	size = sizeof(bootnext);
 	ret = rs->get_variable(L"BootNext",