| 980 | */ |
| 981 | |
| 982 | BOOLEAN |
| 983 | PrepareHibernation (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. |
no test coverage detected