Skip to content

Commit

Permalink
Improve 'CleanNvram' Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dakanji committed Apr 19, 2022
1 parent 7a01922 commit 120f622
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions BootMaster/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,24 @@ EFI_STATUS TrimCoerce (VOID) {
return Status;
} // static EFI_STATUS TrimCoerce()

static
VOID NvramGarbageCollectionMac (IN BOOLEAN Activate) {
CHAR8 DataNVRAM[1] = {0x01};
UINT32 StorageFlags = APPLE_FLAGS;

if (!AppleFirmware) {
// Early Return
return;
}

REFIT_CALL_5_WRAPPER(
gRT->SetVariable, L"ResetNVRam",
&AppleGuid, StorageFlags,
(Activate) ? sizeof (DataNVRAM) : 0,
(Activate) ? DataNVRAM : NULL
);
} // static VOID NvramGarbageCollectionMac()


// Extended 'OpenProtocol'
// Ensures GOP Interface for Boot Loading Screen
Expand Down Expand Up @@ -1949,6 +1967,9 @@ EFI_STATUS EFIAPI efi_main (
/* Remove any recovery boot flags */
ClearRecoveryBootFlag();

// Deactivate forced nvram garbage collection on Macs (if present)
NvramGarbageCollectionMac(FALSE);

/* Other Preambles */
EFI_TIME Now;
REFIT_CALL_2_WRAPPER(gRT->GetTime, &Now, NULL);
Expand Down Expand Up @@ -2823,6 +2844,9 @@ EFI_STATUS EFIAPI efi_main (
LOG_MSG("\n\n");
#endif

// Try to force nvram garbage collection on Macs
NvramGarbageCollectionMac(TRUE);

// No Break
case TAG_REBOOT: // Reboot
TypeStr = L"Running System Reset";
Expand Down
3 changes: 3 additions & 0 deletions NEWS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
- Previously only properly erased when called on the main screen
- The erasure was however also lost on the main screen when `IconRowMove` and/or `IconRowTune` is active
- Now fixed for all screens but artefacts may result with some custom banners
- Improves `CleanNvram` Feature
* Now triggers NVRAM garbage collection on Macs when run
* This is an equivalent of manually setting `nvram ResetNVRam=1`
- Improves `ProtectNVRAM` Feature
* Adds `rEFIt Variant` to UEFI Loaders filtered for `ProtectNVRAM`
- Made up of `RefindPlus`, `rEFIt` and `rEFInd` files chain-loaded from named locations
Expand Down

0 comments on commit 120f622

Please sign in to comment.