N2 time not synced with RTC at startup

Post Reply
Zdenek
Posts: 3
Joined: Sat Apr 27, 2019 11:28 pm
languages_spoken: english
ODROIDs: N2
Has thanked: 0
Been thanked: 0
Contact:

N2 time not synced with RTC at startup

Unread post by Zdenek » Sat Apr 27, 2019 11:58 pm

N2 running Ubuntu minimal 20190329, all updates, kernel: Linux 4.9.170-25.
I plugged battery to RTC. RTC keeps time during shutdown. After boot, TRC time is not synced to system clock.

Code: Select all

zdenek@odroid:~$ sudo hwclock -r && date
2019-04-27 14:01:41.313761+0200
Sat Apr 27 14:01:42 CEST 2019
zdenek@odroid:~$ sudo shutdown -h now

Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.9.170-25 aarch64)
Last login: Sat Apr 27 13:52:27 2019 from 10.0.0.21
zdenek@odroid:~$ sudo hwclock -r && date
2019-04-27 14:38:06.082188+0200
Sat Apr 27 13:52:26 CEST 2019
zdenek@odroid:~$ sudo hwclock -s
zdenek@odroid:~$ sudo hwclock -r && date
2019-04-27 14:38:25.346740+0200
Sat Apr 27 14:38:26 CEST 2019

Code: Select all

sudo dmesg |grep rtc
[    5.199769] hctosys: unable to open rtc device (rtc0)
[   15.213530] rtc-pcf8563 3-0051: rtc core: registered rtc-pcf8563 as rtc0
Can this be the reason? Is kernel trying to restore clock before RTC HW device is registered?
I am not so familiar with linux and don't know how to reorder startup of these services...
Any suggestions?

User avatar
tobetter
Posts: 4043
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 43 times
Been thanked: 189 times
Contact:

Re: N2 time not synced with RTC at startup

Unread post by tobetter » Sun Apr 28, 2019 2:54 am

Zdenek wrote:
Sat Apr 27, 2019 11:58 pm
N2 running Ubuntu minimal 20190329, all updates, kernel: Linux 4.9.170-25.
I plugged battery to RTC. RTC keeps time during shutdown. After boot, TRC time is not synced to system clock.

Code: Select all

zdenek@odroid:~$ sudo hwclock -r && date
2019-04-27 14:01:41.313761+0200
Sat Apr 27 14:01:42 CEST 2019
zdenek@odroid:~$ sudo shutdown -h now

Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.9.170-25 aarch64)
Last login: Sat Apr 27 13:52:27 2019 from 10.0.0.21
zdenek@odroid:~$ sudo hwclock -r && date
2019-04-27 14:38:06.082188+0200
Sat Apr 27 13:52:26 CEST 2019
zdenek@odroid:~$ sudo hwclock -s
zdenek@odroid:~$ sudo hwclock -r && date
2019-04-27 14:38:25.346740+0200
Sat Apr 27 14:38:26 CEST 2019

Code: Select all

sudo dmesg |grep rtc
[    5.199769] hctosys: unable to open rtc device (rtc0)
[   15.213530] rtc-pcf8563 3-0051: rtc core: registered rtc-pcf8563 as rtc0
Can this be the reason? Is kernel trying to restore clock before RTC HW device is registered?
I am not so familiar with linux and don't know how to reorder startup of these services...
Any suggestions?
Have you done once this command after RTC battery is connected?

Code: Select all

sudo hwclock -w
FYI, https://wiki.odroid.com/odroid-n2/appli ... akeup_time

Zdenek
Posts: 3
Joined: Sat Apr 27, 2019 11:28 pm
languages_spoken: english
ODROIDs: N2
Has thanked: 0
Been thanked: 0
Contact:

Re: N2 time not synced with RTC at startup

Unread post by Zdenek » Sun Apr 28, 2019 6:18 am

RTC is definitely working. I did write value with sudo hwclock -w command. I can see correct time after shutdown with sudo hwclock -r command while system time is even older than shutdown time - see again the code below, i made some remarks to it to be clearer.

Code: Select all

zdenek@odroid:~$ sudo hwclock -r && date
2019-04-27 14:01:41.313761+0200 <<<<< hwclock before reboot
Sat Apr 27 14:01:42 CEST 2019 <<<<< system time before reboot

Shutdown for about half hour with PSU disconnected.
Note: internet connection was disabled on router to prevent N2 NTP daemon from kick in and set correct time right after reboot.

zdenek@odroid:~$ sudo hwclock -r && date
2019-04-27 14:38:06.082188+0200 <<<<< CORRECT TIME from hwclock after reboot 
Sat Apr 27 13:52:26 CEST 2019 <<<<< OLD system time after reboot 
Now i can manually set system time by sudo hwclock -s.
BTW even RTC alarm wakeup is working (there is delay about 45 seconds between scheduled time and actual start of board (red LED ON), but it is working).
Only problem is that system clock is not synced during boot.
I can use @reboot sudo hwclock -s cron job, but i am wondering if somebody else is experiencing same problem...

phaseshifter
Posts: 3495
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: U-2,U3+,,XU-3,,XU3-LITE,,XU-4
C1+,,C-2,,,
N-1,,N-2,...other odroid acc`s as well
Has thanked: 39 times
Been thanked: 42 times
Contact:

Re: N2 time not synced with RTC at startup

Unread post by phaseshifter » Sun Apr 28, 2019 7:16 am

you may need to set up your time zone correctly..???
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!

Zdenek
Posts: 3
Joined: Sat Apr 27, 2019 11:28 pm
languages_spoken: english
ODROIDs: N2
Has thanked: 0
Been thanked: 0
Contact:

Re: N2 time not synced with RTC at startup

Unread post by Zdenek » Sun Apr 28, 2019 4:08 pm

Time zone was set after install with sudo dpkg-reconfigure tzdata

Code: Select all

timedatectl status
                      Local time: Sun 2019-04-28 08:55:25 CEST
                  Universal time: Sun 2019-04-28 06:55:25 UTC
                        RTC time: Sun 2019-04-28 06:55:26
                       Time zone: Europe/Prague (CEST, +0200)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

Code: Select all

sudo hwclock -D
hwclock from util-linux 2.31.1
System Time: 1556434518.431144
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Last drift adjustment done at 1556397128 seconds after 1969
Last calibration done at 1556397128 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
ioctl(4, RTC_UIE_ON, 0): Invalid argument
Waiting in loop for time from /dev/rtc0 to change
...got clock tick
Time read from Hardware Clock: 2019/04/28 06:55:20
Hw clock time : 2019/04/28 06:55:20 = 1556434520 seconds since 1969
Time since last adjustment is 37392 seconds
Calculated Hardware Clock drift is 0.000000 seconds
2019-04-28 08:55:19.284533+0200

darkusas
Posts: 4
Joined: Mon May 13, 2019 3:14 pm
languages_spoken: english
ODROIDs: ODROID-N2
Has thanked: 3 times
Been thanked: 0
Contact:

Re: N2 time not synced with RTC at startup

Unread post by darkusas » Mon May 13, 2019 7:49 pm

Hi,

Did anybody solve this problem?

I do experience the same problem. System clock not updated from RTC after startup.


Code: Select all

root@odroid:~# timedatectl
                      Local time: Mon 2019-05-13 13:33:49 EEST
                  Universal time: Mon 2019-05-13 10:33:49 UTC
                        RTC time: Mon 2019-05-13 10:42:48
                       Time zone: Europe/Vilnius (EEST, +0300)
       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

Code: Select all

root@odroid:~# dmesg |grep rtc
[    5.219851] hctosys: unable to open rtc device (rtc0)
[    7.437876] rtc-pcf8563 3-0051: rtc core: registered rtc-pcf8563 as rtc0

It seems to me that RTC to SYSTEM date time transfer initiated before initialization of RTC hardware. But how to solve it?

cap00k
Posts: 88
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID
Has thanked: 0
Been thanked: 9 times
Contact:

Re: N2 time not synced with RTC at startup

Unread post by cap00k » Tue May 14, 2019 2:04 pm

Hi,

That's correct, hctosys works before RTC hardware initialized. Because the i2c/rtc drivers are modules.
There are two ways to solve this problem.

1) To build the kernel by replacing the two module drivers with built-in.

Code: Select all

CONFIG_AMLOGIC_I2C_MASTER = y
CONFIG_RTC_DRV_PCF8563 = y
2) If you want to update system Time/Calendar from the HW RTC at boot time by editing /etc/rc.local file

Code: Select all

odroid@odroid:~$ sudo nano /etc/rc.local
 
if [ -f /aafirstboot ]; then /aafirstboot start ; fi
 
hwclock -s
 
exit 0
odroid@odroid:~$
I recommend the second.
These users thanked the author cap00k for the post:
darkusas (Wed May 15, 2019 2:05 pm)

darkusas
Posts: 4
Joined: Mon May 13, 2019 3:14 pm
languages_spoken: english
ODROIDs: ODROID-N2
Has thanked: 3 times
Been thanked: 0
Contact:

Re: N2 time not synced with RTC at startup

Unread post by darkusas » Tue May 14, 2019 2:36 pm

Thanks, I was not sure that this is the correct way, but I already solved this problem with cron.

Code: Select all

root@odroid:~# crontab -l
@reboot /sbin/hwclock  --hctosys 
I believe, this works similar to the second option that you offered.

cap00k wrote:
Tue May 14, 2019 2:04 pm
Hi,

That's correct, hctosys works before RTC hardware initialized. Because the i2c/rtc drivers are modules.
There are two ways to solve this problem.

1) To build the kernel by replacing the two module drivers with built-in.

Code: Select all

CONFIG_AMLOGIC_I2C_MASTER = y
CONFIG_RTC_DRV_PCF8563 = y
2) If you want to update system Time/Calendar from the HW RTC at boot time by editing /etc/rc.local file

Code: Select all

odroid@odroid:~$ sudo nano /etc/rc.local
 
if [ -f /aafirstboot ]; then /aafirstboot start ; fi
 
hwclock -s
 
exit 0
odroid@odroid:~$
I recommend the second.

nikodemus
Posts: 25
Joined: Fri Mar 08, 2019 2:15 pm
languages_spoken: german, english
ODROIDs: C1, C2, XU4, N2
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: N2 time not synced with RTC at startup

Unread post by nikodemus » Sun May 19, 2019 2:53 pm

Solution no 1 has advantages, because there is no need to remember this detail when burning a new os image. Would it significantly increase the kernel?

User avatar
odroid
Site Admin
Posts: 32368
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 147 times
Been thanked: 325 times
Contact:

Re: N2 time not synced with RTC at startup

Unread post by odroid » Mon May 20, 2019 8:32 am

I think the difference of the kernel size must be negligible.
But we have to consider a side effect since many people are not using the RTC backup battery.
Let's check it.

User avatar
odroid
Site Admin
Posts: 32368
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 147 times
Been thanked: 325 times
Contact:

Re: N2 time not synced with RTC at startup

Unread post by odroid » Thu May 23, 2019 6:06 pm

Because some users have used the I2C signals as a GPIO mode on the 40pin header, we can't build the module into the kernel.
The I2C bus on the 40pin header is connected to the RTC chip too.

We've slightly updated the RTC wiki page with some workarounds.
https://wiki.odroid.com/odroid-n2/appli ... at_startup

paulcrawford
Posts: 145
Joined: Tue May 10, 2016 11:51 am
languages_spoken: english
ODROIDs: c2 and n2
Has thanked: 18 times
Been thanked: 1 time
Contact:

Re: N2 time not synced with RTC at startup

Unread post by paulcrawford » Thu May 23, 2019 8:10 pm

@odroid, I was reviewing the updated wiki and tried this example:

Code: Select all

sudo fdtget /boot/dtb /soc/cbus@ffd00000/i2c@1c000 status
It failed:

Code: Select all

root@no:/sys/class/gpio# fdtget /boot/dtb /soc/cbus@ffd00000/i2c@1c000 status
Couldn't open blob from '/boot/dtb': No such file or directory
The correct command is:

Code: Select all

root@no:/sys/class/gpio# fdtget /boot/meson64_odroidn2.dtb /soc/cbus@ffd00000/i2c@1c000 status
okay
root@no:/sys/class/gpio#
It seems that some untested commands get into the wiki e.g. this and the pwm issue. Would it not be better to actually run the commands on an N2 rather than simply type something into the wiki?

Thanks.

User avatar
tobetter
Posts: 4043
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 43 times
Been thanked: 189 times
Contact:

Re: N2 time not synced with RTC at startup

Unread post by tobetter » Thu May 23, 2019 11:47 pm

@paulcrawford, thanks...the Wiki page is updated.

oldchap
Posts: 66
Joined: Mon Aug 07, 2017 3:27 pm
languages_spoken: english
Has thanked: 0
Been thanked: 2 times
Contact:

Re: N2 time not synced with RTC at startup

Unread post by oldchap » Sat May 25, 2019 1:53 pm

Is the RT battery from a XU4 able to be used in a N2? thanks

User avatar
tobetter
Posts: 4043
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: X, X2, U2, U3, XU3, C1
Location: Paju, South Korea
Has thanked: 43 times
Been thanked: 189 times
Contact:

Re: N2 time not synced with RTC at startup

Unread post by tobetter » Sat May 25, 2019 2:56 pm

oldchap wrote:
Sat May 25, 2019 1:53 pm
Is the RT battery from a XU4 able to be used in a N2? thanks
If the battery has being connected to XU4, then it is.

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 0 guests