diff mbox series

[v3,2/4] efi_loader: function to get GUID for variable name

Message ID 20211003092320.4671-3-heinrich.schuchardt@canonical.com
State Accepted, archived
Delegated to: Heinrich Schuchardt
Headers show
Series efi_loader: centralize known vendor GUIDs | expand

Commit Message

Heinrich Schuchardt Oct. 3, 2021, 9:23 a.m. UTC
In multiple places we need the default GUID matching a variable name.
The patch provides a library function. For secure boot related variables
like 'PK', 'KEK', 'db' a lookup table is used. For all other variable
names EFI_GLOBAL_VARIABLE is returned.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
v3:
	no change
v2:
	adjust function documentation
---
 include/efi_variable.h          | 11 +++++++++++
 lib/efi_loader/efi_var_common.c |  9 +++++++++
 2 files changed, 20 insertions(+)

Comments

Ilias Apalodimas Oct. 6, 2021, 6:25 a.m. UTC | #1
On Sun, Oct 03, 2021 at 11:23:18AM +0200, Heinrich Schuchardt wrote:
> In multiple places we need the default GUID matching a variable name.
> The patch provides a library function. For secure boot related variables
> like 'PK', 'KEK', 'db' a lookup table is used. For all other variable
> names EFI_GLOBAL_VARIABLE is returned.
> 
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
> v3:
> 	no change
> v2:
> 	adjust function documentation
> ---
>  include/efi_variable.h          | 11 +++++++++++
>  lib/efi_loader/efi_var_common.c |  9 +++++++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/include/efi_variable.h b/include/efi_variable.h
> index 8f666b2309..74909e8ec6 100644
> --- a/include/efi_variable.h
> +++ b/include/efi_variable.h
> @@ -256,6 +256,17 @@ efi_status_t efi_init_secure_state(void);
>  enum efi_auth_var_type efi_auth_var_get_type(const u16 *name,
>  					     const efi_guid_t *guid);
>  
> +/**
> + * efi_auth_var_get_guid() - get the predefined GUID for a variable name
> + *
> + * For secure boot related variables a lookup table is used to determine
> + * the GUID. For all other variables EFI_GLOBAL_VARIABLE is returned.
> + *
> + * @name:	name of UEFI variable
> + * Return:	guid of UEFI variable
> + */
> +const efi_guid_t *efi_auth_var_get_guid(const u16 *name);
> +
>  /**
>   * efi_get_next_variable_name_mem() - Runtime common code across efi variable
>   *                                    implementations for GetNextVariable()
> diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c
> index e179932124..3cbb7c96c2 100644
> --- a/lib/efi_loader/efi_var_common.c
> +++ b/lib/efi_loader/efi_var_common.c
> @@ -385,6 +385,15 @@ enum efi_auth_var_type efi_auth_var_get_type(const u16 *name,
>  	return EFI_AUTH_VAR_NONE;
>  }
>  
> +const efi_guid_t *efi_auth_var_get_guid(const u16 *name)
> +{
> +	for (size_t i = 0; i < ARRAY_SIZE(name_type); ++i) {
> +		if (!u16_strcmp(name, name_type[i].name))
> +			return name_type[i].guid;
> +	}
> +	return &efi_global_variable_guid;
> +}
> +
>  /**
>   * efi_get_var() - read value of an EFI variable
>   *
> -- 
> 2.32.0
> 

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
diff mbox series

Patch

diff --git a/include/efi_variable.h b/include/efi_variable.h
index 8f666b2309..74909e8ec6 100644
--- a/include/efi_variable.h
+++ b/include/efi_variable.h
@@ -256,6 +256,17 @@  efi_status_t efi_init_secure_state(void);
 enum efi_auth_var_type efi_auth_var_get_type(const u16 *name,
 					     const efi_guid_t *guid);
 
+/**
+ * efi_auth_var_get_guid() - get the predefined GUID for a variable name
+ *
+ * For secure boot related variables a lookup table is used to determine
+ * the GUID. For all other variables EFI_GLOBAL_VARIABLE is returned.
+ *
+ * @name:	name of UEFI variable
+ * Return:	guid of UEFI variable
+ */
+const efi_guid_t *efi_auth_var_get_guid(const u16 *name);
+
 /**
  * efi_get_next_variable_name_mem() - Runtime common code across efi variable
  *                                    implementations for GetNextVariable()
diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c
index e179932124..3cbb7c96c2 100644
--- a/lib/efi_loader/efi_var_common.c
+++ b/lib/efi_loader/efi_var_common.c
@@ -385,6 +385,15 @@  enum efi_auth_var_type efi_auth_var_get_type(const u16 *name,
 	return EFI_AUTH_VAR_NONE;
 }
 
+const efi_guid_t *efi_auth_var_get_guid(const u16 *name)
+{
+	for (size_t i = 0; i < ARRAY_SIZE(name_type); ++i) {
+		if (!u16_strcmp(name, name_type[i].name))
+			return name_type[i].guid;
+	}
+	return &efi_global_variable_guid;
+}
+
 /**
  * efi_get_var() - read value of an EFI variable
  *