system76 / firmware-update

System76 Firmware Update Utility
GNU General Public License v3.0
204 stars 15 forks source link

Migrate SMMSTOREv1 data to NV Data FV #48

Closed crawfxrd closed 2 years ago

crawfxrd commented 3 years ago

As part of the next firmware update we will switch from SMMSTOREv1 to SMMSTOREv2. Migrate existing SMMSTOREv1 data to UEFI variable store data used in edk2.

The migration cannot happen after flashing because BlSMMStoreDxe will erase the store on the next boot if the volume is not valid, deleting all variables.

  1. Detect if there is an SMMSTORE region
    • Already done for copying the existing store
  2. Determine if it is an NV Data Firmware Volume
    • Check for the firmware volume header
    • If true, assume data is valid and copy the region as-is
    • If false, assume it is SMMSTOREv1 and convert it
  3. Convert raw SMMSTOREv1 data into a data structure and remove duplicates
    • Implemented in firmware-smmstore as deserialize()
  4. Write the firmware volume and variable store headers to the new slice
    • InitializeFvAndVariableStoreHeaders() is the corresponding function in edk2
    • Hard-coded assumptions must be made about the SMMSTORE's total size (256k), block size (64k), and if FTWs are enabled in edk2 (true)
  5. Write out SMMSTOREv1 records as UEFI variables

TODO: