]>
git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/PlatformDxe/Rtc.c
2 Adjust Default System Time.
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials are licensed and made available under
7 the terms and conditions of the BSD License that accompanies this distribution.
8 The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <PlatformDxe.h>
19 // Date and time initial values.
20 // They are used if the RTC values are invalid during driver initialization
22 #define RTC_INIT_SECOND 0
23 #define RTC_INIT_MINUTE 0
24 #define RTC_INIT_HOUR 0
26 CHAR16 mBiosReleaseDate
[20];
29 Convert a single character to number.
30 It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'
32 @param Char The input char which need to change to a hex number.
40 if ((Char
>= L
'0') && (Char
<= L
'9')) {
41 return (UINTN
) (Char
- L
'0');
44 if ((Char
>= L
'A') && (Char
<= L
'F')) {
45 return (UINTN
) (Char
- L
'A' + 0xA);
53 See if YEAR field of a variable of EFI_TIME type is correct.
55 @param Time The time to be checked.
57 @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.
58 @retval EFI_SUCCESS Time is a valid EFI_TIME variable.
68 YearBuilt
= (UINT16
)(CharToUint(mBiosReleaseDate
[8])*10 + CharToUint(mBiosReleaseDate
[9]) + 2000);
70 if ((Time
->Year
) < YearBuilt
) {
71 return EFI_INVALID_PARAMETER
;
78 ExitPmAuth Protocol notification event handler, which set initial system time to be
79 the time when BIOS was built.
81 @param[in] Event Event whose notification function is being invoked.
82 @param[in] Context Pointer to the notification function's context.
87 AdjustDefaultRtcTimeCallback (
94 CHAR16 BiosVersion
[60];
95 CHAR16 BiosReleaseTime
[20];
97 // Get BIOS built time from Bios-ID.
100 SetMem(BiosVersion
, sizeof(BiosVersion
), 0);
101 SetMem(mBiosReleaseDate
, sizeof(mBiosReleaseDate
), 0);
102 SetMem(BiosReleaseTime
, sizeof(BiosReleaseTime
), 0);
104 Status
= GetBiosVersionDateTime (BiosVersion
, mBiosReleaseDate
, BiosReleaseTime
);
105 ASSERT_EFI_ERROR(Status
);
106 if (EFI_ERROR (Status
)) {
111 // Get current RTC time.
113 Status
= gRT
->GetTime (&EfiTime
, NULL
);
116 // Validate RTC time fields
118 Status
= CheckRtcTimeFields (&EfiTime
);
120 if (EFI_ERROR (Status
)) {
122 // Date such as Dec 28th of 2015
125 // BiosReleaseDate[0] = '1';
126 // BiosReleaseDate[1] = '2';
129 // BiosReleaseDate[3] = '2';
130 // BiosReleaseDate[4] = '8';
135 // BiosReleaseDate[6] = '2';
136 // BiosReleaseDate[7] = '0';
137 // BiosReleaseDate[8] = '1'
138 // BiosReleaseDate[9] = '5';
140 EfiTime
.Second
= RTC_INIT_SECOND
;
141 EfiTime
.Minute
= RTC_INIT_MINUTE
;
142 EfiTime
.Hour
= RTC_INIT_HOUR
;
143 EfiTime
.Day
= (UINT8
)(CharToUint(mBiosReleaseDate
[3])*10 + CharToUint(mBiosReleaseDate
[4]));
144 EfiTime
.Month
= (UINT8
)(CharToUint(mBiosReleaseDate
[0])*10 + CharToUint(mBiosReleaseDate
[1]));
145 EfiTime
.Year
= (UINT16
)(CharToUint(mBiosReleaseDate
[8])*10 + CharToUint(mBiosReleaseDate
[9]) + 2000);
146 EfiTime
.Nanosecond
= 0;
147 EfiTime
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
148 EfiTime
.Daylight
= 1;
150 DEBUG ((EFI_D_INFO
, "Day:%d Month:%d Year:%d \n", (UINT32
)EfiTime
.Day
, (UINT32
)EfiTime
.Month
, (UINT32
)EfiTime
.Year
));
153 // Reset time value according to new RTC configuration
155 Status
= gRT
->SetTime (&EfiTime
);
156 ASSERT_EFI_ERROR(Status
);