Re: [edk2] [PATCH 1/1] EmbeddedPkg/Library: Add VirtualRealTimeClockLib
On Fri, 15 Feb 2019 at 15:57, Pete Batard wrote: > > On 2019-02-15 14:39, Ard Biesheuvel wrote: > > On Fri, 15 Feb 2019 at 11:07, Ard Biesheuvel > > wrote: > >> > >> On Tue, 12 Feb 2019 at 19:14, Leif Lindholm > >> wrote: > >>> > >>> On Mon, Feb 04, 2019 at 12:47:36PM +, Pete Batard wrote: > This is designed to be used on platforms where a a real RTC is not > available and relies on an RtcEpochSeconds variable having been set or, > if that is not the case, falls back to using the epoch embedded at > compilation time. > > Note that, in order to keep things simple for the setting of the > compilation time variable, only GCC environments with UNIX-like shells > and where a 'date' command is available are meant to be supported for > now. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Pete Batard > >>> > >>> On the whole, this looks good to me. > >>> One addition we'll need, so that we can build this library standalone > >>> is an entry in EmbeddedPkg.dsc: > >>> > >>> diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc > >>> index 4d9e6399d5..dc5040e611 100644 > >>> --- a/EmbeddedPkg/EmbeddedPkg.dsc > >>> +++ b/EmbeddedPkg/EmbeddedPkg.dsc > >>> @@ -218,6 +218,7 @@ [Components.common] > >>> EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf > >>> EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf > >>> > >>> EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf > >>> + EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf > >>> EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf > >>> EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf > >>> > >>> I don't have any strong opinions on either of Phil's suggestions, but > >>> if you could give some feedback on those and fold the above in, this > >>> could go in. > >>> > >> > >> WIth this addition > >> > >> Reviewed-by: Ard Biesheuvel > >> > >> Pushed as 1b261a705f94..64a17fadcb79 > > > > OK, there is a problem with this code: > > > > +EFI_STATUS > > +EFIAPI > > +LibGetTime ( > > + OUT EFI_TIME *Time, > > + OUT EFI_TIME_CAPABILITIES *Capabilities > > + ) > > +{ > > + EFI_STATUS Status; > > + UINT32 EpochSeconds; > > > > EpochSeconds is declared here, and updated depending on time zone and > > DST settings. However, the resulting value is never used anywhere. > > You're right. > > Looks like I forgot to merge all the use of EpochSeconds into > ElapsedSeconds, from the code I copy/pasted. > > I'm very sorry about this, as it's something I should have picked up > before sending this patch for review. > > It is not clear to me what the correct fix is, so Pete, could you > > please look into this? > > I'll send a fix for this as soon as I have a chance. Thanks for pointing > the mistake. > Any progress here? ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 1/1] EmbeddedPkg/Library: Add VirtualRealTimeClockLib
On 2019-02-15 14:39, Ard Biesheuvel wrote: On Fri, 15 Feb 2019 at 11:07, Ard Biesheuvel wrote: On Tue, 12 Feb 2019 at 19:14, Leif Lindholm wrote: On Mon, Feb 04, 2019 at 12:47:36PM +, Pete Batard wrote: This is designed to be used on platforms where a a real RTC is not available and relies on an RtcEpochSeconds variable having been set or, if that is not the case, falls back to using the epoch embedded at compilation time. Note that, in order to keep things simple for the setting of the compilation time variable, only GCC environments with UNIX-like shells and where a 'date' command is available are meant to be supported for now. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Pete Batard On the whole, this looks good to me. One addition we'll need, so that we can build this library standalone is an entry in EmbeddedPkg.dsc: diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc index 4d9e6399d5..dc5040e611 100644 --- a/EmbeddedPkg/EmbeddedPkg.dsc +++ b/EmbeddedPkg/EmbeddedPkg.dsc @@ -218,6 +218,7 @@ [Components.common] EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf + EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf I don't have any strong opinions on either of Phil's suggestions, but if you could give some feedback on those and fold the above in, this could go in. WIth this addition Reviewed-by: Ard Biesheuvel Pushed as 1b261a705f94..64a17fadcb79 OK, there is a problem with this code: +EFI_STATUS +EFIAPI +LibGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities + ) +{ + EFI_STATUS Status; + UINT32 EpochSeconds; EpochSeconds is declared here, and updated depending on time zone and DST settings. However, the resulting value is never used anywhere. You're right. Looks like I forgot to merge all the use of EpochSeconds into ElapsedSeconds, from the code I copy/pasted. I'm very sorry about this, as it's something I should have picked up before sending this patch for review. It is not clear to me what the correct fix is, so Pete, could you please look into this? I'll send a fix for this as soon as I have a chance. Thanks for pointing the mistake. Regards, /Pete ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 1/1] EmbeddedPkg/Library: Add VirtualRealTimeClockLib
On Fri, 15 Feb 2019 at 15:57, Pete Batard wrote: > > On 2019-02-15 14:39, Ard Biesheuvel wrote: > > On Fri, 15 Feb 2019 at 11:07, Ard Biesheuvel > > wrote: > >> > >> On Tue, 12 Feb 2019 at 19:14, Leif Lindholm > >> wrote: > >>> > >>> On Mon, Feb 04, 2019 at 12:47:36PM +, Pete Batard wrote: > This is designed to be used on platforms where a a real RTC is not > available and relies on an RtcEpochSeconds variable having been set or, > if that is not the case, falls back to using the epoch embedded at > compilation time. > > Note that, in order to keep things simple for the setting of the > compilation time variable, only GCC environments with UNIX-like shells > and where a 'date' command is available are meant to be supported for > now. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Pete Batard > >>> > >>> On the whole, this looks good to me. > >>> One addition we'll need, so that we can build this library standalone > >>> is an entry in EmbeddedPkg.dsc: > >>> > >>> diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc > >>> index 4d9e6399d5..dc5040e611 100644 > >>> --- a/EmbeddedPkg/EmbeddedPkg.dsc > >>> +++ b/EmbeddedPkg/EmbeddedPkg.dsc > >>> @@ -218,6 +218,7 @@ [Components.common] > >>> EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf > >>> EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf > >>> > >>> EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf > >>> + EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf > >>> EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf > >>> EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf > >>> > >>> I don't have any strong opinions on either of Phil's suggestions, but > >>> if you could give some feedback on those and fold the above in, this > >>> could go in. > >>> > >> > >> WIth this addition > >> > >> Reviewed-by: Ard Biesheuvel > >> > >> Pushed as 1b261a705f94..64a17fadcb79 > > > > OK, there is a problem with this code: > > > > +EFI_STATUS > > +EFIAPI > > +LibGetTime ( > > + OUT EFI_TIME *Time, > > + OUT EFI_TIME_CAPABILITIES *Capabilities > > + ) > > +{ > > + EFI_STATUS Status; > > + UINT32 EpochSeconds; > > > > EpochSeconds is declared here, and updated depending on time zone and > > DST settings. However, the resulting value is never used anywhere. > > You're right. > > Looks like I forgot to merge all the use of EpochSeconds into > ElapsedSeconds, from the code I copy/pasted. > > I'm very sorry about this, as it's something I should have picked up > before sending this patch for review. No need to worry about it, as long as you get it fixed :-) > > It is not clear to me what the correct fix is, so Pete, could you > > please look into this? > > I'll send a fix for this as soon as I have a chance. Thanks for pointing > the mistake. > ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 1/1] EmbeddedPkg/Library: Add VirtualRealTimeClockLib
On Fri, 15 Feb 2019 at 11:07, Ard Biesheuvel wrote: > > On Tue, 12 Feb 2019 at 19:14, Leif Lindholm wrote: > > > > On Mon, Feb 04, 2019 at 12:47:36PM +, Pete Batard wrote: > > > This is designed to be used on platforms where a a real RTC is not > > > available and relies on an RtcEpochSeconds variable having been set or, > > > if that is not the case, falls back to using the epoch embedded at > > > compilation time. > > > > > > Note that, in order to keep things simple for the setting of the > > > compilation time variable, only GCC environments with UNIX-like shells > > > and where a 'date' command is available are meant to be supported for > > > now. > > > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > > Signed-off-by: Pete Batard > > > > On the whole, this looks good to me. > > One addition we'll need, so that we can build this library standalone > > is an entry in EmbeddedPkg.dsc: > > > > diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc > > index 4d9e6399d5..dc5040e611 100644 > > --- a/EmbeddedPkg/EmbeddedPkg.dsc > > +++ b/EmbeddedPkg/EmbeddedPkg.dsc > > @@ -218,6 +218,7 @@ [Components.common] > >EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf > >EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf > > > > EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf > > + EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf > >EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf > >EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf > > > > I don't have any strong opinions on either of Phil's suggestions, but > > if you could give some feedback on those and fold the above in, this > > could go in. > > > > WIth this addition > > Reviewed-by: Ard Biesheuvel > > Pushed as 1b261a705f94..64a17fadcb79 OK, there is a problem with this code: +EFI_STATUS +EFIAPI +LibGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities + ) +{ + EFI_STATUS Status; + UINT32 EpochSeconds; EpochSeconds is declared here, and updated depending on time zone and DST settings. However, the resulting value is never used anywhere. It is not clear to me what the correct fix is, so Pete, could you please look into this? ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 1/1] EmbeddedPkg/Library: Add VirtualRealTimeClockLib
On Tue, 12 Feb 2019 at 19:14, Leif Lindholm wrote: > > On Mon, Feb 04, 2019 at 12:47:36PM +, Pete Batard wrote: > > This is designed to be used on platforms where a a real RTC is not > > available and relies on an RtcEpochSeconds variable having been set or, > > if that is not the case, falls back to using the epoch embedded at > > compilation time. > > > > Note that, in order to keep things simple for the setting of the > > compilation time variable, only GCC environments with UNIX-like shells > > and where a 'date' command is available are meant to be supported for > > now. > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Pete Batard > > On the whole, this looks good to me. > One addition we'll need, so that we can build this library standalone > is an entry in EmbeddedPkg.dsc: > > diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc > index 4d9e6399d5..dc5040e611 100644 > --- a/EmbeddedPkg/EmbeddedPkg.dsc > +++ b/EmbeddedPkg/EmbeddedPkg.dsc > @@ -218,6 +218,7 @@ [Components.common] >EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf >EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf > > EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf > + EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf >EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf >EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf > > I don't have any strong opinions on either of Phil's suggestions, but > if you could give some feedback on those and fold the above in, this > could go in. > WIth this addition Reviewed-by: Ard Biesheuvel Pushed as 1b261a705f94..64a17fadcb79 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 1/1] EmbeddedPkg/Library: Add VirtualRealTimeClockLib
On Fri, Feb 15, 2019 at 01:12:11AM +0100, Pete Batard wrote: > Hi Leif, > > On 2019-02-12 19:14, Leif Lindholm wrote: > > On Mon, Feb 04, 2019 at 12:47:36PM +, Pete Batard wrote: > > > This is designed to be used on platforms where a a real RTC is not > > > available and relies on an RtcEpochSeconds variable having been set or, > > > if that is not the case, falls back to using the epoch embedded at > > > compilation time. > > > > > > Note that, in order to keep things simple for the setting of the > > > compilation time variable, only GCC environments with UNIX-like shells > > > and where a 'date' command is available are meant to be supported for > > > now. > > > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > > Signed-off-by: Pete Batard > > > > On the whole, this looks good to me. > > Thanks for the review. > > > One addition we'll need, so that we can build this library standalone > > is an entry in EmbeddedPkg.dsc: > > > > diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc > > index 4d9e6399d5..dc5040e611 100644 > > --- a/EmbeddedPkg/EmbeddedPkg.dsc > > +++ b/EmbeddedPkg/EmbeddedPkg.dsc > > @@ -218,6 +218,7 @@ [Components.common] > > EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf > > EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf > > > > EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf > > + EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf > > EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf > > EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf > > Well, I actually tried just that but got a build failure when trying to > compile it (sorry can't remember exactly what was the issue and I don't have > access to an edk2 test env at the moment) and I saw that some libraries in > the same location, such as TimeLib which I believe is used by some > edk2-platforms, are also not referenced at all in the dsc. > > So my take was that not all of the libs are required to be included in the > dsc, especially if they are meant to be referenced directly. Oh, we do want all modules in the .dsc - so that we can easily compile test everything. (And sure, we may have missed some in the past, but we've gotten better at remembering when we add new ones :) With the above line added, I built VirtualRealTimeClockLib succesfully for AARCH64, ARM, IA32 and X64. > If you feel this is important, I can look into adding the .dsc ref again, > though provided I can figure out my issue (which may very well boil down to > me not being too familiar with compiling a standalone EmbeddedPkg) it might > be a week or two before I can send an updated patch. All that should be needed is: build -p EmbeddedPkg/EmbeddedPkg.dsc -m EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf Regards, Leif > Regards, > > /Pete > > > I don't have any strong opinions on either of Phil's suggestions, but > > if you could give some feedback on those and fold the above in, this > > could go in. > > > > Regards, > > > > Leif > > > > > --- > > > EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c > > > | 400 > > > EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf > > > | 43 +++ > > > 2 files changed, 443 insertions(+) > > > > > > diff --git > > > a/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c > > > b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c > > > new file mode 100644 > > > index ..4c354730d02b > > > --- /dev/null > > > +++ > > > b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c > > > @@ -0,0 +1,400 @@ > > > +/** @file > > > + * > > > + * Implement virtual EFI RealTimeClock runtime services. > > > + * > > > + * Coypright (c) 2019, Pete Batard > > > + * Copyright (c) 2018, Andrei Warkentin > > > + * Copyright (c) 2011-2014, ARM Ltd. All rights reserved. > > > + * Copyright (c) 2008-2010, Apple Inc. All rights reserved. > > > + * Copyright (c) Microsoft 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 > > > + * http://opensource.org/licenses/bsd-license.php > > > + * > > > + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > > > + * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR > > > IMPLIED. > > > + * > > > + * Based on > > > ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf > > > + * > > > + **/ > > > + > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > + > > > +STATIC
Re: [edk2] [PATCH 1/1] EmbeddedPkg/Library: Add VirtualRealTimeClockLib
Hi Leif, On 2019-02-12 19:14, Leif Lindholm wrote: On Mon, Feb 04, 2019 at 12:47:36PM +, Pete Batard wrote: This is designed to be used on platforms where a a real RTC is not available and relies on an RtcEpochSeconds variable having been set or, if that is not the case, falls back to using the epoch embedded at compilation time. Note that, in order to keep things simple for the setting of the compilation time variable, only GCC environments with UNIX-like shells and where a 'date' command is available are meant to be supported for now. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Pete Batard On the whole, this looks good to me. Thanks for the review. One addition we'll need, so that we can build this library standalone is an entry in EmbeddedPkg.dsc: diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc index 4d9e6399d5..dc5040e611 100644 --- a/EmbeddedPkg/EmbeddedPkg.dsc +++ b/EmbeddedPkg/EmbeddedPkg.dsc @@ -218,6 +218,7 @@ [Components.common] EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf + EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf Well, I actually tried just that but got a build failure when trying to compile it (sorry can't remember exactly what was the issue and I don't have access to an edk2 test env at the moment) and I saw that some libraries in the same location, such as TimeLib which I believe is used by some edk2-platforms, are also not referenced at all in the dsc. So my take was that not all of the libs are required to be included in the dsc, especially if they are meant to be referenced directly. If you feel this is important, I can look into adding the .dsc ref again, though provided I can figure out my issue (which may very well boil down to me not being too familiar with compiling a standalone EmbeddedPkg) it might be a week or two before I can send an updated patch. Regards, /Pete I don't have any strong opinions on either of Phil's suggestions, but if you could give some feedback on those and fold the above in, this could go in. Regards, Leif --- EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c | 400 EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf | 43 +++ 2 files changed, 443 insertions(+) diff --git a/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c new file mode 100644 index ..4c354730d02b --- /dev/null +++ b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c @@ -0,0 +1,400 @@ +/** @file + * + * Implement virtual EFI RealTimeClock runtime services. + * + * Coypright (c) 2019, Pete Batard + * Copyright (c) 2018, Andrei Warkentin + * Copyright (c) 2011-2014, ARM Ltd. All rights reserved. + * Copyright (c) 2008-2010, Apple Inc. All rights reserved. + * Copyright (c) Microsoft 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 + * http://opensource.org/licenses/bsd-license.php + * + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + * + * Based on ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf + * + **/ + +#include +#include +#include +#include +#include +#include +#include +#include + +STATIC CONST CHAR16 mEpochVariableName[] = L"RtcEpochSeconds"; +STATIC CONST CHAR16 mTimeZoneVariableName[] = L"RtcTimeZone"; +STATIC CONST CHAR16 mDaylightVariableName[] = L"RtcDaylight"; + +/** + Returns the current time and date information, and the time-keeping capabilities + of the virtual RTC. + + @param Time A pointer to storage to receive a snapshot of the current time. + @param Capabilities An optional pointer to a buffer to receive the real time clock + device's capabilities. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error. + +**/ +EFI_STATUS +EFIAPI +LibGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities + ) +{ + EFI_STATUS Status; + UINT32 EpochSeconds; + INT16 TimeZone; + UINT8 Daylight; + UINT64 Freq; + UINT64
Re: [edk2] [PATCH 1/1] EmbeddedPkg/Library: Add VirtualRealTimeClockLib
Hi Philippe, Thanks fort reviewing this patch, and apologies for the late reply. On 2019-02-05 20:57, Philippe Mathieu-Daudé wrote: Hi Pete, On 2/4/19 1:47 PM, Pete Batard wrote: This is designed to be used on platforms where a a real RTC is not available and relies on an RtcEpochSeconds variable having been set or, if that is not the case, falls back to using the epoch embedded at compilation time. Note that, in order to keep things simple for the setting of the compilation time variable, only GCC environments with UNIX-like shells and where a 'date' command is available are meant to be supported for now. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Pete Batard --- EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c | 400 EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf | 43 +++ 2 files changed, 443 insertions(+) diff --git a/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c new file mode 100644 index ..4c354730d02b --- /dev/null +++ b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c @@ -0,0 +1,400 @@ +/** @file + * + * Implement virtual EFI RealTimeClock runtime services. + * + * Coypright (c) 2019, Pete Batard + * Copyright (c) 2018, Andrei Warkentin + * Copyright (c) 2011-2014, ARM Ltd. All rights reserved. + * Copyright (c) 2008-2010, Apple Inc. All rights reserved. + * Copyright (c) Microsoft 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 + * http://opensource.org/licenses/bsd-license.php + * + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + * + * Based on ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf + * + **/ + +#include +#include +#include +#include +#include +#include +#include +#include + +STATIC CONST CHAR16 mEpochVariableName[] = L"RtcEpochSeconds"; +STATIC CONST CHAR16 mTimeZoneVariableName[] = L"RtcTimeZone"; +STATIC CONST CHAR16 mDaylightVariableName[] = L"RtcDaylight"; + +/** + Returns the current time and date information, and the time-keeping capabilities + of the virtual RTC. + + @param Time A pointer to storage to receive a snapshot of the current time. + @param Capabilities An optional pointer to a buffer to receive the real time clock + device's capabilities. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error. + +**/ +EFI_STATUS +EFIAPI +LibGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities + ) +{ + EFI_STATUS Status; + UINT32 EpochSeconds; + INT16 TimeZone; + UINT8 Daylight; + UINT64 Freq; + UINT64 Counter; + UINT64 Remainder; + UINTN ElapsedSeconds; + UINTN Size; + + if (Time == NULL) { +return EFI_INVALID_PARAMETER; + } + + // Get the counter frequency + Freq = GetPerformanceCounterProperties (NULL, NULL); + if (Freq == 0) { +return EFI_DEVICE_ERROR; + } + + // Get the epoch time from non-volatile storage + Size = sizeof (UINTN); + ElapsedSeconds = 0; + Status = EfiGetVariable ( + (CHAR16 *)mEpochVariableName, + , + NULL, + , + (VOID *) + ); + // Fall back to compilation-time epoch if not set + if (EFI_ERROR (Status)) { +ASSERT(Status != EFI_INVALID_PARAMETER); +ASSERT(Status != EFI_BUFFER_TOO_SMALL); +// +// The following is intended to produce a compilation error on build +// environments where BUILD_EPOCH can not be set from inline shell. +// If you are attempting to use this library on such an environment, please +// contact the edk2 mailing list, so we can try to add support for it. +// What about: #ifndef BUILD_EPOCH #define BUILD_EPOCH 1549396000 /* As of this commit */ #endif Well, the plan is to see what we can actually do for platforms that can't define BUILD_EPOCH to the actual compilation time through shell invocation. Rather than assume that we won't be able to do anything for those, and therefore default to an epoch that would have a very large offset even when the user went the trouble of recompiling the firmware, I'd rather we get a better idea of the environments this might apply to, and see if there's anything that could be achieved there. Of course, if there are other people here that support your
Re: [edk2] [PATCH 1/1] EmbeddedPkg/Library: Add VirtualRealTimeClockLib
On Mon, Feb 04, 2019 at 12:47:36PM +, Pete Batard wrote: > This is designed to be used on platforms where a a real RTC is not > available and relies on an RtcEpochSeconds variable having been set or, > if that is not the case, falls back to using the epoch embedded at > compilation time. > > Note that, in order to keep things simple for the setting of the > compilation time variable, only GCC environments with UNIX-like shells > and where a 'date' command is available are meant to be supported for > now. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Pete Batard On the whole, this looks good to me. One addition we'll need, so that we can build this library standalone is an entry in EmbeddedPkg.dsc: diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc index 4d9e6399d5..dc5040e611 100644 --- a/EmbeddedPkg/EmbeddedPkg.dsc +++ b/EmbeddedPkg/EmbeddedPkg.dsc @@ -218,6 +218,7 @@ [Components.common] EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf + EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf I don't have any strong opinions on either of Phil's suggestions, but if you could give some feedback on those and fold the above in, this could go in. Regards, Leif > --- > EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c | > 400 > EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf | > 43 +++ > 2 files changed, 443 insertions(+) > > diff --git > a/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c > b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c > new file mode 100644 > index ..4c354730d02b > --- /dev/null > +++ b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c > @@ -0,0 +1,400 @@ > +/** @file > + * > + * Implement virtual EFI RealTimeClock runtime services. > + * > + * Coypright (c) 2019, Pete Batard > + * Copyright (c) 2018, Andrei Warkentin > + * Copyright (c) 2011-2014, ARM Ltd. All rights reserved. > + * Copyright (c) 2008-2010, Apple Inc. All rights reserved. > + * Copyright (c) Microsoft 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 > + * http://opensource.org/licenses/bsd-license.php > + * > + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR > IMPLIED. > + * > + * Based on > ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf > + * > + **/ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +STATIC CONST CHAR16 mEpochVariableName[] = L"RtcEpochSeconds"; > +STATIC CONST CHAR16 mTimeZoneVariableName[] = L"RtcTimeZone"; > +STATIC CONST CHAR16 mDaylightVariableName[] = L"RtcDaylight"; > + > +/** > + Returns the current time and date information, and the time-keeping > capabilities > + of the virtual RTC. > + > + @param Time A pointer to storage to receive a snapshot > of the current time. > + @param Capabilities An optional pointer to a buffer to receive > the real time clock > + device's capabilities. > + > + @retval EFI_SUCCESS The operation completed successfully. > + @retval EFI_INVALID_PARAMETER Time is NULL. > + @retval EFI_DEVICE_ERROR The time could not be retrieved due to > hardware error. > + > +**/ > +EFI_STATUS > +EFIAPI > +LibGetTime ( > + OUT EFI_TIME *Time, > + OUT EFI_TIME_CAPABILITIES *Capabilities > + ) > +{ > + EFI_STATUS Status; > + UINT32 EpochSeconds; > + INT16 TimeZone; > + UINT8 Daylight; > + UINT64 Freq; > + UINT64 Counter; > + UINT64 Remainder; > + UINTN ElapsedSeconds; > + UINTN Size; > + > + if (Time == NULL) { > +return EFI_INVALID_PARAMETER; > + } > + > + // Get the counter frequency > + Freq = GetPerformanceCounterProperties (NULL, NULL); > + if (Freq == 0) { > +return EFI_DEVICE_ERROR; > + } > + > + // Get the epoch time from non-volatile storage > + Size = sizeof (UINTN); > + ElapsedSeconds = 0; > + Status = EfiGetVariable ( > + (CHAR16 *)mEpochVariableName, > + , > + NULL, > + , > + (VOID *) > + ); > + // Fall back to compilation-time epoch if not set > + if (EFI_ERROR (Status))
Re: [edk2] [PATCH 1/1] EmbeddedPkg/Library: Add VirtualRealTimeClockLib
Hi Pete, On 2/4/19 1:47 PM, Pete Batard wrote: > This is designed to be used on platforms where a a real RTC is not > available and relies on an RtcEpochSeconds variable having been set or, > if that is not the case, falls back to using the epoch embedded at > compilation time. > > Note that, in order to keep things simple for the setting of the > compilation time variable, only GCC environments with UNIX-like shells > and where a 'date' command is available are meant to be supported for > now. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Pete Batard > --- > EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c | > 400 > EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf | > 43 +++ > 2 files changed, 443 insertions(+) > > diff --git > a/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c > b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c > new file mode 100644 > index ..4c354730d02b > --- /dev/null > +++ b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c > @@ -0,0 +1,400 @@ > +/** @file > + * > + * Implement virtual EFI RealTimeClock runtime services. > + * > + * Coypright (c) 2019, Pete Batard > + * Copyright (c) 2018, Andrei Warkentin > + * Copyright (c) 2011-2014, ARM Ltd. All rights reserved. > + * Copyright (c) 2008-2010, Apple Inc. All rights reserved. > + * Copyright (c) Microsoft 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 > + * http://opensource.org/licenses/bsd-license.php > + * > + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, > + * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR > IMPLIED. > + * > + * Based on > ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf > + * > + **/ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +STATIC CONST CHAR16 mEpochVariableName[] = L"RtcEpochSeconds"; > +STATIC CONST CHAR16 mTimeZoneVariableName[] = L"RtcTimeZone"; > +STATIC CONST CHAR16 mDaylightVariableName[] = L"RtcDaylight"; > + > +/** > + Returns the current time and date information, and the time-keeping > capabilities > + of the virtual RTC. > + > + @param Time A pointer to storage to receive a snapshot > of the current time. > + @param Capabilities An optional pointer to a buffer to receive > the real time clock > + device's capabilities. > + > + @retval EFI_SUCCESS The operation completed successfully. > + @retval EFI_INVALID_PARAMETER Time is NULL. > + @retval EFI_DEVICE_ERROR The time could not be retrieved due to > hardware error. > + > +**/ > +EFI_STATUS > +EFIAPI > +LibGetTime ( > + OUT EFI_TIME *Time, > + OUT EFI_TIME_CAPABILITIES *Capabilities > + ) > +{ > + EFI_STATUS Status; > + UINT32 EpochSeconds; > + INT16 TimeZone; > + UINT8 Daylight; > + UINT64 Freq; > + UINT64 Counter; > + UINT64 Remainder; > + UINTN ElapsedSeconds; > + UINTN Size; > + > + if (Time == NULL) { > +return EFI_INVALID_PARAMETER; > + } > + > + // Get the counter frequency > + Freq = GetPerformanceCounterProperties (NULL, NULL); > + if (Freq == 0) { > +return EFI_DEVICE_ERROR; > + } > + > + // Get the epoch time from non-volatile storage > + Size = sizeof (UINTN); > + ElapsedSeconds = 0; > + Status = EfiGetVariable ( > + (CHAR16 *)mEpochVariableName, > + , > + NULL, > + , > + (VOID *) > + ); > + // Fall back to compilation-time epoch if not set > + if (EFI_ERROR (Status)) { > +ASSERT(Status != EFI_INVALID_PARAMETER); > +ASSERT(Status != EFI_BUFFER_TOO_SMALL); > +// > +// The following is intended to produce a compilation error on build > +// environments where BUILD_EPOCH can not be set from inline shell. > +// If you are attempting to use this library on such an environment, > please > +// contact the edk2 mailing list, so we can try to add support for it. > +// What about: #ifndef BUILD_EPOCH #define BUILD_EPOCH 1549396000 /* As of this commit */ #endif > +ElapsedSeconds = BUILD_EPOCH; > +DEBUG (( > + DEBUG_INFO, > + "LibGetTime: %s non volatile variable was not found - Using > compilation time epoch.\n", > + mEpochVariableName > + )); > + } > + Counter = GetPerformanceCounter (); > + ElapsedSeconds += DivU64x64Remainder (Counter, Freq, ); > + > + // Get the current time zone information from non-volatile storage > + Size = sizeof (TimeZone); > +
[edk2] [PATCH 1/1] EmbeddedPkg/Library: Add VirtualRealTimeClockLib
This is designed to be used on platforms where a a real RTC is not available and relies on an RtcEpochSeconds variable having been set or, if that is not the case, falls back to using the epoch embedded at compilation time. Note that, in order to keep things simple for the setting of the compilation time variable, only GCC environments with UNIX-like shells and where a 'date' command is available are meant to be supported for now. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Pete Batard --- EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c | 400 EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.inf | 43 +++ 2 files changed, 443 insertions(+) diff --git a/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c new file mode 100644 index ..4c354730d02b --- /dev/null +++ b/EmbeddedPkg/Library/VirtualRealTimeClockLib/VirtualRealTimeClockLib.c @@ -0,0 +1,400 @@ +/** @file + * + * Implement virtual EFI RealTimeClock runtime services. + * + * Coypright (c) 2019, Pete Batard + * Copyright (c) 2018, Andrei Warkentin + * Copyright (c) 2011-2014, ARM Ltd. All rights reserved. + * Copyright (c) 2008-2010, Apple Inc. All rights reserved. + * Copyright (c) Microsoft 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 + * http://opensource.org/licenses/bsd-license.php + * + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + * + * Based on ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf + * + **/ + +#include +#include +#include +#include +#include +#include +#include +#include + +STATIC CONST CHAR16 mEpochVariableName[] = L"RtcEpochSeconds"; +STATIC CONST CHAR16 mTimeZoneVariableName[] = L"RtcTimeZone"; +STATIC CONST CHAR16 mDaylightVariableName[] = L"RtcDaylight"; + +/** + Returns the current time and date information, and the time-keeping capabilities + of the virtual RTC. + + @param Time A pointer to storage to receive a snapshot of the current time. + @param Capabilities An optional pointer to a buffer to receive the real time clock + device's capabilities. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error. + +**/ +EFI_STATUS +EFIAPI +LibGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities + ) +{ + EFI_STATUS Status; + UINT32 EpochSeconds; + INT16 TimeZone; + UINT8 Daylight; + UINT64 Freq; + UINT64 Counter; + UINT64 Remainder; + UINTN ElapsedSeconds; + UINTN Size; + + if (Time == NULL) { +return EFI_INVALID_PARAMETER; + } + + // Get the counter frequency + Freq = GetPerformanceCounterProperties (NULL, NULL); + if (Freq == 0) { +return EFI_DEVICE_ERROR; + } + + // Get the epoch time from non-volatile storage + Size = sizeof (UINTN); + ElapsedSeconds = 0; + Status = EfiGetVariable ( + (CHAR16 *)mEpochVariableName, + , + NULL, + , + (VOID *) + ); + // Fall back to compilation-time epoch if not set + if (EFI_ERROR (Status)) { +ASSERT(Status != EFI_INVALID_PARAMETER); +ASSERT(Status != EFI_BUFFER_TOO_SMALL); +// +// The following is intended to produce a compilation error on build +// environments where BUILD_EPOCH can not be set from inline shell. +// If you are attempting to use this library on such an environment, please +// contact the edk2 mailing list, so we can try to add support for it. +// +ElapsedSeconds = BUILD_EPOCH; +DEBUG (( + DEBUG_INFO, + "LibGetTime: %s non volatile variable was not found - Using compilation time epoch.\n", + mEpochVariableName + )); + } + Counter = GetPerformanceCounter (); + ElapsedSeconds += DivU64x64Remainder (Counter, Freq, ); + + // Get the current time zone information from non-volatile storage + Size = sizeof (TimeZone); + Status = EfiGetVariable ( + (CHAR16 *)mTimeZoneVariableName, + , + NULL, + , + (VOID *) + ); + + if (EFI_ERROR (Status)) { +ASSERT(Status != EFI_INVALID_PARAMETER); +ASSERT(Status != EFI_BUFFER_TOO_SMALL); + +if (Status != EFI_NOT_FOUND) { + return Status; +} + +// The time zone variable does not exist in non-volatile storage, so