libupgrade: Ensure main/backup partition in sync
For r/w variables, hnvram maintains a main and a backup partition which
should be identical under normal circumstances. For read operations, it
looks at the main partition first and only reads the backup partition if
it fails to read the main partition. Inconsistencies go unnoticed. For
write operations, it would only write to the flash if the value being
written is different from the value that is already stored on the flash.
With this approach, we might end up in a situation where the main and
the backup partitions contain different values for the same variable,
but still, a write operation would not fix the problem.
Example: Let's say the main and backup partitions contain VAR=abc and
VAR=xyz, respectively. Previously, the command "hnvram -w VAR=abc" would
not write VAR=abc to the backup partition because a read operation
yields VAR=abc which is why it decides that no write operation is
Let's move the logic that skips unnecessary writes a few levels down
where it checks the main and backup partitions separately.
2 files changed