Message ID | 20201025071316.37416-1-xypron.glpk@gmx.de |
---|---|
Headers | show |
Series | rtc: provide an emulated RTC | expand |
Can I suggest as a future enhancement adding an option to also be able to read U_BOOT_EPOCH from env? Userspace tools could write the time on shutdown (like fakehwclock). Ok, adding `date xxxxx` to the start script could work too, but it seems messy. Pablo. On 25/10/20 04:13, Heinrich Schuchardt wrote: > 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. > > v2: > more elaborate Kconfig message > adjust device name properties > use build time as initial time > > Heinrich Schuchardt (2): > Makefile: provide constant with seconds since epoch > rtc: provide an emulated RTC > > MAINTAINERS | 1 + > Makefile | 2 ++ > drivers/rtc/Kconfig | 11 ++++++ > drivers/rtc/Makefile | 1 + > drivers/rtc/emul_rtc.c | 80 ++++++++++++++++++++++++++++++++++++++++++ > 5 files changed, 95 insertions(+) > create mode 100644 drivers/rtc/emul_rtc.c > > -- > 2.28.0 >
On 10/29/20 11:27 AM, Pablo Sebastián Greco wrote: > Can I suggest as a future enhancement adding an option to also be able > to read U_BOOT_EPOCH from env? Userspace tools could write the time on > shutdown (like fakehwclock). Thank you for your suggestion. What does fakehwclock relate to? > Ok, adding `date xxxxx` to the start script could work too, but it seems > messy. If you have network, you should use CONFIG_CMD_SNTP=Y and CONFIG_BOOTP_NTPSERVER=y and add "setenv autoload no && dhcp && sntp" to your script. This is why I submitted the following patch: net: sntp: remove CONFIG_TIMESTAMP constraint https://lists.denx.de/pipermail/u-boot/2020-October/430445.html If we want to follow you idea, we would have a probe() and a remove() method to the driver for managing the environment variable. One problem with saving the time on shutdown to the environment is that save_env() always saves the complete environment and not a single variable. Saving the complete environment may save changes that you do not want to persist. So a complete solution will require: * Create a function to save a single environment variable selectively. This will be the part with the biggest effort. * Implement the probe() and remove() methods * Add a Kconfig option to enable the usage of the environment variable. But is this worth the effort if you have SNTP? Best regards Heinrich > > On 25/10/20 04:13, Heinrich Schuchardt wrote: >> 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. >> >> v2: >> more elaborate Kconfig message >> adjust device name properties >> use build time as initial time >> >> Heinrich Schuchardt (2): >> Makefile: provide constant with seconds since epoch >> rtc: provide an emulated RTC >> >> MAINTAINERS | 1 + >> Makefile | 2 ++ >> drivers/rtc/Kconfig | 11 ++++++ >> drivers/rtc/Makefile | 1 + >> drivers/rtc/emul_rtc.c | 80 ++++++++++++++++++++++++++++++++++++++++++ >> 5 files changed, 95 insertions(+) >> create mode 100644 drivers/rtc/emul_rtc.c >> >> -- >> 2.28.0 >>
On 29/10/20 08:36, Heinrich Schuchardt wrote: > On 10/29/20 11:27 AM, Pablo Sebastián Greco wrote: >> Can I suggest as a future enhancement adding an option to also be able >> to read U_BOOT_EPOCH from env? Userspace tools could write the time on >> shutdown (like fakehwclock). > Thank you for your suggestion. > > What does fakehwclock relate to? fake-hwclock is a userspace linux tool that saves the current time in a file, in case ntp is not available at reboot time, so the clock will not be perfect, but it may be "good enough" > >> Ok, adding `date xxxxx` to the start script could work too, but it seems >> messy. > If you have network, you should use CONFIG_CMD_SNTP=Y and > CONFIG_BOOTP_NTPSERVER=y and add "setenv autoload no && dhcp && sntp" to > your script. > > This is why I submitted the following patch: > > net: sntp: remove CONFIG_TIMESTAMP constraint > https://lists.denx.de/pipermail/u-boot/2020-October/430445.html > > If we want to follow you idea, we would have a probe() and a remove() > method to the driver for managing the environment variable. > > One problem with saving the time on shutdown to the environment is that > save_env() always saves the complete environment and not a single > variable. Saving the complete environment may save changes that you do > not want to persist. > > So a complete solution will require: > > * Create a function to save a single environment variable selectively. > This will be the part with the biggest effort. That would be nice to have, even if not related to this. > * Implement the probe() and remove() methods > * Add a Kconfig option to enable the usage of the environment variable. > > But is this worth the effort if you have SNTP? If SNTP is available, I agree that it makes no sense. but may not always be the case (as noted before), and some programs don't react too kindly to the clock jumping ahead several years during boot, so it would be nice to have a "good enough" clock before the kernel takes over, Also, as was mentioned in other parts of the thread, some devices may be too close to the size limit, but I'd happily exchange network in uboot for this driver. I know the idea is a bit wacky, but thought it could be useful ;) > > Best regards > > Heinrich > >> On 25/10/20 04:13, Heinrich Schuchardt wrote: >>> 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. >>> >>> v2: >>> more elaborate Kconfig message >>> adjust device name properties >>> use build time as initial time >>> >>> Heinrich Schuchardt (2): >>> Makefile: provide constant with seconds since epoch >>> rtc: provide an emulated RTC >>> >>> MAINTAINERS | 1 + >>> Makefile | 2 ++ >>> drivers/rtc/Kconfig | 11 ++++++ >>> drivers/rtc/Makefile | 1 + >>> drivers/rtc/emul_rtc.c | 80 ++++++++++++++++++++++++++++++++++++++++++ >>> 5 files changed, 95 insertions(+) >>> create mode 100644 drivers/rtc/emul_rtc.c >>> >>> -- >>> 2.28.0 >>> Pablo