From 07d8559c6bd8a8716e163a930a63f16e742aaa7a Mon Sep 17 00:00:00 2001 From: Ruiyu Ni Date: Thu, 23 Aug 2018 13:37:37 +0800 Subject: [PATCH] EmulatorPkg/Win: Add RTC support Now firmware can display the time correctly. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Reviewed-by: Hao A Wu Cc: Andrew Fish --- EmulatorPkg/Win/Host/WinThunk.c | 58 +++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/EmulatorPkg/Win/Host/WinThunk.c b/EmulatorPkg/Win/Host/WinThunk.c index ffe71aef9a..306fe75ecd 100644 --- a/EmulatorPkg/Win/Host/WinThunk.c +++ b/EmulatorPkg/Win/Host/WinThunk.c @@ -482,14 +482,68 @@ SecGetTime ( OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL ) { + SYSTEMTIME SystemTime; + TIME_ZONE_INFORMATION TimeZone; + + GetLocalTime (&SystemTime); + GetTimeZoneInformation (&TimeZone); + + Time->Year = (UINT16)SystemTime.wYear; + Time->Month = (UINT8)SystemTime.wMonth; + Time->Day = (UINT8)SystemTime.wDay; + Time->Hour = (UINT8)SystemTime.wHour; + Time->Minute = (UINT8)SystemTime.wMinute; + Time->Second = (UINT8)SystemTime.wSecond; + Time->Nanosecond = (UINT32)(SystemTime.wMilliseconds * 1000000); + Time->TimeZone = (INT16)TimeZone.Bias; + + if (Capabilities != NULL) { + Capabilities->Resolution = 1; + Capabilities->Accuracy = 50000000; + Capabilities->SetsToZero = FALSE; + } + + Time->Daylight = 0; + if (TimeZone.StandardDate.wMonth) { + Time->Daylight = (UINT8)TimeZone.StandardDate.wMonth; + } } EFI_STATUS SecSetTime ( IN EFI_TIME *Time -) + ) { - return EFI_SUCCESS; + TIME_ZONE_INFORMATION TimeZone; + SYSTEMTIME SystemTime; + BOOL Flag; + + // + // Set Daylight savings time information and Time Zone + // + GetTimeZoneInformation (&TimeZone); + TimeZone.StandardDate.wMonth = Time->Daylight; + TimeZone.Bias = Time->TimeZone; + Flag = SetTimeZoneInformation (&TimeZone); + if (!Flag) { + return EFI_DEVICE_ERROR; + } + + SystemTime.wYear = Time->Year; + SystemTime.wMonth = Time->Month; + SystemTime.wDay = Time->Day; + SystemTime.wHour = Time->Hour; + SystemTime.wMinute = Time->Minute; + SystemTime.wSecond = Time->Second; + SystemTime.wMilliseconds = (INT16)(Time->Nanosecond / 1000000); + + Flag = SetLocalTime (&SystemTime); + + if (!Flag) { + return EFI_DEVICE_ERROR; + } else { + return EFI_SUCCESS; + } } EMU_THUNK_PROTOCOL gEmuThunkProtocol = { -- 2.39.2