Time&Date reset when power off the system

Hi
according to following article

https://developer.toradex.com/knowledge-base/how-to-use-the-real-time-clock-in-linux

sudo su
date -s "2020-01-25 15:11:40"
hwclock -w

i try to update date&time of my system , but when power off the system, its time was set to hardware
time again on next boot !!! what can i do to keep date&time update in every boot?

Best Regards

I assume you did insert a proper battery, right? What do the kernel messages say e.g. the output of dmesg | grep rtc?

Hi
excuse me for my delay to answer
yes i used a battery according to ixora manual(CR 1220 +3volt)

ubuntu@tegra-ubuntu:~$ sudo su
[sudo] password for ubuntu: 
root@tegra-ubuntu:/home/ubuntu# dmesg | grep rtc
[    3.766176] as3722-rtc as3722-rtc.1: rtc core: registered as3722 as rtc0
[    3.766183] as3722-rtc as3722-rtc.1: RTC interrupt 449
[    3.907807] rtc-ds1307 0-0068: oscillator failed, set time!
[    3.907998] rtc-ds1307 0-0068: rtc core: registered m41t0 as rtc1
[    3.908478] tegra_rtc tegra_rtc: rtc core: registered tegra_rtc as rtc2
[    3.908507] tegra_rtc tegra_rtc: Tegra internal Real Time Clock
[    6.710813] as3722-rtc as3722-rtc.1: setting system clock to 2000-01-01 00:00:10 UTC (946684810)
root@tegra-ubuntu:/home/ubuntu#

You may want to make sure to use rtc1 which is probably the only one to preserve time & date when powering off the system.

excuse me how can i use rtc1 as only one to preserve time & date?

hi, you need to create a udev rule file as explained here.

Best regards,
Jaski

hi
excuse me for my bad linux knowledge

i created a file 99-rtc1.rules in /etc/udev/rules.d with this content

KERNEL=="rtc1", SUBSYSTEM=="rtc", DRIVER=="", ATTR{name}=="m41t0", SYMLINK="rtc", MODE="0666"

but when i shut down tk1 the time&date reset again!!!

would you please explain me step by step what should i do

Thank you

Hi @toradexvision

I tested this and it works for me.

If you create the udev rules file, then rtc should be linked to rtc1 : ls -la /dev/rtc.

Regarding setting the time to RTC, you need to do the following:

  1. Turn off Ntp: sudo timedatectl set-ntp false
  2. Enable RTC local: sudo timedatectl set-local-rtc true
  3. Set time: sudo timedatectl set-time “2019-01-31 11:13:54”
  4. write time to RTC: sudo hwclock -w

After doing this, time should be retained even if you reboot the module.

Best regards,
Jaski

Hi Jaski

root@tegra-ubuntu:/home/ubuntu# cat /etc/udev/rules.d/99-rtc1.rules 
KERNEL=="rtc1", SUBSYSTEM=="rtc", DRIVER=="", ATTR{name}=="m41t0", SYMLINK="rtc", MODE="0666"
root@tegra-ubuntu:/home/ubuntu# ls -la /dev/rtc
lrwxrwxrwx 1 root root 4 Jan  1 00:00 /dev/rtc -> rtc0
root@tegra-ubuntu:/home/ubuntu# rm /dev/rtc
root@tegra-ubuntu:/home/ubuntu# ln -s /dev/rtc1 /dev/rtc
root@tegra-ubuntu:/home/ubuntu# ls -la /dev/rtc
lrwxrwxrwx 1 root root 9 Jan  1 00:04 /dev/rtc -> /dev/rtc1
root@tegra-ubuntu:/home/ubuntu# timedatectl set-ntp false
root@tegra-ubuntu:/home/ubuntu# timedatectl set-local-rtc true
root@tegra-ubuntu:/home/ubuntu# timedatectl set-time "2020-01-29 11:12:20"
root@tegra-ubuntu:/home/ubuntu# hwclock -w

but when power off (not reboot) ixora , time&date reset again!!!
also i realized that symbolic link reset again !!!

root@tegra-ubuntu:/home/ubuntu# ls -la /dev/rtc
    lrwxrwxrwx 1 root root 4 Jan  1 00:00 /dev/rtc -> rtc0

Best Regards

Hi, You have typos in your udev rules file. Correct them and it should work.

Best regards,
Jaski

hi
excuse me you was right i correct it ,but still not work !!!

root@tegra-ubuntu:/home/ubuntu# cat /etc/udev/rules.d/99-rtc1.rules
KERNEL=="rtc1", SUBSYSTEM=="rtc", DRIVER=="", ATTR{name}=="m41t0", SYMLINK="rtc", MODE="0666"

 root@tegra-ubuntu:/home/ubuntu# timedatectl set-ntp false
 root@tegra-ubuntu:/home/ubuntu# timedatectl set-local-rtc true
 root@tegra-ubuntu:/home/ubuntu# timedatectl set-time "2020-01-29 11:12:20"
 root@tegra-ubuntu:/home/ubuntu# hwclock -w

Best Regards

What is not working? Could you share some error or output log?

hi Jaski
it seems rtc1 rules worked

 root@tegra-ubuntu:/home/ubuntu# ls -la  /dev/rtc
    lrwxrwxrwx 1 root root 4 Jan  1 00:00 /dev/rtc -> rtc1

and output of hwclock -r is correct

root@tegra-ubuntu:/home/ubuntu# hwclock -r
Wed 29 Jan 2020 11:17:59 AM UTC  -0.429637 seconds

but i still have problem !!!

root@tegra-ubuntu:/home/ubuntu# date
Sat Jan  1 00:03:21 UTC 2000

it seems system time still not correct . perhaps i should run hwclock -s at the beginning as an autostart program , is it true?

excuse me for lot of my stupid questions perhaps it is better to block my ID in toradex community

Perfect that it works.

perhaps i should run hwclock -s at the beginning as an autostart program , is it true?

Yes, you are absolutely right.

excuse me for lot of my stupid questions perhaps it is better to block my ID in toradex community

No, that’s ok ;).

Best regards,
Jaski