[PATCH v2 0/2] rtc: provide an emulated RTC
Heinrich Schuchardt
xypron.glpk at gmx.de
Thu Oct 29 12:36:16 CET 2020
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
>>
More information about the U-Boot
mailing list