public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC, PATCH v4 16/16] efi_loader: variable: rework with new extended env interfaces
Date: Thu, 18 Jul 2019 09:13:51 +0900	[thread overview]
Message-ID: <20190718001351.GO21948@linaro.org> (raw)
In-Reply-To: <b1e1fc66-fbc8-8a6f-1c2f-28d6d3a93af8@gmx.de>

Heinrich,

On Wed, Jul 17, 2019 at 08:53:53PM +0200, Heinrich Schuchardt wrote:
> On 7/17/19 10:25 AM, AKASHI Takahiro wrote:
> >In UEFI variable implementation, ENVCTX_UEFI is used for context
> >and VARSTORAGE_VOLATILE and VARSTORAGE_NON_VOLATILE_AUTOSAVE are
> >allowed for variable storage attribute.
> >
> >Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> >---
> >  include/efi_loader.h          |  1 +
> >  lib/efi_loader/Kconfig        | 12 +++++++++
> >  lib/efi_loader/Makefile       |  2 +-
> >  lib/efi_loader/efi_setup.c    |  5 ++++
> >  lib/efi_loader/efi_variable.c | 50 ++++++++++++++++++++++++++---------
> >  5 files changed, 57 insertions(+), 13 deletions(-)
> >
> >diff --git a/include/efi_loader.h b/include/efi_loader.h
> >index b07155cecb7c..e119d2d2a802 100644
> >--- a/include/efi_loader.h
> >+++ b/include/efi_loader.h
> >@@ -617,6 +617,7 @@ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size,
> >  efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
> >  				     const efi_guid_t *vendor, u32 attributes,
> >  				     efi_uintn_t data_size, const void *data);
> >+efi_status_t efi_variable_init(void);
> 
> This initialization function is already defined in origin/master as
> 
> efi_status_t efi_init_variables();

As I mentioned in the previous reply, the current patch set is
based on v2019.07.

