diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
index bf221768c8..acc70a67b7 100644
--- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
+++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
@@ -1,7 +1,7 @@
/** @file
RTC Architectural Protocol GUID as defined in DxeCis 0.96.
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -14,6 +14,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "PcRtc.h"
+//
+// Days of month.
+//
+UINTN mDayOfMonth[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+//
+// The name of NV variable to store the timezone and daylight saving information.
+//
+CHAR16 mTimeZoneVariableName[] = L"RTC";
+
/**
Compare the Hour, Minute and Second of the From time and the To time.
@@ -182,11 +192,11 @@ PcRtcInit (
//
DataSize = sizeof (UINT32);
Status = EfiGetVariable (
- L"RTC",
+ mTimeZoneVariableName,
&gEfiCallerIdGuid,
NULL,
&DataSize,
- (VOID *) &TimerVar
+ &TimerVar
);
if (!EFI_ERROR (Status)) {
Time.TimeZone = (INT16) TimerVar;
@@ -477,15 +487,29 @@ PcRtcSetTime (
//
// Write timezone and daylight to RTC variable
//
- TimerVar = Time->Daylight;
- TimerVar = (UINT32) ((TimerVar << 16) | (UINT16)(Time->TimeZone));
- Status = EfiSetVariable (
- L"RTC",
- &gEfiCallerIdGuid,
- EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
- sizeof (TimerVar),
- &TimerVar
- );
+ if (Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE) {
+ Status = EfiSetVariable (
+ mTimeZoneVariableName,
+ &gEfiCallerIdGuid,
+ 0,
+ 0,
+ NULL
+ );
+ if (Status == EFI_NOT_FOUND) {
+ Status = EFI_SUCCESS;
+ }
+ } else {
+ TimerVar = Time->Daylight;
+ TimerVar = (UINT32) ((TimerVar << 16) | (UINT16)(Time->TimeZone));
+ Status = EfiSetVariable (
+ mTimeZoneVariableName,
+ &gEfiCallerIdGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ sizeof (TimerVar),
+ &TimerVar
+ );
+ }
+
if (EFI_ERROR (Status)) {
if (!EfiAtRuntime ()) {
EfiReleaseLock (&Global->RtcLock);
@@ -987,28 +1011,13 @@ DayValid (
IN EFI_TIME *Time
)
{
- INTN DayOfMonth[12];
-
- DayOfMonth[0] = 31;
- DayOfMonth[1] = 29;
- DayOfMonth[2] = 31;
- DayOfMonth[3] = 30;
- DayOfMonth[4] = 31;
- DayOfMonth[5] = 30;
- DayOfMonth[6] = 31;
- DayOfMonth[7] = 31;
- DayOfMonth[8] = 30;
- DayOfMonth[9] = 31;
- DayOfMonth[10] = 30;
- DayOfMonth[11] = 31;
-
//
// The validity of Time->Month field should be checked before
//
ASSERT (Time->Month >=1);
ASSERT (Time->Month <=12);
if (Time->Day < 1 ||
- Time->Day > DayOfMonth[Time->Month - 1] ||
+ Time->Day > mDayOfMonth[Time->Month - 1] ||
(Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))
) {
return FALSE;
@@ -1144,22 +1153,8 @@ IsWithinOneDay (
IN EFI_TIME *To
)
{
- UINT8 DayOfMonth[12];
BOOLEAN Adjacent;
- DayOfMonth[0] = 31;
- DayOfMonth[1] = 29;
- DayOfMonth[2] = 31;
- DayOfMonth[3] = 30;
- DayOfMonth[4] = 31;
- DayOfMonth[5] = 30;
- DayOfMonth[6] = 31;
- DayOfMonth[7] = 31;
- DayOfMonth[8] = 30;
- DayOfMonth[9] = 31;
- DayOfMonth[10] = 30;
- DayOfMonth[11] = 31;
-
Adjacent = FALSE;
//
@@ -1186,7 +1181,7 @@ IsWithinOneDay (
Adjacent = TRUE;
}
}
- } else if (From->Day == DayOfMonth[From->Month - 1]) {
+ } else if (From->Day == mDayOfMonth[From->Month - 1]) {
if ((CompareHMS(From, To) >= 0)) {
Adjacent = TRUE;
}