Ilias Apalodimas 00da8d65a3 efi_loader: add an EFI variable with the file contents
Previous patches enabled SetVariableRT using a RAM backend.
Although EBBR [0] defines a variable format we can teach userspace tools
and write the altered variables, it's better if we skip the ABI
requirements completely.

So let's add a new variable, in its own namespace called "VarToFile"
which contains a binary dump of the updated RT, BS and, NV variables
and will be updated when GetVariable is called.

Some adjustments are needed to do that.
Currently we discard BS-only variables in EBS(). We need to preserve
those on the RAM backend that exposes the variables. Since BS-only
variables can't appear at runtime we need to move the memory masking
checks from efi_var_collect() to efi_get_next_variable_name_mem()/
efi_get_variable_mem() and do the filtering at runtime.

We also need an efi_var_collect() variant available at runtime, in order
to construct the "VarToFile" buffer on the fly.

All users and applications (for linux) have to do when updating a variable
is dd that variable in the file described by "RTStorageVolatile".

Linux efivarfs uses a first 4 bytes of the output to represent attributes
in little-endian format. So, storing variables works like this:

$~ efibootmgr -n 0001
$~ dd if=/sys/firmware/efi/efivars/VarToFile-b2ac5fc9-92b7-4acd-aeac-11e818c3130c of=/boot/efi/ubootefi.var skip=4 bs=1

[0] https://arm-software.github.io/ebbr/index.html#document-chapter5-variable-storage

Suggested-by: Ard Biesheuvel <ardb@kernel.org> # dumping all variables to a variable
Co-developed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> # contributed on efi_var_collect_mem()
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-04-20 08:22:24 +02:00
..
2024-01-03 09:22:47 -05:00
2024-03-14 18:19:44 +08:00
2022-10-30 20:07:16 +01:00
2023-08-25 13:54:33 -04:00
2023-08-08 10:22:03 -04:00
2023-12-21 08:54:37 -05:00
2023-12-13 11:51:24 -05:00
2024-02-13 15:38:49 -05:00
2024-01-29 22:35:02 -05:00
2022-11-02 08:42:03 +01:00
2023-02-06 13:04:52 -05:00
2023-10-23 17:07:06 +03:00
2023-05-02 14:23:34 -04:00
2023-05-15 10:00:30 +02:00
2023-01-20 12:27:06 -05:00
2023-11-07 14:50:51 -05:00
2024-01-13 18:17:47 +01:00
2023-12-21 08:54:37 -05:00
2023-10-31 09:08:51 +01:00
2023-04-27 13:51:06 -04:00
2024-03-01 14:44:35 +00:00
2023-12-21 11:59:49 -05:00
2023-08-19 04:12:53 +02:00
2023-12-13 11:35:13 -05:00
2022-10-30 20:07:17 +01:00
2023-12-21 08:54:37 -05:00
2023-10-11 15:43:55 -04:00
2024-04-15 15:19:12 +09:00
2023-11-16 12:43:49 -05:00
2023-12-21 08:54:37 -05:00
2023-11-18 10:08:09 +02:00
2024-03-26 19:58:26 -04:00
2024-03-26 19:58:26 -04:00
2023-01-16 18:01:10 +08:00
2023-12-21 08:54:37 -05:00
2023-10-15 12:23:48 +02:00
2024-03-27 09:23:30 +01:00
2023-11-16 13:49:14 -05:00
2023-10-09 15:24:31 -04:00
2023-02-10 07:41:40 -05:00
2023-10-27 13:14:47 +03:00
2022-12-07 16:04:17 -05:00
2022-12-22 10:31:49 -05:00
2023-11-14 20:04:00 -07:00