MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / PrepareHibernation

Function PrepareHibernation

rEFIt_UEFI/Platform/Hibernate.cpp:982–1180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

980 */
981
982BOOLEAN
983PrepareHibernation (IN REFIT_VOLUME *Volume)
984{
985 EFI_STATUS Status;
986 UINT64 SleepImageOffset;
987 EFI_DEVICE_PATH_PROTOCOL *BootImageDevPath;
988 UINTN Size = 0;
989 VOID *Value = NULL;
990 AppleRTCHibernateVars RtcVars;
991 UINT8 *VarData = NULL;
992 REFIT_VOLUME *SleepImageVolume;
993 UINT32 Attributes;
994 BOOLEAN HasIORTCVariables = FALSE;
995 BOOLEAN HasHibernateInfo = FALSE;
996 BOOLEAN HasHibernateInfoInRTC = FALSE;
997
998 DBG("PrepareHibernation:\n");
999
1000 if (!GlobalConfig.StrictHibernate) {
1001 // Find sleep image offset
1002 SleepImageOffset = GetSleepImagePosition (Volume, &SleepImageVolume);
1003 DBG(" SleepImageOffset: %llx\n", SleepImageOffset);
1004 if (SleepImageOffset == 0 || SleepImageVolume == NULL) {
1005 DBG(" sleepimage offset not found\n");
1006 return FALSE;
1007 }
1008
1009 // Set boot-image var
1010 snwprintf(OffsetHexStr, sizeof(OffsetHexStr), "%llx", SleepImageOffset);
1011 BootImageDevPath = FileDevicePath(SleepImageVolume->WholeDiskDeviceHandle, OffsetHexStr);
1012 // DBG(" boot-image device path:\n");
1013 Size = GetDevicePathSize(BootImageDevPath);
1014 VarData = (UINT8*)BootImageDevPath;
1015 PrintBytes(VarData, Size);
1016 DBG("boot-image before: %ls\n", FileDevicePathToXStringW(BootImageDevPath).wc_str());
1017 // VarData[6] = 8;
1018
1019 // VarData[24] = 0xFF;
1020 // VarData[25] = 0xFF;
1021 // DBG("boot-image corrected: %ls\n", FileDevicePathToStr(BootImageDevPath));
1022
1023 Status = gRT->SetVariable(L"boot-image", &gEfiAppleBootGuid,
1024 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
1025 Size , BootImageDevPath);
1026 if (EFI_ERROR(Status)) {
1027 DBG(" can not write boot-image -> %s\n", efiStrError(Status));
1028 return FALSE;
1029 }
1030 }
1031
1032 // now we should delete boot0082 to do hibernate only once
1033 Status = DeleteBootOption(0x82);
1034 if (EFI_ERROR(Status)) {
1035 DBG("Options 0082 was not deleted: %s\n", efiStrError(Status));
1036 }
1037
1038 //
1039 // If legacy boot-switch-vars exists (NVRAM working), then use it.

Callers 1

StartLoaderMethod · 0.85

Calls 14

GetSleepImagePositionFunction · 0.85
FileDevicePathToXStringWFunction · 0.85
DeleteBootOptionFunction · 0.85
GetVariable2Function · 0.85
SimpleRtcReadFunction · 0.85
SimpleRtcWriteFunction · 0.85
SetMemFunction · 0.85
PrintBytesFunction · 0.70
FileDevicePathFunction · 0.50
GetDevicePathSizeFunction · 0.50
efiStrErrorFunction · 0.50
ZeroMemFunction · 0.50

Tested by

no test coverage detected