[5/8,v2] efi_loader: bootmgr: Use get_var from efi_helper file

Message ID 20201230150722.154663-6-ilias.apalodimas@linaro.org
State New
Headers show
Series
  • Change logic of EFI LoadFile2 protocol for initrd loading
Related show

Commit Message

Ilias Apalodimas Dec. 30, 2020, 3:07 p.m.
A few patches before we introduced a file which includes the get_var_efi()
function defined in the efi bootmanager.
So let's replace it here and use the common function as much as we can.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

---
 lib/efi_loader/Makefile      |  2 +-
 lib/efi_loader/efi_bootmgr.c | 37 +++---------------------------------
 2 files changed, 4 insertions(+), 35 deletions(-)

-- 
2.30.0

Comments

Heinrich Schuchardt Dec. 30, 2020, 7:32 p.m. | #1
On 12/30/20 4:07 PM, Ilias Apalodimas wrote:
> A few patches before we introduced a file which includes the get_var_efi()

> function defined in the efi bootmanager.

> So let's replace it here and use the common function as much as we can.

>

> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

> ---

>   lib/efi_loader/Makefile      |  2 +-

>   lib/efi_loader/efi_bootmgr.c | 37 +++---------------------------------

>   2 files changed, 4 insertions(+), 35 deletions(-)

>

> diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile

> index cd4b252a417c..a47160189c42 100644

> --- a/lib/efi_loader/Makefile

> +++ b/lib/efi_loader/Makefile

> @@ -21,7 +21,7 @@ targets += helloworld.o

>   endif

>

>   obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o

> -obj-y += efi_bootmgr.o

> +obj-y += efi_helper.o efi_bootmgr.o

>   obj-y += efi_boottime.o

>   obj-y += efi_console.o

>   obj-y += efi_device_path.o

> diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c

> index 61dc72a23da8..0221fd1261b3 100644

> --- a/lib/efi_loader/efi_bootmgr.c

> +++ b/lib/efi_loader/efi_bootmgr.c

> @@ -11,6 +11,7 @@

>   #include <charset.h>

>   #include <log.h>

>   #include <malloc.h>

> +#include <efi_helper.h>

>   #include <efi_loader.h>

>   #include <efi_variable.h>

>   #include <asm/unaligned.h>

> @@ -165,38 +166,6 @@ unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data)

>   	return size;

>   }

>

> -/**

> - * get_var() - get UEFI variable

> - *

> - * It is the caller's duty to free the returned buffer.

> - *

> - * @name:	name of variable

> - * @vendor:	vendor GUID of variable

> - * @size:	size of allocated buffer

> - * Return:	buffer with variable data or NULL

> - */

> -static void *get_var(u16 *name, const efi_guid_t *vendor,

> -		     efi_uintn_t *size)

> -{

> -	efi_status_t ret;

> -	void *buf = NULL;

> -

> -	*size = 0;

> -	ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL);

> -	if (ret == EFI_BUFFER_TOO_SMALL) {

> -		buf = malloc(*size);

> -		ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL);

> -	}

> -

> -	if (ret != EFI_SUCCESS) {

> -		free(buf);

> -		*size = 0;

> -		return NULL;

> -	}

> -

> -	return buf;

> -}

> -

>   /**

>    * try_load_entry() - try to load image for boot option

>    *

> @@ -224,7 +193,7 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle,

>   	varname[6] = hexmap[(n & 0x00f0) >> 4];

>   	varname[7] = hexmap[(n & 0x000f) >> 0];

>

> -	load_option = get_var(varname, &efi_global_variable_guid, &size);

> +	load_option = get_var_efi(varname, &efi_global_variable_guid, &size);

>   	if (!load_option)

>   		return EFI_LOAD_ERROR;

>

> @@ -336,7 +305,7 @@ efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options)

>   	}

>

>   	/* BootOrder */

> -	bootorder = get_var(L"BootOrder", &efi_global_variable_guid, &size);

> +	bootorder = get_var_efi(L"BootOrder", &efi_global_variable_guid, &size);


efi_var_get() would be more in line with our naming of other UEFI
related functions.

Best regards

Heinrich

>   	if (!bootorder) {

>   		log_info("BootOrder not defined\n");

>   		ret = EFI_NOT_FOUND;

>

Patch

diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index cd4b252a417c..a47160189c42 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -21,7 +21,7 @@  targets += helloworld.o
 endif
 
 obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
-obj-y += efi_bootmgr.o
+obj-y += efi_helper.o efi_bootmgr.o
 obj-y += efi_boottime.o
 obj-y += efi_console.o
 obj-y += efi_device_path.o
diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 61dc72a23da8..0221fd1261b3 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -11,6 +11,7 @@ 
 #include <charset.h>
 #include <log.h>
 #include <malloc.h>
+#include <efi_helper.h>
 #include <efi_loader.h>
 #include <efi_variable.h>
 #include <asm/unaligned.h>
@@ -165,38 +166,6 @@  unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data)
 	return size;
 }
 
-/**
- * get_var() - get UEFI variable
- *
- * It is the caller's duty to free the returned buffer.
- *
- * @name:	name of variable
- * @vendor:	vendor GUID of variable
- * @size:	size of allocated buffer
- * Return:	buffer with variable data or NULL
- */
-static void *get_var(u16 *name, const efi_guid_t *vendor,
-		     efi_uintn_t *size)
-{
-	efi_status_t ret;
-	void *buf = NULL;
-
-	*size = 0;
-	ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL);
-	if (ret == EFI_BUFFER_TOO_SMALL) {
-		buf = malloc(*size);
-		ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL);
-	}
-
-	if (ret != EFI_SUCCESS) {
-		free(buf);
-		*size = 0;
-		return NULL;
-	}
-
-	return buf;
-}
-
 /**
  * try_load_entry() - try to load image for boot option
  *
@@ -224,7 +193,7 @@  static efi_status_t try_load_entry(u16 n, efi_handle_t *handle,
 	varname[6] = hexmap[(n & 0x00f0) >> 4];
 	varname[7] = hexmap[(n & 0x000f) >> 0];
 
-	load_option = get_var(varname, &efi_global_variable_guid, &size);
+	load_option = get_var_efi(varname, &efi_global_variable_guid, &size);
 	if (!load_option)
 		return EFI_LOAD_ERROR;
 
@@ -336,7 +305,7 @@  efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options)
 	}
 
 	/* BootOrder */
-	bootorder = get_var(L"BootOrder", &efi_global_variable_guid, &size);
+	bootorder = get_var_efi(L"BootOrder", &efi_global_variable_guid, &size);
 	if (!bootorder) {
 		log_info("BootOrder not defined\n");
 		ret = EFI_NOT_FOUND;