Research on ubuntu 20.04 rtc time display problem

1. Hardware and software

        The hardware of this test is RK3568 chip, and the operating system is ubuntu 20.04.

 2. RTC and system time

       Let me talk about the result first. If the RTC driver is unavailable or the time stored in the RTC is invalid, the operating system will store the last valid time. When the power is turned on again, the date command will use the stored time as the start and count backwards. If there is no RTC driver, the operating system can synchronize the time with the Internet, and it will automatically synchronize the network time to the system time every time it is powered on, and the date read is the correct Beijing time.

     The following are some test records. When the operating system is not connected to the Internet, the power-on operation is repeated. The RTC will not maintain power supply after power-off, and read the system time.

RTC不带电容多次上电测试系统时间
1、上电eiota@firefly:~$ date
Tue 25 Jul 2023 04:18:18 PM CST

eiota@firefly:~$ sudo hwclock -r
[sudo] password for eiota:
2023-07-25 08:01:52.750005+08:00

2、Last login: Tue Jul 25 16:18:04 2023 from 10.10.26.92
eiota@firefly:~$ date
Tue 25 Jul 2023 04:18:29 PM CST
eiota@firefly:~$

3、eiota@firefly:~$ date
Tue 25 Jul 2023 04:22:39 PM CST
eiota@firefly:~$ sudo hwclock -r
[sudo] password for eiota:
2023-07-25 08:05:41.252411+08:00

4、
Last login: Tue Jul 25 16:22:33 2023 from 10.10.26.92
eiota@firefly:~$ date
Tue 25 Jul 2023 04:17:53 PM CST
eiota@firefly:~$ sudo hwclock -r
[sudo] password for eiota:
2023-07-25 08:00:43.260777+08:00
eiota@firefly:~$

5、联网同步过一次时间后,上电启动时间变成17:08了,说明linux系统会保存一个上一次的时间
Last login: Tue Jul 25 17:08:02 2023 from 10.10.26.92
eiota@firefly:~$ date
Tue 25 Jul 2023 05:07:53 PM CST
eiota@firefly:~$ date
Tue 25 Jul 2023 05:07:55 PM CST
eiota@firefly:~$ sudo hwclock -r
[sudo] password for eiota:
2023-07-25 08:00:58.126505+08:00
eiota@firefly:~$ date
Tue 25 Jul 2023 05:08:08 PM CST

6、Last login: Tue Jul 25 17:07:51 2023 from 10.10.26.92
dateeiota@firefly:~$ date
Tue 25 Jul 2023 05:07:43 PM CST

7、eiota@firefly:~$ date
Tue 25 Jul 2023 05:30:26 PM CST
eiota@firefly:~$
eiota@firefly:~$ sudo hwclock -r
[sudo] password for eiota:
2023-07-25 08:00:44.516689+08:00
eiota@firefly:~$

      

       For a newly programmed system, because the time may not have been synchronized, when the operating system starts for the first time, the RTC internally reads the wrong time, and there is no stored time, and the date command will not be able to read the time. At this time If the time is used in the started application, the program will report an error when it runs.

Guess you like

Origin blog.csdn.net/fhqlongteng/article/details/131924020