[PATCH v2 0/4] Enable SetVariable at runtime

Ilias Apalodimas ilias.apalodimas at linaro.org
Wed Apr 17 12:19:21 CEST 2024


Hi all,
This is the new version of [0]

The main difference from v1 is that VarToFile is now filled on the fly,
during a GetVariable call for it, instead of creating it during
SetVariable.

The advantage of doing that is memory efficiency, since the buffer comes
from the OS now and we don't have to allocate and preserve runtime memory
to copy things around. We also don't consume space from the existsing
variable storage.

The disadvantage is that it complicates the code a bit more since we need
to check for the variable name in GetVariable. We also need a function to
collect variables at runtime that operates on the memory backend.

In the future we can clean up and try to unify efi_var_collectXXX() variants,
but I'd rather keep tha patchset simpler for now.
We will also need support for QueryVariableInfo, which I will send in
another series as part of a cleanup since it's mostly supported already.

Changes since v1:
- Instead of Creating VarToFile at SetVariable, create it on GetVariable.
  This allows us to get rid of the preallocated RT buffer, since the
  address is user provided
- convert Set/GetVariableRT -> Set/GetVariable at runtime
- return EFI_INVALID_PARAM is NV is not set at runtime
- Heinrich sent me the efi_var_collect_mem() variant

Changes since the RFC:
- Return EFI_INVALID_PARAM if attributes are not volatile
- Add EFI_WRITE_PROTECTED checks for BS, RT *only* variables
- Add 2 EFI variables and allow userspace to write the file
- Add selftests

[0] https://lore.kernel.org/u-boot/20240406140203.248211-1-ilias.apalodimas@linaro.org/



Ilias Apalodimas (4):
  efi_loader: conditionally enable SetvariableRT
  efi_loader: Add OS notifications for SetVariable at runtime
  efi_loader: add an EFI variable with the file contents
  efi_selftest: add tests for setvariableRT

 include/efi_loader.h                          |   4 +
 include/efi_variable.h                        |  14 +-
 lib/charset.c                                 |   2 +-
 lib/efi_loader/Kconfig                        |  16 ++
 lib/efi_loader/efi_runtime.c                  |  36 +++++
 lib/efi_loader/efi_var_common.c               |   6 +-
 lib/efi_loader/efi_var_mem.c                  | 146 +++++++++++-------
 lib/efi_loader/efi_variable.c                 | 121 +++++++++++++--
 lib/efi_loader/efi_variable_tee.c             |   5 -
 .../efi_selftest_variables_runtime.c          | 116 +++++++++++++-
 10 files changed, 384 insertions(+), 82 deletions(-)

--
2.40.1



More information about the U-Boot mailing list