From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: Shantur Rathore <i@shantur.com>
Cc: u-boot@lists.denx.de, Simon Glass <sjg@chromium.org>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>
Subject: Re: [PATCH v1 1/3] efi: filestore: don't compile when config disabled
Date: Wed, 22 Nov 2023 11:13:52 +0900 [thread overview]
Message-ID: <ZV1j4AQfWLD5K/OK@octopus> (raw)
In-Reply-To: <20231121235713.1530289-2-i@shantur.com>
On Tue, Nov 21, 2023 at 11:57:11PM +0000, Shantur Rathore wrote:
> Compile out filestore functions when config isn't enabled.
>
> Signed-off-by: Shantur Rathore <i@shantur.com>
> ---
>
> include/efi_variable.h | 21 ++++++++++++---------
> lib/efi_loader/efi_var_file.c | 13 +++++++------
> lib/efi_loader/efi_variable.c | 10 +++++++++-
> 3 files changed, 28 insertions(+), 16 deletions(-)
>
> diff --git a/include/efi_variable.h b/include/efi_variable.h
> index 805e6c5f1e..ca7e19d514 100644
> --- a/include/efi_variable.h
> +++ b/include/efi_variable.h
> @@ -136,15 +136,6 @@ struct efi_var_file {
> struct efi_var_entry var[];
> };
>
> -/**
> - * efi_var_to_file() - save non-volatile variables as file
> - *
> - * File ubootefi.var is created on the EFI system partion.
> - *
> - * Return: status code
> - */
> -efi_status_t efi_var_to_file(void);
> -
> /**
> * efi_var_collect() - collect variables in buffer
> *
> @@ -172,6 +163,16 @@ efi_status_t __maybe_unused efi_var_collect(struct efi_var_file **bufp, loff_t *
> */
> efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe);
>
> +#ifdef CONFIG_EFI_VARIABLE_FILE_STORE
I don't think we need this guard because any function declaration
in a header is harmless even if that function implementation is opted out.
> +/**
> + * efi_var_to_file() - save non-volatile variables as file
> + *
> + * File ubootefi.var is created on the EFI system parition.
> + *
> + * Return: status code
> + */
> +efi_status_t efi_var_to_file(void);
> +
> /**
> * efi_var_from_file() - read variables from file
> *
> @@ -185,6 +186,8 @@ efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe);
> */
> efi_status_t efi_var_from_file(void);
>
> +#endif // CONFIG_EFI_VARIABLE_FILE_STORE
> +
> /**
> * efi_var_mem_init() - set-up variable list
> *
> diff --git a/lib/efi_loader/efi_var_file.c b/lib/efi_loader/efi_var_file.c
> index 62e071bd83..7ceb7e3cf7 100644
> --- a/lib/efi_loader/efi_var_file.c
> +++ b/lib/efi_loader/efi_var_file.c
> @@ -117,6 +117,8 @@ efi_status_t __maybe_unused efi_var_collect(struct efi_var_file **bufp, loff_t *
> return EFI_SUCCESS;
> }
>
> +#ifdef CONFIG_EFI_VARIABLE_FILE_STORE
Can you refactor the code further to purge all "#ifdef" stuffs from this file?
I mean:
1) move efi_var_collect/restor() to a always-compiled file, say,
efi_var_common.c/efi_variable.c
2) modify call sites of the other functions, for example, as follows:
if (CONFIG_IS_ENABLED(EFI_VARIABLE_STORE))
efi_var_to_file();
# I'm not sure why the return code is ignored everywhere.
3) modify Makefile to compile efi_var_file.c only if EFI_VARIABLE_FILE_STORE
is enabled
4) remove "#ifdef CONFIG_EFI_VARIABLE_FILE_STORE" from efi_var_file.c
-Takahiro Akashi
> +
> /**
> * efi_var_to_file() - save non-volatile variables as file
> *
> @@ -126,7 +128,6 @@ efi_status_t __maybe_unused efi_var_collect(struct efi_var_file **bufp, loff_t *
> */
> efi_status_t efi_var_to_file(void)
> {
> -#ifdef CONFIG_EFI_VARIABLE_FILE_STORE
> efi_status_t ret;
> struct efi_var_file *buf;
> loff_t len;
> @@ -150,11 +151,10 @@ error:
> log_err("Failed to persist EFI variables\n");
> free(buf);
> return ret;
> -#else
> - return EFI_SUCCESS;
> -#endif
> }
>
> +#endif // CONFIG_EFI_VARIABLE_FILE_STORE
> +
> efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe)
> {
> struct efi_var_entry *var, *last_var;
> @@ -198,6 +198,7 @@ efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe)
> return EFI_SUCCESS;
> }
>
> +#ifdef CONFIG_EFI_VARIABLE_FILE_STORE
> /**
> * efi_var_from_file() - read variables from file
> *
> @@ -211,7 +212,6 @@ efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe)
> */
> efi_status_t efi_var_from_file(void)
> {
> -#ifdef CONFIG_EFI_VARIABLE_FILE_STORE
> struct efi_var_file *buf;
> loff_t len;
> efi_status_t ret;
> @@ -236,6 +236,7 @@ efi_status_t efi_var_from_file(void)
> log_err("Invalid EFI variables file\n");
> error:
> free(buf);
> -#endif
> return EFI_SUCCESS;
> }
> +
> +#endif // CONFIG_EFI_VARIABLE_FILE_STORE
> diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
> index be95ed44e6..7fa444451d 100644
> --- a/lib/efi_loader/efi_variable.c
> +++ b/lib/efi_loader/efi_variable.c
> @@ -357,8 +357,11 @@ efi_status_t efi_set_variable_int(const u16 *variable_name,
> * Write non-volatile EFI variables to file
> * TODO: check if a value change has occured to avoid superfluous writes
> */
> - if (attributes & EFI_VARIABLE_NON_VOLATILE)
> + if (attributes & EFI_VARIABLE_NON_VOLATILE) {
> +#ifdef CONFIG_EFI_VARIABLE_FILE_STORE
> efi_var_to_file();
> +#endif
> + }
>
> return EFI_SUCCESS;
> }
> @@ -466,7 +469,12 @@ efi_status_t efi_init_variables(void)
> if (ret != EFI_SUCCESS)
> return ret;
>
> +#ifdef CONFIG_EFI_VARIABLE_FILE_STORE
> ret = efi_var_from_file();
> +#else
> + ret = EFI_SUCCESS;
> +#endif
> +
> if (ret != EFI_SUCCESS)
> return ret;
> if (IS_ENABLED(CONFIG_EFI_VARIABLES_PRESEED)) {
> --
> 2.40.1
>
next prev parent reply other threads:[~2023-11-22 2:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-21 23:57 [PATCH v1 0/3] efi_vars: SPI Flash store Shantur Rathore
2023-11-21 23:57 ` [PATCH v1 1/3] efi: filestore: don't compile when config disabled Shantur Rathore
2023-11-22 2:13 ` AKASHI Takahiro [this message]
2023-11-21 23:57 ` [PATCH v1 2/3] efi_vars: Implement SPI Flash store Shantur Rathore
2023-11-22 2:38 ` AKASHI Takahiro
2023-11-22 6:57 ` Ilias Apalodimas
2023-11-24 11:58 ` Shantur Rathore
2023-11-27 7:09 ` Ilias Apalodimas
2023-11-27 9:30 ` Shantur Rathore
2023-11-27 10:35 ` Ilias Apalodimas
2023-11-21 23:57 ` [PATCH v1 3/3] defconfig: rockpro64: Enable SF EFI var store Shantur Rathore
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=ZV1j4AQfWLD5K/OK@octopus \
--to=takahiro.akashi@linaro.org \
--cc=i@shantur.com \
--cc=ilias.apalodimas@linaro.org \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.