/** See if YEAR field of a variable of EFI_TIME type is correct. @param Time The time to be checked. @retval EFI_INVALID_PARAMETER Some fields of Time are not correct. @retval EFI_SUCCESS Time is a valid EFI_TIME variable. **/ EFI_STATUS CheckRtcTimeFields ( IN EFI_TIME *Time ) { UINT16 YearBuilt; YearBuilt = (UINT16)(CharToUint(mBiosReleaseDate[8])*10 + CharToUint(mBiosReleaseDate[9]) + 2000); if ((Time->Year) < YearBuilt) { return EFI_INVALID_PARAMETER; } return EFI_SUCCESS; }
EFIAPI BdsLibVariableToOption ( IN OUT LIST_ENTRY *BdsCommonOptionList, IN CHAR16 *VariableName ) { UINT32 Attribute; UINT16 FilePathSize; UINT8 *Variable; UINT8 *TempPtr; UINTN VariableSize; EFI_DEVICE_PATH_PROTOCOL *DevicePath; BDS_COMMON_OPTION *Option; VOID *LoadOptions; UINT32 LoadOptionsSize; CHAR16 *Description; UINT8 NumOff; // // Read the variable. We will never free this data. // Variable = BdsLibGetVariableAndSize ( VariableName, &gEfiGlobalVariableGuid, &VariableSize ); if (Variable == NULL) { return NULL; } // // Validate Boot#### variable data. // if (!ValidateOption(Variable, VariableSize)) { FreePool (Variable); return NULL; } // // Notes: careful defined the variable of Boot#### or // Driver####, consider use some macro to abstract the code // // // Get the option attribute // TempPtr = Variable; Attribute = *(UINT32 *) Variable; TempPtr += sizeof (UINT32); // // Get the option's device path size // FilePathSize = *(UINT16 *) TempPtr; TempPtr += sizeof (UINT16); // // Get the option's description string // Description = (CHAR16 *) TempPtr; // // Get the option's description string size // TempPtr += StrSize((CHAR16 *) TempPtr); // // Get the option's device path // DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr; TempPtr += FilePathSize; // // Get load opion data. // LoadOptions = TempPtr; LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable)); // // The Console variables may have multiple device paths, so make // an Entry for each one. // Option = AllocateZeroPool (sizeof (BDS_COMMON_OPTION)); if (Option == NULL) { FreePool (Variable); return NULL; } Option->Signature = BDS_LOAD_OPTION_SIGNATURE; Option->DevicePath = AllocateCopyPool (GetDevicePathSize (DevicePath), DevicePath); // ASSERT(Option->DevicePath != NULL); if (!Option->DevicePath) { FreePool (Option); return NULL; } // CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath)); Option->Attribute = Attribute; Option->Description = AllocateCopyPool (StrSize (Description), Description); // ASSERT(Option->Description != NULL); if (!Option->Description) { FreePool (Option); return NULL; } // CopyMem (Option->Description, Description, StrSize (Description)); Option->LoadOptions = AllocateCopyPool (LoadOptionsSize, LoadOptions); // ASSERT(Option->LoadOptions != NULL); if (!Option->LoadOptions) { FreePool (Option); return NULL; } // CopyMem (Option->LoadOptions, LoadOptions, LoadOptionsSize); Option->LoadOptionsSize = LoadOptionsSize; // // Get the value from VariableName Unicode string // since the ISO standard assumes ASCII equivalent abbreviations, we can be safe in converting this // Unicode stream to ASCII without any loss in meaning. // if (*VariableName == 'B') { NumOff = (UINT8) (sizeof (L"Boot") / sizeof (CHAR16) - 1); Option->BootCurrent = (UINT16) (CharToUint (VariableName[NumOff+0]) * 0x1000) + (UINT16) (CharToUint (VariableName[NumOff+1]) * 0x100) + (UINT16) (CharToUint (VariableName[NumOff+2]) * 0x10) + (UINT16) (CharToUint (VariableName[NumOff+3]) * 0x1); } InsertTailList (BdsCommonOptionList, &Option->Link); FreePool (Variable); return Option; }
/** ExitPmAuth Protocol notification event handler, which set initial system time to be the time when BIOS was built. @param[in] Event Event whose notification function is being invoked. @param[in] Context Pointer to the notification function's context. **/ VOID EFIAPI AdjustDefaultRtcTimeCallback ( IN EFI_EVENT Event, IN VOID *Context ) { EFI_STATUS Status; EFI_TIME EfiTime; CHAR16 BiosVersion[60]; CHAR16 BiosReleaseTime[20]; // // Get BIOS built time from Bios-ID. // SetMem(BiosVersion, sizeof(BiosVersion), 0); SetMem(mBiosReleaseDate, sizeof(mBiosReleaseDate), 0); SetMem(BiosReleaseTime, sizeof(BiosReleaseTime), 0); Status = GetBiosVersionDateTime (BiosVersion, mBiosReleaseDate, BiosReleaseTime); ASSERT_EFI_ERROR(Status); if (EFI_ERROR (Status)) { return; } // // Get current RTC time. // Status = gRT->GetTime (&EfiTime, NULL); // // Validate RTC time fields // Status = CheckRtcTimeFields (&EfiTime); if (EFI_ERROR (Status)) { // // Date such as Dec 28th of 2015 // // Month // BiosReleaseDate[0] = '1'; // BiosReleaseDate[1] = '2'; // // Day // BiosReleaseDate[3] = '2'; // BiosReleaseDate[4] = '8'; // // // Year // // BiosReleaseDate[6] = '2'; // BiosReleaseDate[7] = '0'; // BiosReleaseDate[8] = '1' // BiosReleaseDate[9] = '5'; EfiTime.Second = RTC_INIT_SECOND; EfiTime.Minute = RTC_INIT_MINUTE; EfiTime.Hour = RTC_INIT_HOUR; EfiTime.Day = (UINT8)(CharToUint(mBiosReleaseDate[3])*10 + CharToUint(mBiosReleaseDate[4])); EfiTime.Month = (UINT8)(CharToUint(mBiosReleaseDate[0])*10 + CharToUint(mBiosReleaseDate[1])); EfiTime.Year = (UINT16)(CharToUint(mBiosReleaseDate[8])*10 + CharToUint(mBiosReleaseDate[9]) + 2000); EfiTime.Nanosecond = 0; EfiTime.TimeZone = EFI_UNSPECIFIED_TIMEZONE; EfiTime.Daylight = 1; DEBUG ((EFI_D_INFO, "Day:%d Month:%d Year:%d \n", (UINT32)EfiTime.Day, (UINT32)EfiTime.Month, (UINT32)EfiTime.Year)); // // Reset time value according to new RTC configuration // Status = gRT->SetTime (&EfiTime); ASSERT_EFI_ERROR(Status); } return; }