cancel
Showing results for 
Search instead for 
Did you mean: 

Hello, I'd like to preserve time after rebooting, when no internet connection is present. Every time I reboot I get the same date, which i presume is the late date there was an internet connection. I'd like to update this system clock with the current tim

Lmoio.1
Senior
root@stm32mp1:~# timedatectl status
               Local time: Thu 2021-10-14 15:10:06 UTC
           Universal time: Thu 2021-10-14 15:10:06 UTC
                 RTC time: Sat 2000-01-01 00:00:38
                Time zone: UTC (UTC, +0000)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no

My RTC is out of sync.

This is the date loaded after every boot. Where does system clock get it?

This is the timesyncd service.

[[0;1;32m*[[0m systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
     Active: [[0;1;32mactive (running)[[0m since Thu 2021-10-14 15:09:43 UTC; 2min 23s ago
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 373 (systemd-timesyn)
     Status: "Idle."
     Memory: 576.0K
     CGroup: /system.slice/systemd-timesyncd.service
             `-373 /lib/systemd/systemd-timesyncd
 
Sep 20 10:44:02 stm32mp1 systemd[1]: Starting Network Time Synchronization...
Sep 20 10:44:03 stm32mp1 systemd-timesyncd[373]: System clock time unset or jumped backwards, restoring from recorded timesta
mp: Thu 2021-10-14 15:09:43 UTC
Oct 14 15:09:43 stm32mp1 systemd[1]: Started Network Time Synchronization.

I already tried:

hwclock -w, then rebooting, then hwclock -s, but it goes back to 2000s.

Can someone help me?

1 ACCEPTED SOLUTION

Accepted Solutions

Ok, I got the point.

You wanted to save the current system time as the 'last ntp time' which is the one restored at boot time. right ?

I'm not SW expert, but I found that which seems working. Don't know if it is a reliable solution.

date -s "fri oct 15 09:54:00 UTC 2021"  <-- if needed
touch /var/lib/systemd/timesync/clock
sync

I hope other people from community have some more clever answers.

Regards.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

5 REPLIES 5
PatrickF
ST Employee

Hi,

to 'copy' system time to RTC, you need to use the following:

hwclock --systohc --utc

See https://wiki.st.com/stm32mpu/wiki/How_to_use_the_RTC

Obviously, need a 3V battery on VBAT pin to keep time in absence of power.

Regards.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

The point is my cmos battery is dead, but somehow at boot, time is not the RTC reset time (Sat 2000-01-01 00:00:38), but is restored to the last time that there was an internet connection (i think it's the ntp service that does this). However this time does not keep the progress while the board is running offline. How can i update this time, so that it accounts for the time the board is on but offline at the next reboot?

Thanks

Ok, I got the point.

You wanted to save the current system time as the 'last ntp time' which is the one restored at boot time. right ?

I'm not SW expert, but I found that which seems working. Don't know if it is a reliable solution.

date -s "fri oct 15 09:54:00 UTC 2021"  <-- if needed
touch /var/lib/systemd/timesync/clock
sync

I hope other people from community have some more clever answers.

Regards.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Thanks for your help, but stil can't achieve what i want.

As you suggest, the documentation says:

"/var/lib/systemd/timesync/clock

The modification time ("mtime") of this file is updated on each successful NTP synchronization or after each

SaveIntervalSec= time interval, as specified in timesyncd.conf(5). At the minimum, it will be set to the systemd build date. It is used to ensure that the system clock remains roughly monotonic across reboots, in case no local RTC is available."

When i connect to internet and ntp gets a new date, the modification time of the file changes, but if i try to add SaveIntervalSec inside timesyncd.conf i get that the service does not know the variable

Oct 15 08:52:01 stm32mp1 systemd-timesyncd[1171]: [[0;1;38;5;185m[[0;1;39m[[0;1;38;5;185m/etc/systemd/timesyncd.conf:6: Unkno
wn key name 'SaveIntervalSec' in section 'Time', ignoring.[[0m

I think i'll just call a script that does "touch /var/lib/systemd/timesync/clock" periodically.

Thanks again for the help

Have a nice day

Hi,

Seems the 'SaveIntervalSec' is not supported in the Linux we use (don't ask me why, I'm an HW guy !).

Regards,

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.