efivarfs: Update a file variable store On SetVariable RT #282
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Embedded boards have hardware limitations when storing and managing EFI variables. Some hardware comes with an eMMC & an RPMB partition which they use to store the EFI variables securely. However, the vast majority of boards (using U-Boot), stores the EFI variables in a file in the ESP.
This has a few limitations
Distros and capsule updates on-disk do rely on the that service though and U-Boot does implement a workaround.
U-Boot enables SetVariableRT in the RTPROP table and creates a memory backend, so the linux kernel can naturally read and write variables via the efivarfs filesystem. Those reads and writes end up in memory though. So they are visible while the OS is live and are lost in the event of a reboot.
At the same time it also creates two EFI RO variables. RTStorageVolatile -- Holds the filename the variables are stored relative to
the ESP
VarToFile -- Holds a binary dump of all the EFI variables that should be
preserved (BS, NV, RT).
By using these two variables we can persist the changes after reboots by doing
dd if=/sys/firmware/efi/efivars/VarToFile-b2ac5fc9-92b7-4acd-aeac-11e818c3130c of=/boot/efi/ubootefi.var skip=4 bs=1
So let's plug this functionality into the efivafs backend and enable it automatically if those variables are detected.