* [PATCH 0/2] rtc: initialize emulated RTC from environment variable
@ 2020-10-30 3:19 Heinrich Schuchardt
2020-10-30 3:19 ` [PATCH 1/2] rtc: use probe() to initialize emulated RTC Heinrich Schuchardt
2020-10-30 3:19 ` [PATCH 2/2] rtc: initialize emulated RTC from environment variable Heinrich Schuchardt
0 siblings, 2 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2020-10-30 3:19 UTC (permalink / raw)
To: u-boot
Up to now the emulated RTC is initialized using the U-Boot build time.
With this patch the environment variable 'rtc_emul_epoch' can be used to
provide a better initial time. The variable is a decimal string with
the number of seconds since 1970-01-01.
Heinrich Schuchardt (2):
rtc: use probe() to initialize emulated RTC
rtc: initialize emulated RTC from environment variable
drivers/rtc/Kconfig | 13 ++++++++-----
drivers/rtc/emul_rtc.c | 29 +++++++++++++++++++++++------
2 files changed, 31 insertions(+), 11 deletions(-)
--
2.28.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] rtc: use probe() to initialize emulated RTC
2020-10-30 3:19 [PATCH 0/2] rtc: initialize emulated RTC from environment variable Heinrich Schuchardt
@ 2020-10-30 3:19 ` Heinrich Schuchardt
2020-11-03 15:12 ` Simon Glass
2020-10-30 3:19 ` [PATCH 2/2] rtc: initialize emulated RTC from environment variable Heinrich Schuchardt
1 sibling, 1 reply; 5+ messages in thread
From: Heinrich Schuchardt @ 2020-10-30 3:19 UTC (permalink / raw)
To: u-boot
Currently the emulated RTC is initialized in the emul_rtc_get() get
function. This does not match the design of the driver model.
Move the initialization of the emulated RTC to the probe() function.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
drivers/rtc/emul_rtc.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/rtc/emul_rtc.c b/drivers/rtc/emul_rtc.c
index c98c24bbb3..209b4965c1 100644
--- a/drivers/rtc/emul_rtc.c
+++ b/drivers/rtc/emul_rtc.c
@@ -30,12 +30,6 @@ static int emul_rtc_get(struct udevice *dev, struct rtc_time *time)
struct emul_rtc *priv = dev_get_priv(dev);
u64 now;
- if (!priv->offset_us) {
- /* Use the build date as initial time */
- priv->offset_us = U_BOOT_EPOCH * 1000000ULL - timer_get_us();
- priv->isdst = -1;
- }
-
now = timer_get_us() + priv->offset_us;
do_div(now, 1000000);
rtc_to_tm(now, time);
@@ -63,6 +57,17 @@ static int emul_rtc_set(struct udevice *dev, const struct rtc_time *time)
return 0;
}
+int emul_rtc_probe(struct udevice *dev)
+{
+ struct emul_rtc *priv = dev_get_priv(dev);
+
+ /* Use the build date as initial time */
+ priv->offset_us = U_BOOT_EPOCH * 1000000ULL - timer_get_us();
+ priv->isdst = -1;
+
+ return 0;
+}
+
static const struct rtc_ops emul_rtc_ops = {
.get = emul_rtc_get,
.set = emul_rtc_set,
@@ -72,6 +77,7 @@ U_BOOT_DRIVER(rtc_emul) = {
.name = "rtc_emul",
.id = UCLASS_RTC,
.ops = &emul_rtc_ops,
+ .probe = emul_rtc_probe,
.priv_auto_alloc_size = sizeof(struct emul_rtc),
};
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] rtc: initialize emulated RTC from environment variable
2020-10-30 3:19 [PATCH 0/2] rtc: initialize emulated RTC from environment variable Heinrich Schuchardt
2020-10-30 3:19 ` [PATCH 1/2] rtc: use probe() to initialize emulated RTC Heinrich Schuchardt
@ 2020-10-30 3:19 ` Heinrich Schuchardt
2020-11-03 15:12 ` Simon Glass
1 sibling, 1 reply; 5+ messages in thread
From: Heinrich Schuchardt @ 2020-10-30 3:19 UTC (permalink / raw)
To: u-boot
Up to now the emulated RTC is initialized using the U-Boot build time.
With this patch the environment variable 'rtc_emul_epoch' can be used to
provide a better initial time. The variable is a decimal string with
the number of seconds since 1970-01-01. Here is an example where the RTC
had not been probed yet:
=> setenv rtc_emul_epoch 1610109000
=> date
Date: 2021-01-08 (Friday) Time: 12:30:00
If the variable does not exist, the U-Boot build time is used as fallback.
The environment variable may be set when shutting down the operating system
if the U-Boot environment is exposed to the OS (cf. ENV_IS_IN_FAT and
ENV_IS_IN_EXT4).
Suggested-by: Pablo Sebasti?n Greco <pgreco@centosproject.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
drivers/rtc/Kconfig | 13 ++++++++-----
drivers/rtc/emul_rtc.c | 16 +++++++++++++---
2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index d06d272e14..cad667a404 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -68,11 +68,14 @@ config RTC_EMULATION
depends on DM_RTC
help
On a board without hardware clock this software real time clock can be
- used. The build time is used to initialize the RTC. So you will have
- to adjust the time either manually using the 'date' command or use
- the 'sntp' to update the RTC with the time from a network time server.
- See CONFIG_CMD_SNTP and CONFIG_BOOTP_NTPSERVER. The RTC time is
- advanced according to CPU ticks.
+ used. The initial time may be provided via the environment variable
+ 'rtc_emul_epoch' as a decimal string indicating seconds since
+ 1970-01-01. If the environment variable is missing, the build time is
+ used to initialize the RTC. The time can be adjusted manually via the
+ 'date' command or the 'sntp' command can be used to update the RTC
+ with the time from a network time server. See CONFIG_CMD_SNTP and
+ CONFIG_BOOTP_NTPSERVER. The RTC time is advanced according to CPU
+ ticks.
config RTC_ISL1208
bool "Enable ISL1208 driver"
diff --git a/drivers/rtc/emul_rtc.c b/drivers/rtc/emul_rtc.c
index 209b4965c1..7e522103fd 100644
--- a/drivers/rtc/emul_rtc.c
+++ b/drivers/rtc/emul_rtc.c
@@ -8,6 +8,7 @@
#include <common.h>
#include <div64.h>
#include <dm.h>
+#include <env.h>
#include <generated/timestamp_autogenerated.h>
#include <rtc.h>
@@ -60,9 +61,18 @@ static int emul_rtc_set(struct udevice *dev, const struct rtc_time *time)
int emul_rtc_probe(struct udevice *dev)
{
struct emul_rtc *priv = dev_get_priv(dev);
-
- /* Use the build date as initial time */
- priv->offset_us = U_BOOT_EPOCH * 1000000ULL - timer_get_us();
+ const char *epoch_str;
+ u64 epoch;
+
+ epoch_str = env_get("rtc_emul_epoch");
+
+ if (epoch_str) {
+ epoch = simple_strtoull(epoch_str, NULL, 10);
+ } else {
+ /* Use the build date as initial time */
+ epoch = U_BOOT_EPOCH;
+ }
+ priv->offset_us = epoch * 1000000ULL - timer_get_us();
priv->isdst = -1;
return 0;
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] rtc: initialize emulated RTC from environment variable
2020-10-30 3:19 ` [PATCH 2/2] rtc: initialize emulated RTC from environment variable Heinrich Schuchardt
@ 2020-11-03 15:12 ` Simon Glass
0 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2020-11-03 15:12 UTC (permalink / raw)
To: u-boot
On Thu, 29 Oct 2020 at 21:20, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Up to now the emulated RTC is initialized using the U-Boot build time.
>
> With this patch the environment variable 'rtc_emul_epoch' can be used to
> provide a better initial time. The variable is a decimal string with
> the number of seconds since 1970-01-01. Here is an example where the RTC
> had not been probed yet:
>
> => setenv rtc_emul_epoch 1610109000
> => date
> Date: 2021-01-08 (Friday) Time: 12:30:00
>
> If the variable does not exist, the U-Boot build time is used as fallback.
>
> The environment variable may be set when shutting down the operating system
> if the U-Boot environment is exposed to the OS (cf. ENV_IS_IN_FAT and
> ENV_IS_IN_EXT4).
>
> Suggested-by: Pablo Sebasti?n Greco <pgreco@centosproject.org>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> drivers/rtc/Kconfig | 13 ++++++++-----
> drivers/rtc/emul_rtc.c | 16 +++++++++++++---
> 2 files changed, 21 insertions(+), 8 deletions(-)
Reviewed-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] rtc: use probe() to initialize emulated RTC
2020-10-30 3:19 ` [PATCH 1/2] rtc: use probe() to initialize emulated RTC Heinrich Schuchardt
@ 2020-11-03 15:12 ` Simon Glass
0 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2020-11-03 15:12 UTC (permalink / raw)
To: u-boot
On Thu, 29 Oct 2020 at 21:20, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Currently the emulated RTC is initialized in the emul_rtc_get() get
> function. This does not match the design of the driver model.
>
> Move the initialization of the emulated RTC to the probe() function.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> drivers/rtc/emul_rtc.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
Reviewed-by: Simon Glass <sjg@chromium.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-11-03 15:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-30 3:19 [PATCH 0/2] rtc: initialize emulated RTC from environment variable Heinrich Schuchardt
2020-10-30 3:19 ` [PATCH 1/2] rtc: use probe() to initialize emulated RTC Heinrich Schuchardt
2020-11-03 15:12 ` Simon Glass
2020-10-30 3:19 ` [PATCH 2/2] rtc: initialize emulated RTC from environment variable Heinrich Schuchardt
2020-11-03 15:12 ` Simon Glass
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.