> >
> >  /*
> >   * See section 3.1.3 in the v2.7 UEFI spec for more details on
> >diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
> >index cd5436c576b1..60085a81144d 100644
> >--- a/lib/efi_loader/Kconfig
> >+++ b/lib/efi_loader/Kconfig
> >@@ -18,6 +18,18 @@ config EFI_LOADER
> >
> >  if EFI_LOADER
> >
> >+choice
> >+	prompt "Select variables storage"
> >+	default EFI_VARIABLE_USE_ENV
> >+	help
> >+	  With this option, UEFI variables are implemented using
> >+	  U-Boot environment variables.
> >+
> >+config EFI_VARIABLE_USE_ENV
> >+	bool "Dedicated context in U-Boot environment"
> 
> I could not find any place in the code where EFI_VARIABLE_USE_ENV is
> set. Why do you introduce it?

Set by default in "choice."
Once another implementation like StMM be added, you will see choices.

> >+
> >+endchoice
> >+
> >  config EFI_GET_TIME
> >  	bool "GetTime() runtime service"
> >  	depends on DM_RTC
> >diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
> >index 01769ea58ba6..a1fb0f112e5c 100644
> >--- a/lib/efi_loader/Makefile
> >+++ b/lib/efi_loader/Makefile
> >@@ -31,7 +31,7 @@ obj-y += efi_root_node.o
> >  obj-y += efi_runtime.o
> >  obj-y += efi_setup.o
> >  obj-$(CONFIG_EFI_UNICODE_COLLATION_PROTOCOL2) += efi_unicode_collation.o
> >-obj-y += efi_variable.o
> >+obj-$(CONFIG_EFI_VARIABLE_USE_ENV) += efi_variable.o
> >  obj-y += efi_watchdog.o
> >  obj-$(CONFIG_LCD) += efi_gop.o
> >  obj-$(CONFIG_DM_VIDEO) += efi_gop.o
> >diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
> >index bfb57836fa9f..e96c92474467 100644
> >--- a/lib/efi_loader/efi_setup.c
> >+++ b/lib/efi_loader/efi_setup.c
> >@@ -102,6 +102,11 @@ efi_status_t efi_init_obj_list(void)
> >  	/* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */
> >  	switch_to_non_secure_mode();
> >
> >+	/* Initialize UEFI variables */
> >+	ret = efi_variable_init();
> 
> We already call efi_init_variables() here.
> 
> >+	if (ret != EFI_SUCCESS)
> >+		goto out;
> >+
> >  	/* Define supported languages */
> >  	ret = efi_init_platform_lang();
> >  	if (ret != EFI_SUCCESS)
> >diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
> >index d6b75ca02e45..115a1f593058 100644
> >--- a/lib/efi_loader/efi_variable.c
> >+++ b/lib/efi_loader/efi_variable.c
> >@@ -8,6 +8,7 @@
> >  #include <malloc.h>
> >  #include <charset.h>
> >  #include <efi_loader.h>
> >+#include <exports.h>
> >  #include <hexdump.h>
> >  #include <environment.h>
> >  #include <search.h>
> >@@ -184,7 +185,7 @@ efi_status_t EFIAPI efi_get_variable(u16 *variable_name,
> >
> >  	EFI_PRINT("get '%s'\n", native_name);
> >
> >-	val = env_get(native_name);
> >+	val = env_get_ext(ENVCTX_UEFI, native_name, NULL);
> >  	free(native_name);
> >  	if (!val)
> >  		return EFI_EXIT(EFI_NOT_FOUND);
> >@@ -272,7 +273,7 @@ static efi_status_t parse_uboot_variable(char *variable,
> >  					 const efi_guid_t *vendor,
> >  					 u32 *attributes)
> >  {
> >-	char *guid, *name, *end, c;
> >+	char *guid, *name, *env_attr, *end, c;
> >  	unsigned long name_len;
> >  	u16 *p;
> >
> >@@ -284,11 +285,14 @@ static efi_status_t parse_uboot_variable(char *variable,
> >  	if (!name)
> >  		return EFI_INVALID_PARAMETER;
> >  	name++;
> >-	end = strchr(name, '=');
> >+	env_attr = strchr(name, ':');
> >+	if (!env_attr)
> >+		return EFI_INVALID_PARAMETER;
> >+	end = strchr(env_attr, '=');
> >  	if (!end)
> >  		return EFI_INVALID_PARAMETER;
> >
> >-	name_len = end - name;
> >+	name_len = env_attr - name;
> >  	if (*variable_name_size < (name_len + 1)) {
> >  		*variable_name_size = name_len + 1;
> >  		return EFI_BUFFER_TOO_SMALL;
> >@@ -360,7 +364,7 @@ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size,
> >  		name_len = strlen(native_name);
> >  		for (variable = efi_variables_list; variable && *variable;) {
> >  			if (!strncmp(variable, native_name, name_len) &&
> >-			    variable[name_len] == '=')
> >+			    variable[name_len] == ':')
> >  				break;
> >
> >  			variable = strchr(variable, '\n');
> >@@ -387,9 +391,9 @@ efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size,
> >  		efi_cur_variable = NULL;
> >
> >  		snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_.*");
> >-		list_len = hexport_r(&env_htab, '\n',
> >-				     H_MATCH_REGEX | H_MATCH_KEY,
> >-				     &efi_variables_list, 0, 1, regexlist);
> >+		list_len = hexport_ext(&env_htab, ENVCTX_UEFI, '\n',
> >+				       H_MATCH_REGEX | H_MATCH_KEY,
> >+				       &efi_variables_list, 0, 1, regexlist);
> >  		/* 1 indicates that no match was found */
> >  		if (list_len <= 1)
> >  			return EFI_EXIT(EFI_NOT_FOUND);
> >@@ -424,7 +428,7 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
> >  {
> >  	char *native_name = NULL, *val = NULL, *s;
> >  	efi_status_t ret = EFI_SUCCESS;
> >-	u32 attr;
> >+	u32 attr, flags;
> >
> >  	EFI_ENTRY("\"%ls\" %pUl %x %zu %p", variable_name, vendor, attributes,
> >  		  data_size, data);
> >@@ -446,12 +450,12 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
> >
> >  	if ((data_size == 0) || !(attributes & ACCESS_ATTR)) {
> >  		/* delete the variable: */
> >-		env_set(native_name, NULL);
> >+		env_set_ext(ENVCTX_UEFI, native_name, 0, NULL);
> >  		ret = EFI_SUCCESS;
> >  		goto out;
> >  	}
> >
> >-	val = env_get(native_name);
> >+	val = env_get_ext(ENVCTX_UEFI, native_name, NULL);
> >  	if (val) {
> >  		parse_attr(val, &attr);
> >
> >@@ -484,6 +488,8 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
> >  	 * store attributes
> >  	 * TODO: several attributes are not supported
> >  	 */
> >+	flags =	(attributes & EFI_VARIABLE_NON_VOLATILE) ?
> >+			ENV_FLAGS_VARSTORAGE_NON_VOLATILE_AUTOSAVE : 0;
> >  	attributes &= (EFI_VARIABLE_NON_VOLATILE |
> >  		       EFI_VARIABLE_BOOTSERVICE_ACCESS |
> >  		       EFI_VARIABLE_RUNTIME_ACCESS);
> >@@ -511,7 +517,8 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
> >
> >  	EFI_PRINT("setting: %s=%s\n", native_name, val);
> >
> >-	if (env_set(native_name, val))
> >+	/* TODO: type: string, access: READ/WRITE/CREATE/DELETE */
> >+	if (env_set_ext(ENVCTX_UEFI, native_name, flags, val))
> >  		ret = EFI_DEVICE_ERROR;
> >
> >  out:
> >@@ -520,3 +527,22 @@ out:
> >
> >  	return EFI_EXIT(ret);
> >  }
> >+
> >+efi_status_t efi_variable_init(void)
> 
> Please, rebase your patch on the existing coding.
> 
> 
> >+{
> >+	int ret;
> >+
> >+	ret = env_load_ext(ENVCTX_UEFI);
> >+	if (ret)
> >+#if 1
> 
> There is no need for the #if. Please, remove the unused code.

I know. This is just a reminder of the "FIXME" below.

> >+		/*
> >+		 * FIXME:
> >+		 * It is valid even if initial file in FAT doesn't exist
> 
> What will the correct handling look like?

Probably env_load() should be modified consistently across all drivers
to return, say, ENOENT? so that we can distinguish and handle the case
properly.

Thanks,
-Takahiro Akashi

> Best regards
> 
> Heinrich
> 
> >+		 */
> >+		return EFI_SUCCESS;
> >+#else
> >+		return EFI_DEVICE_ERROR;
> >+#endif
> >+
> >+	return EFI_SUCCESS;
> >+}
> >
> 

  reply	other threads:[~2019-07-18  0:13 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-17  8:25 [U-Boot] [RFC, PATCH v4 00/16] efi_loader: non-volatile variables support AKASHI Takahiro
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 01/16] hashtable: extend interfaces to handle entries with context AKASHI Takahiro
2019-07-19  6:58   ` Wolfgang Denk
2019-07-19  7:44     ` AKASHI Takahiro
2019-07-19  9:49       ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 02/16] env: extend interfaces to import/export U-Boot environment per context AKASHI Takahiro
2019-07-19  7:38   ` Wolfgang Denk
2019-07-19  8:15     ` AKASHI Takahiro
2019-07-19 10:04       ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 03/16] env: extend interfaces to label variable with context AKASHI Takahiro
2019-07-19  8:09   ` Wolfgang Denk
2019-07-19  8:25     ` AKASHI Takahiro
2019-07-19 13:06       ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 04/16] env: flash: add U-Boot environment context support AKASHI Takahiro
2019-07-19  8:14   ` Wolfgang Denk
2019-07-19  8:30     ` AKASHI Takahiro
2019-07-19 13:11       ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 05/16] env: fat: " AKASHI Takahiro
2019-07-19  8:21   ` Wolfgang Denk
2019-07-19  8:35     ` AKASHI Takahiro
2019-07-19 13:14       ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 06/16] env: add variable storage attribute support AKASHI Takahiro
2019-07-19  8:35   ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 07/16] env: add/expose attribute helper functions for hashtable AKASHI Takahiro
2019-07-19  8:36   ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 08/16] hashtable: import/export entries with flags AKASHI Takahiro
2019-07-19  8:38   ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 09/16] hashtable: extend hdelete_ext for autosave AKASHI Takahiro
2019-07-19  8:41   ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 10/16] env: save non-volatile variables only AKASHI Takahiro
2019-07-19  8:45   ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 11/16] env: save a context immediately if 'autosave' variable is changed AKASHI Takahiro
2019-07-19  8:48   ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 12/16] env: extend interfaces to get/set attributes AKASHI Takahiro
2019-07-19  8:50   ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 13/16] cmd: env: show variable storage attribute in "env flags" command AKASHI Takahiro
2019-07-19  9:05   ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC,PATCH v4 14/16] env: fat: support UEFI context AKASHI Takahiro
2019-07-19  9:08   ` Wolfgang Denk
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 15/16] env, efi_loader: define flags for well-known global UEFI variables AKASHI Takahiro
2019-07-17  8:25 ` [U-Boot] [RFC, PATCH v4 16/16] efi_loader: variable: rework with new extended env interfaces AKASHI Takahiro
2019-07-17 18:53   ` Heinrich Schuchardt
2019-07-18  0:13     ` AKASHI Takahiro [this message]
2019-07-17 19:05 ` [U-Boot] [RFC, PATCH v4 00/16] efi_loader: non-volatile variables support Heinrich Schuchardt
2019-07-18  0:04   ` AKASHI Takahiro
2019-07-19  6:50 ` Wolfgang Denk
2019-07-19  7:36   ` AKASHI Takahiro
2019-07-19  9:41     ` Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190718001351.GO21948@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox