[SOLVED] RTC not keeping time

Moderators: odroid, mdrjr

[SOLVED] RTC not keeping time

Unread postby Eliotness » Wed Jun 08, 2016 1:59 am

Hello All,

I just received and installed the RTC module from hardkernel. It seems to keep the time when I just restart the C-2, but if I shut it down and power on the next day, the time is reset again. It is almost as if the battery is dead. Has anybody else experienced this issue ? If I set the time manually again, hwclock -w and hwclock-r work fine. Until I shut the system down.
Eliotness
 
Posts: 6
Joined: Tue Apr 19, 2016 11:01 pm
languages_spoken: English,German
ODROIDs: C-2

Re: RTC not keeping time

Unread postby odroid » Wed Jun 08, 2016 10:26 am

Can you check the voltage of RTC battery with a DMM?
User avatar
odroid
Site Admin
 
Posts: 29098
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: RTC not keeping time

Unread postby Eliotness » Thu Jun 16, 2016 11:30 pm

I just changed the battery and did not have a chance to measure the voltage on the old one. This issue more and more is looking like a software problem. After I changed the battery, the clock was set to some random date in 2009 I think, which more or less makes sense. When I reboot the ordoid, or turn it of/on and boot, the system clock and hwclock are always set to February 11 2016. I don't know where this date is coming from. Maybe there is a command somewhere in the startup files that sets hwclock to the system time, instead of the other way around. I know about rc.local- this is set correctly to hwclock -s. Is there any other file, maybe ?
Eliotness
 
Posts: 6
Joined: Tue Apr 19, 2016 11:01 pm
languages_spoken: English,German
ODROIDs: C-2

Re: RTC not keeping time

Unread postby Eliotness » Fri Jun 17, 2016 10:45 pm

Ok. So turns out the problem was the ntp service. I have a firewall here, that blocks NTP requests, hence the need for an RTC. When the Odroid starts up, it tries to connect to the NTP server. As the next step, the current date/time are written to the hardware clock. If the NTP connection fails, the default date/time are written to the hwclock. Once I disabled the NTP service, the hwclock was not overwritten anymore.
Now If I could get the hwclock -s command in the rc.local working, everything would be perfect !!
Last edited by Eliotness on Mon Jun 20, 2016 10:46 pm, edited 1 time in total.
Eliotness
 
Posts: 6
Joined: Tue Apr 19, 2016 11:01 pm
languages_spoken: English,German
ODROIDs: C-2

Re: RTC not keeping time

Unread postby crossover » Sat Jun 18, 2016 10:48 am

I have a similar issue. How did you disable the NTP service?
crossover
 
Posts: 113
Joined: Wed Jul 22, 2015 2:23 pm
languages_spoken: english
ODROIDs: XU4, C1+, C2, USB-IO, HC2, Tinkering kits

Re: RTC not keeping time

Unread postby phaseshifter » Sun Jun 19, 2016 2:19 pm

post removed irrelevant
Last edited by phaseshifter on Tue Jun 21, 2016 12:26 am, edited 1 time in total.
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!
phaseshifter
 
Posts: 3000
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: N-1..c1+ ..c-2..xu3 lite,xu4...u-3..
u-2...other odroid acc`s as well

Re: RTC not keeping time

Unread postby phaseshifter » Sun Jun 19, 2016 6:43 pm

To stop ntpd:

Code: Select all
sudo /etc/init.d/ntp stop


or

Code: Select all
sudo service ntp stop


To prevent it from starting at boot:

Code: Select all
sudo update-rc.d -f ntp remove

or
Code: Select all
sudo update-rc.d -f ntp disable
Last edited by phaseshifter on Sat Dec 03, 2016 12:33 am, edited 2 times in total.
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!
phaseshifter
 
Posts: 3000
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: N-1..c1+ ..c-2..xu3 lite,xu4...u-3..
u-2...other odroid acc`s as well

Re: RTC not keeping time

Unread postby Eliotness » Mon Jun 20, 2016 10:45 pm

Phaseshifter, you are correct. I do have the hwclock -s line in the rc.local, but it does not do anything. If I open a terminal window after booting, and manually enter this command, everything works as it should (system time updates from the rtc).
Eliotness
 
Posts: 6
Joined: Tue Apr 19, 2016 11:01 pm
languages_spoken: English,German
ODROIDs: C-2

Re: RTC not keeping time

Unread postby phaseshifter » Tue Jun 21, 2016 12:11 am

this is the step`s i took & refer to the C-2 rtc setup page as per wiki

1: adjust time zone settings as per the gui at the top right of the screen
2: with a web page open simply click on the time at the top right of the screen and that should update the time..after having set your time zone settings
3: run the code as per wiki installing the tree compiler and then enter the line of code as per wiki
4: edit the /etc/modules file as per wiki
5: edit the rc.local file as per wiki
6 : reboot

if after you reboot & the time is not correct then open a web page and let it update the time or set it manually as per wiki
next write the time to the rtc modulle
Code: Select all
hwclock -w


run the code to stop ntp service at boot as per my notes above

reboot if all is well your time will be correct from now on unless you reset it or re-flash your opp system
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!
phaseshifter
 
Posts: 3000
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: N-1..c1+ ..c-2..xu3 lite,xu4...u-3..
u-2...other odroid acc`s as well

Re: RTC not keeping time

Unread postby phaseshifter » Tue Jun 21, 2016 12:24 am

i think you have the hwclock -s below the exit line in the rc.local file ..put it above the exit line...
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!
phaseshifter
 
Posts: 3000
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: N-1..c1+ ..c-2..xu3 lite,xu4...u-3..
u-2...other odroid acc`s as well

Re: RTC not keeping time

Unread postby phaseshifter » Sun Nov 06, 2016 2:30 pm

if you followed the wiki code to remove the ntp service
and find the need to reset-restart it temporary and reset the time...

open a terminal
restart start ntp service
Code: Select all
sudo /etc/init.d/ntp start


you can now go ahead and set the time in the gui clock or via the terminal code...
i found it easier to do it via gui
wait for it to update the time

next
check the clock in a terminal
Code: Select all
hwclock -r


then write it after it updates
Code: Select all
hwclock -w


Code: Select all
reboot
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!
phaseshifter
 
Posts: 3000
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: N-1..c1+ ..c-2..xu3 lite,xu4...u-3..
u-2...other odroid acc`s as well

Re: RTC not keeping time

Unread postby yurikleb » Wed Nov 30, 2016 3:54 am

Hey all,

I have the same issue on the ODRID C2 running Android 5.1.1

I cant figure out howto disable NTP / prevent it from running on startup.
Code: Select all
su /etc/init.d/ntp stop


thanks!
yurikleb
 
Posts: 15
Joined: Tue Aug 09, 2016 1:05 am
languages_spoken: english
ODROIDs: C2

Re: RTC not keeping time

Unread postby phaseshifter » Wed Nov 30, 2016 6:10 am

Code: Select all
sudo update-rc.d -f ntp remove


this is for linux ubuntu but i dont use android..so i am not shure that it will work

follow the android setup here...http://odroid.com/dokuwiki/doku.php?id=en:pcf8563rtc
Build It And They Will Come...Be Bold And Mighty Forces Will Come To Your Aid..!!!
phaseshifter
 
Posts: 3000
Joined: Fri May 08, 2015 9:12 am
languages_spoken: english
ODROIDs: N-1..c1+ ..c-2..xu3 lite,xu4...u-3..
u-2...other odroid acc`s as well

Re: RTC not keeping time

Unread postby yurikleb » Wed Nov 30, 2016 6:51 pm

yeh the manual doesn't include an explanation how to disable NTP on Android only on Linux. :(
yurikleb
 
Posts: 15
Joined: Tue Aug 09, 2016 1:05 am
languages_spoken: english
ODROIDs: C2

Re: RTC not keeping time

Unread postby odroid » Wed Nov 30, 2016 7:31 pm

You don't need to disable NTP on Android.
Just edit /init.odroidc2.board.rc file.
http://odroid.com/dokuwiki/doku.php?id= ... tc#android
User avatar
odroid
Site Admin
 
Posts: 29098
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: RTC not keeping time

Unread postby yurikleb » Wed Nov 30, 2016 9:34 pm

Ok, It seems to work, the Odroid does seem to grab time from the RTC module. but it is still displaying the wrong time after reboot.
If I start the Odroid without the RTC connected the initial time is as expected - 1:00 Jan 01 1970
With the RTC connected the time is some random date and hour in the future (1:00 Jan 13 2024), it does seem to keep pace (also after reboot) relative to this future date.
But changing the time in the android settings does not seem to affect the time in the RTC.
How does one updates the RTC with the correct time and date?
I tried
Code: Select all
hwclock -w
but it doesn't seem to work in the Android terminal.
Its looking for a non existing:
Code: Select all
/dev/misc/rtc
yurikleb
 
Posts: 15
Joined: Tue Aug 09, 2016 1:05 am
languages_spoken: english
ODROIDs: C2

Re: RTC not keeping time

Unread postby odroid » Wed Nov 30, 2016 11:19 pm

Type "su" on the terminal and grant super-user permission.
And run "hwclock -w" command.
Also check "date" command output first.
User avatar
odroid
Site Admin
 
Posts: 29098
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: RTC not keeping time

Unread postby yurikleb » Thu Dec 01, 2016 12:09 am

Ok solved!
So after following the ANDROID instructions in the manual: http://odroid.com/dokuwiki/doku.php?id= ... tc#android
one needs to set the correct system time and then apply it to the RTC Module.

Change to Sudo in Android trminal:
Code: Select all
su


Set system time and date:
Code: Select all
date -s YYYYMMDD.HHmmss


Write the system time to the RTC via terminal command (make sure you are sudo):
Code: Select all
hwclock -w


Check RTC time is correct by running
Code: Select all
hwclock
yurikleb
 
Posts: 15
Joined: Tue Aug 09, 2016 1:05 am
languages_spoken: english
ODROIDs: C2

Re: RTC not keeping time

Unread postby odroid » Thu Dec 01, 2016 12:06 pm

Thank you for the confirmation.
I've added your instruction into the WiKi page : http://odroid.com/dokuwiki/doku.php?id= ... tc#android ;)

BTW, which version of Android OS image do you use?
In fact, we don't need to set the hwclock manually since the Android OS do it automatically in the shutdown process.
User avatar
odroid
Site Admin
 
Posts: 29098
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: [SOLVED] RTC not keeping time

Unread postby chargerent » Fri Jan 13, 2017 7:50 am

I cannot seem to get this to work.
Running android 5.1.1
kernel 3.14.29
followed wiki instructions.
not sure what "Load kernel image from vfat partition built rtc module." means
also fatload command in terminal does not work and erasing boot.ini does not fix things as new boot.ini is not created.
hwclock command gives me "can't open dev/misc/rtc no such file or directory
chargerent
 
Posts: 33
Joined: Sat May 07, 2016 1:13 am
languages_spoken: english
ODROIDs: Odroid C2

Re: [SOLVED] RTC not keeping time

Unread postby odroid » Fri Jan 13, 2017 12:22 pm

Run "Factory Reset" and reboot.
The boot.ini file will be generated automatically.

I've updated the guide.
http://odroid.com/dokuwiki/doku.php?id= ... tc#android
User avatar
odroid
Site Admin
 
Posts: 29098
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: [SOLVED] RTC not keeping time

Unread postby chargerent » Fri Jan 13, 2017 12:35 pm

running factory reset does not generate boot.ini. when i enter odroid utility it asks me to check and format internal fat storage. when i press yes it opens Storage settings and no formating option is avaliable. just unmount and erase data
chargerent
 
Posts: 33
Joined: Sat May 07, 2016 1:13 am
languages_spoken: english
ODROIDs: Odroid C2

Re: [SOLVED] RTC not keeping time

Unread postby odroid » Fri Jan 13, 2017 12:36 pm

Which OS image do you run?
Android 5.1.1 V2.8 ? or V.2.9 ?
http://odroid.com/dokuwiki/doku.php?id= ... se_android
User avatar
odroid
Site Admin
 
Posts: 29098
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: [SOLVED] RTC not keeping time

Unread postby chargerent » Fri Jan 13, 2017 12:54 pm

running build number odroidc2-eng 5.1.1 LMY49M odroidc2-eng-s905_5.1.1_master-285 test-keys
chargerent
 
Posts: 33
Joined: Sat May 07, 2016 1:13 am
languages_spoken: english
ODROIDs: Odroid C2

Re: [SOLVED] RTC not keeping time

Unread postby chargerent » Fri Jan 13, 2017 1:12 pm

also i am turning ntp off by flipping date and time switch off in settings menu, is that enough or do I need to do it in terminal in Android.
chargerent
 
Posts: 33
Joined: Sat May 07, 2016 1:13 am
languages_spoken: english
ODROIDs: Odroid C2

Re: [SOLVED] RTC not keeping time

Unread postby odroid » Fri Jan 13, 2017 3:20 pm

Ok. -285 release is the latest version.
Can you find "Image" file in FAT partition?
http://odroid.com/dokuwiki/doku.php?id= ... tc#android

If not, try this.
Run Settings App and select "Storage" sub-menu.
Internal Storage --> Erase SD card

After rebooting, you will have fresh boot.ini and Image files in FAT partition (/storage/internal/)
User avatar
odroid
Site Admin
 
Posts: 29098
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: [SOLVED] RTC not keeping time

Unread postby chargerent » Sat Jan 14, 2017 4:07 am

followed instructions above no boot.ini and no image in fat partition /storage/internal/. i have tried numerous times on two different odroids. factory reset also does not create boot.ini or image
chargerent
 
Posts: 33
Joined: Sat May 07, 2016 1:13 am
languages_spoken: english
ODROIDs: Odroid C2

Re: [SOLVED] RTC not keeping time

Unread postby rooted » Sat Jan 14, 2017 5:40 am

In /bin is the file makebootini.sh which does this:

Code: Select all
#!/bin/sh
if [ -e "/storage/internal/boot.ini" ]
then
    break
else
    cp /system/etc/boot.ini.template /storage/internal/boot.ini
fi



Hope this helps you sort the issue. boot.ini.template is indeed in the /system/etc directory.

The problem I see is /system is not getting mounted rw first. I think the script should be:

Code: Select all
#!/bin/sh
if [ -e "/storage/internal/boot.ini" ]
then
    break
else
    mount -o remount,rw /system
    cp /system/etc/boot.ini.template /storage/internal/boot.ini
    mount -o remount,ro /system
fi


Here is the boot.ini.template:
https://db.tt/UIObFAmHyk
Last edited by rooted on Sat Jan 14, 2017 5:53 am, edited 2 times in total.
User avatar
rooted
 
Posts: 5908
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english

Re: [SOLVED] RTC not keeping time

Unread postby chargerent » Sat Jan 14, 2017 5:46 am

thanks for tip. the file is missing in/bin. this is probably the problem
chargerent
 
Posts: 33
Joined: Sat May 07, 2016 1:13 am
languages_spoken: english
ODROIDs: Odroid C2

Re: [SOLVED] RTC not keeping time

Unread postby rooted » Sat Jan 14, 2017 5:48 am

chargerent wrote:thanks for tip. the file is missing in/bin. this is probably the problem

I am running 6.0.1 but I assumed this should be the same on 5.1.1.

Is the template in /system/etc?
User avatar
rooted
 
Posts: 5908
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english

Re: [SOLVED] RTC not keeping time

Unread postby chargerent » Sat Jan 14, 2017 5:50 am

ok found it its makebootini.sh
chargerent
 
Posts: 33
Joined: Sat May 07, 2016 1:13 am
languages_spoken: english
ODROIDs: Odroid C2

Re: [SOLVED] RTC not keeping time

Unread postby rooted » Sat Jan 14, 2017 5:52 am

Sorry, so used to mkdir I used mk for make. I edited my post.
User avatar
rooted
 
Posts: 5908
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english

Re: [SOLVED] RTC not keeping time

Unread postby chargerent » Sat Jan 14, 2017 9:00 am

I got rtc shield to work but had to manually copy boot.ini and image file to fat partition. guess that will work till they get a fix
chargerent
 
Posts: 33
Joined: Sat May 07, 2016 1:13 am
languages_spoken: english
ODROIDs: Odroid C2

Re: [SOLVED] RTC not keeping time

Unread postby Ameridroid » Sat Jan 14, 2017 9:09 am

Shouldn't it be:

Code: Select all
mount -o remount,rw /storage


Because the script is trying to write the boot.ini file to the /storage filesystem?
Ameridroid
 
Posts: 164
Joined: Thu Mar 17, 2016 4:19 am
languages_spoken: english

Re: [SOLVED] RTC not keeping time

Unread postby rooted » Sat Jan 14, 2017 9:31 am

No I don't think so, most are symlinks to /system/somepath

Not at home to see, if you run the command 'df' you should be able to see what is actually a mount point.

Something like these three are actual mounts:

/data
/system
/cache

*edit*
After getting home and checking I believe it is /storage but remounting rw isn't necessary since it's already rw.

/storage is a fuse mount

The only other thing I can think of is the shell script isn't being ran as root.
User avatar
rooted
 
Posts: 5908
Joined: Fri Dec 19, 2014 9:12 am
Location: Gulf of Mexico, US
languages_spoken: english

Re: [SOLVED] RTC not keeping time

Unread postby odroid » Mon Jan 16, 2017 12:29 pm

We couldn't reproduce the issue on an eMMC nor SD card with cleanly installed V2.9.

Anyway, we will make the RTC/I2C driver enabled kernel image as a default in the next update.
So most people will not need to edit the boot.ini file.
User avatar
odroid
Site Admin
 
Posts: 29098
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: [SOLVED] RTC not keeping time

Unread postby TEKNOSERVICE » Fri Jan 20, 2017 6:17 pm

If you want to use NTP with internet ntp servers and the hardware reloj. You have to disable ( NO remove) ntp at boot time and launch it in /etc/rc.local
$ sudo update-rc.d ntp disable
$ nano /etc/rc.local.
The rc.local before "exit 0":
hwclock –s
/etc/init.d/ntp start
exit 0
This works perfect on Ubuntu 16.04.

if you wants that the ntp service could read your hardware clock whrn there no internet u other nto servers you have to add two commands in /etc/ntp.conf before the polls of ntp servers
fudge 127.127.1.0 stratum 10
server 127.127.1.0

This is how works:
The data from the hardware clock always is present with a stratum of 10 ( very high).
if there no others ntp servers, ntp catch the data from the hardware, because it is the only server.
If there are ntp servers availables the datas are given with a stratum < 6 or 7 , bether than stratum 10 . So the data cauched by ntp are not from hardware clock.
TEKNOSERVICE
 
Posts: 4
Joined: Wed Jan 27, 2016 7:14 pm
languages_spoken: english, spanish
ODROIDs: XU4
C1+

Re: [SOLVED] RTC not keeping time

Unread postby mark_l » Sat Nov 24, 2018 3:00 am

I was working through this issue the other day and have some notes to add, in case it may be of assistance to someone.

NTP appears to be broken The logic is as follows:
-if no NTP server time, write current "unknown/default" time to HWCLOCK/RTC
-if NTP server time, leave HWCLOCK/RTC alone
This has the effect of trashing the RTC if NTP is running and it cannot reach a server. This is obviously Opposite of what one would normally want.

I hacked around this by modifying the /etc/init.d/ntc script to load the RTC time before starting the server, and writing the current time to the RTC when the NTP server is stopped.
Code: Select all
        start)
                log_daemon_msg "Starting NTP server" "ntpd"
                if [ -z "$UGID" ]; then
                        log_failure_msg "user \"$RUNASUSER\" does not exist"
                        exit 1
                fi

                #
                # hack! to fix ntp from setting HW clock to default time, should invoke a more intelligent script that takes into account UTC and BADYEAR settings
                #
                if /sbin/hwclock --hctosys ; then
                    echo "System Clock set to: `date`"
                fi

                lock_ntpdate
                start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $NTPD_OPTS
                status=$?
                unlock_ntpdate
                log_end_msg $status
                ;;
        stop)
                log_daemon_msg "Stopping NTP server" "ntpd"

                #
                # hack! to get the RTC to be updated to NTP time, should invoke a more intelligent script that takes into account UTC and BADYEAR settings
                #
                if /sbin/hwclock --systohc ;  then
                    echo "Hardware Clock updated to `date`"
                fi

                start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
                log_end_msg $?
                rm -f $PIDFILE
                ;;


As the comment states it is a hack, and needs more intelligence to operate correctly for all cases, mainly needs to take into account BADYEAR and UTC settings, as in the hwclock.sh script. (There is probably a more correct way to fix this, I welcome that input) I tried invoking the hwclock.sh (even with my fixes) script but it doesn't seem to work. (more on that below) The net result of this modification is that the system will boot with whatever time is in the RTC, and will switch to NTP time when a NTP server is reached. On shutdown the RTC is updated with whatever the current system time is. The bottom line is you can now have your RTC and NTP running!

As for hwclock.sh, it doesn't work as-is... or more specifically as it is named. The script stands out like a sore thumb in the /etc/init.d directory by being the only one with an extension, which made me explore it further. Trying to invoke it as-is, results in nothing, no messages, even when bad input is passed. The problem is the name, specifically the ".sh" extension. Renaming the script to "hwclock-sh" results in the script responding as expected. the overall fix is:
Code: Select all
# sudo update-rc.d hwclock.sh remove
# sudo mv /etc/init.d/hwclock.sh /etc/init.d/hwclock-sh
# sudo update-rc.d hwclock-sh defaults

While this does seem to fix the script, it still does not appear to run (or perhaps it is failing) on its own despite having the appropriate hooks in the rc?.d directories. I have not had a chance to track this down as of yet.

*note this has been tested on 16.04, I have not tried or tested 18.04 yet
mark_l
 
Posts: 3
Joined: Thu Nov 08, 2018 2:40 am
languages_spoken: english
ODROIDs: C2


Return to Hardware and peripherals

Who is online

Users browsing this forum: No registered users and 2 guests