User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

UbuntuMATE 15.10 keeps the time of last shutdown in RTC chip

Sat Oct 31, 2015 1:46 pm

I’m using an RTC chip DS3231 in my RPi 2 B that Is automatically recognised during the boot up process when adding “dtoverlay=i2c-rtc,ds3231" at the end of the “/boot/config.txt” file.

However, after each power up of the device, and querying the date and time of the RTC chip, I always get the date and time information from my last shutdown of the device (note: I'm also running the "fake-hwclock" daemon).

Here the exemplary output after a power up of the device:

Code: Select all

root@ubox:~# date
Sat Oct 31 13:57:46 CET 2015
root@ubox:~# hwclock
Sat 31 Oct 2015 11:16:02 CET  .419496 seconds
The system time ultimately gets updated from the Internet NTP source, and then I can use the command "hwclock -w” to write back the system time to the RTC chip.

Shutting down the device, and powering it up again after a few minutes or even a day, brings me to the same situation of the RTC clock information being outdated.

The “dmesg” output shows the following:

Code: Select all

[    3.484039] bcm2708_i2c 3f804000.i2c: BSC1 Controller at 0x3f804000 (irq 79) (baudrate 100000)
[    3.489029] gpiomem-bcm2835 3f200000.gpiomem: Initialised: Registers at 0x3f200000
[    4.175719] rtc-ds1307 1-0068: rtc core: registered ds3231 as rtc0
[    5.232587] smsc95xx 1-1.1:1.0 enxb827ebe202d5: renamed from eth0
[    5.304795] random: nonblocking pool is initialized
[    7.020812] IPv6: ADDRCONF(NETDEV_UP): enxb827ebe202d5: link is not ready
[    7.078569] smsc95xx 1-1.1:1.0 enxb827ebe202d5: hardware isn't capable of remote wakeup
[    7.079407] IPv6: ADDRCONF(NETDEV_UP): enxb827ebe202d5: link is not ready
[    7.353996] bcm2708_fb soc:fb: Unknown ioctl 0x40187a22
Except of the “bcm2708_fb soc:fb: Unknown ioctl 0x40187a22” I do not see anything else to be strange…
Last edited by carriba on Sun Nov 08, 2015 1:32 pm, edited 1 time in total.

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sat Oct 31, 2015 5:06 pm

Mm... this is after your last post in the other thread.
Is the clock updating while the system is up - eg. read it at intervals from CLI
If so it may point lack of power while the machine is off - dead button cell?

Apart from that I have no idea, presumably your install has no fake-hwclock?

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sun Nov 01, 2015 12:48 pm

Yes, this happens when I added the "dtoverlay=i2c-rtc,ds3231" at the end of the "boot/config.txt" file.
Checking the voltage of the RTC chip, it is showing 2.95V, equal as with other RTC chips deployed on other RPi devices, and yes, it shows a running time when firing the “hwclock” command consecutively.
I swapped the RTC chip, and still the same behaviour. It shows the date & time form the last shutdown, which is presumably saved by the "fake-hwclock" daemon.
Disabling the "fake-hwclock" startup script, the "hwclock" outputs the 1 Jan 1970 or an invalid, unrecognised date and time error message.
If I remove this entry, and add back the line "dtparam=i2c_arm=on" in the "boot/config.txt" file (as in my other thread), reboot the device, and then fire the command "ds3231 0x68 >> /sys/class/i2c-adapter/i2c-1/new_device”, then fire “hwclock”, I can see current and correct date and time.
The Ubuntu man page writes “Automatic Hardware Clock Synchronization By the Kernel: You should be aware of another way that the Hardware Clock is kept synchronized in some systems. The Linux kernel has a mode wherein it copies the System Time to the Hardware Clock every 11 minutes. This is a good mode to use when you are using something sophisticated like ntp to keep your System Time synchronized.”
The only conclusion I can draw is that during bootup, the kernel is writing the last known date and time to the RTC chip, either the default one, or the one saved by the “fake-hwclock” process.
Will reinstall the UbuntuMATE 15.10 again on the RPi device with the "dtoverlay=i2c-rtc,ds3231" at the end of the "boot/config.txt", and see whether this behaviour is reproducible…
Last edited by carriba on Sun Nov 01, 2015 2:45 pm, edited 1 time in total.

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sun Nov 01, 2015 2:25 pm

After OS fresh installation with the line “dtoverlay=i2c-rtc,ds3231” in “/boot/config.txt”, I get the following output:

Code: Select all

root@ubox:~# hwclock ; date
Sun 01 Nov 2015 13:54:43 GMT  .179021 seconds
Sun Nov  1 13:54:43 GMT 2015
Then, wait a little bit until the system clock gets synchronised with NTP:

Code: Select all

root@ubox:~# hwclock ; date
Sun 01 Nov 2015 13:56:49 GMT  .842317 seconds
Sun Nov  1 14:06:19 GMT 2015
Shutdown the computer, and powering on after a bit more than 5 minutes:

Code: Select all

root@ubox:~# hwclock ; date
Sun 01 Nov 2015 14:10:55 GMT  .548882 seconds
Sun Nov  1 14:10:56 GMT 2015
Then, wait a little bit until the system clock gets synchronised with NTP:

Code: Select all

root@ubox:~# hwclock ; date
Sun 01 Nov 2015 14:11:14 GMT  .156004 seconds
Sun Nov  1 14:17:40 GMT 2015
Conclusion: For some reason, the HW clock displays the date and time of the last shutdown

User avatar
DougieLawson
Posts: 41966
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sun Nov 01, 2015 4:31 pm

There's three exciting parms for the hwclock program
hwclock # or hwclock -r to read the RTC
hwclock --hctosys # or hwclock -s to update the system clock from the RTC
hwclock --systohc # or hwclock -w to update the RTC from the system

Ideally some time after booting and getting a reliable NTP sync you need to use hwclock --systohc (I prefer that because I don't have to remember if it's -r, -w or -s, the operand tells me) to sync your RTC.
At shutdown/reboot you may want to do that hwclock --systohc again, as the last operation before ntpd terminates.

At boot, before getting a reliable NTP sync or if the network is unavailable you'll want to use hwclock --hctosys to read the RTC that's been keeping time while the RPi was dead and move the unset clock (which has defaulted to midnight on 1st Jan 1970) onwards to the current time (as held by the RTC).

How often sync operations are done depends on how much your RTC drifts compared to NTP.

The ntptime command will tell you if your clock is sync'd to NTP.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sun Nov 01, 2015 4:41 pm

Seems you are running fake-hwclock and a real one. You need to purge fake-hwclock

You need dtparam=i2c_arm=on as well as dtoverlay=i2c-rtc,ds3231 - at least that is what I have, the former enables i2c so that that the RTC can talk over the i2c bus

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Fri Nov 06, 2015 7:40 am

fruit-uk wrote:Seems you are running fake-hwclock and a real one. You need to purge fake-hwclock

You need dtparam=i2c_arm=on as well as dtoverlay=i2c-rtc,ds3231 - at least that is what I have, the former enables i2c so that that the RTC can talk over the i2c bus
Thank you for the feedback on this. I've done some tests.

It seems that I only need "dtoverlay=i2c-rtc,ds3231" in my "/boot/config.txt" file and the "/dev/rtc" device file is being created after the boot up process. No need to activate I2C bus at all :D

I activated and disactivated the "fake-hwclock", to see the effects on why the RTC chip is being displaying the lasts saved date or 1 Jan 1970 of my previous shutdown of the system.

Thus, there must be a process somewhere in the "/etc/init.d", "/etc/init" for services or other configuration files of the "systemd" startup daemon that is writing back or saving the running system time to the RTC chip, or maybe anything else that I have not been able to spot yet.

So, I keep looking further into this to nail down the portantial root cause... And from what I see here, the trend is to use the "systemd" services mechansim for all startup of services and daemons of a Linux OS.

I have found a nice primer on "systemd" that I'm looking into it right now; see https://www.digitalocean.com/community/ ... he-journal and also https://wiki.archlinux.org/index.php/Systemd.

So, will keep digging through all the UNIX startup configuration files and will let you know...
Last edited by carriba on Sat Nov 07, 2015 8:39 pm, edited 1 time in total.

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sat Nov 07, 2015 8:34 pm

Seems that this is a known probelm as described with https://bugs.archlinux.org/task/31674, https://bugs.mageia.org/show_bug.cgi?id=2521 and https://bugs.debian.org/cgi-bin/bugrepo ... bug=782377, sic!

Need to analyse all this info found, and going further through all Systemd documentation with http://www.freedesktop.org/software/sys ... index.html... and some hints found on how this can be accomplished as per http://derekmolloy.ie/automatically-set ... using-ntp/.
Last edited by carriba on Sat Nov 07, 2015 8:51 pm, edited 1 time in total.

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sat Nov 07, 2015 8:45 pm

Those bug reports are quite old.

This link provides interesting reading https://bugs.debian.org/cgi-bin/bugrepo ... bug=764552 though I have no idea whether any of that affects your ubuntu install

I have two jessie Pis with RTC and they are both working perfectly

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sat Nov 07, 2015 8:56 pm

fruit-uk wrote:Those bug reports are quite old.

This link provides interesting reading https://bugs.debian.org/cgi-bin/bugrepo ... bug=764552 though I have no idea whether any of that affects your ubuntu install

I have two jessie Pis with RTC and they are both working perfectly
Yes, they might be old, however I need to capture and anayse what's going here, especially, from past day's reading on this subject, I like to go for the "Systemd" approach with the new release of UbuntuMATE... Have to deploy several RPi devices with this OS under the constraints of no Internet access.

Otherwise, other RPi devices I'm using with Debian are running fine, too. Thank you for the additional pointer, I'm reading through it right now...

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sat Nov 07, 2015 9:16 pm

carriba wrote:
fruit-uk wrote:I like to go for the "Systemd" approach with the new release of UbuntuMATE
same with raspbian jessie now.
I have had no problems with it so far but haven't delved into that area much.
Time will tell :)

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sun Nov 08, 2015 11:05 am

Just started up mi RPi device this morning, and executed the respective commands to query date and time, waited a couple of minutes and fired the same commands again, and here the output:

Code: Select all

root@ubox:~# date ; hwclock ; timedatectl
Sat Nov  7 21:22:19 CET 2015
Sat 07 Nov 2015 21:22:19 CET  .743926 seconds
      Local time: Sat 2015-11-07 21:22:19 CET
  Universal time: Sat 2015-11-07 20:22:19 UTC
        RTC time: Sat 2015-11-07 20:22:20
       Time zone: ... (CET, +0100)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no

root@ubox:~# date ; hwclock ; timedatectl
Sun Nov  8 12:01:20 CET 2015
Sat 07 Nov 2015 21:29:53 CET  .425264 seconds
      Local time: Sun 2015-11-08 12:01:21 CET
  Universal time: Sun 2015-11-08 11:01:21 UTC
        RTC time: Sat 2015-11-07 20:29:54
       Time zone: ... (CET, +0100)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no
When executing the "hwclock -w" command to write the system date & time back to the RTC chip, everything is again synchornised:

Code: Select all

root@ubox:~# hwclock -w
root@ubox:~# date ; hwclock ; timedatectl
Sun Nov  8 12:06:32 CET 2015
Sun 08 Nov 2015 12:06:32 CET  .510336 seconds
      Local time: Sun 2015-11-08 12:06:33 CET
  Universal time: Sun 2015-11-08 11:06:33 UTC
        RTC time: Sun 2015-11-08 11:06:33
       Time zone: ... (CET, +0100)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sun Nov 08, 2015 11:19 am

Do you have a Pi with jessie on? Or at least an SD or even USB stick that you can write a raspbian jessie install to.

If so it might be worth comparing the files involved with hwclock, RTC to try and spot any differences in the way that ubuntu does it.

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sun Nov 08, 2015 11:44 am

Have disabled and deinstalled the "fake-hwclock" startup init scripts, and am getting after a reboot the following results:

Code: Select all

root@ubox:~# date ; hwclock ; timedatectl
Thu Jan  1 01:00:51 CET 1970
hwclock.bin: The Hardware Clock registers contain values that are either invalid (e.g. 50th day of the month) or beyond the range we can handle (e.g. Year 2095).
      Local time: Thu 1970-01-01 01:00:51 CET
  Universal time: Thu 1970-01-01 00:00:51 UTC
        RTC time: Tue 1965-07-20 06:36:28
       Time zone: ... (CET, +0100)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no
And then wait a little while until the system date and time gets synchronised with NTP, and fire the same set of commands yielding to the following output:

Code: Select all

root@ubox:~# date ; hwclock ; timedatectl
Sun Nov  8 12:39:22 CET 2015
hwclock.bin: The Hardware Clock registers contain values that are either invalid (e.g. 50th day of the month) or beyond the range we can handle (e.g. Year 2095).
      Local time: Sun 2015-11-08 12:39:23 CET
  Universal time: Sun 2015-11-08 11:39:23 UTC
        RTC time: Tue 1965-07-20 06:36:28
       Time zone: ... (CET, +0100)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no
Then writing back the system date and time to the RTC chip, firing the same set of commands, and am getting the following results:

Code: Select all

root@ubox:~# hwclock -w
root@ubox:~# date ; hwclock ; timedatectl
Sun Nov  8 12:41:34 CET 2015
Sun 08 Nov 2015 12:41:33 CET  .796009 seconds
      Local time: Sun 2015-11-08 12:41:34 CET
  Universal time: Sun 2015-11-08 11:41:34 UTC
        RTC time: Sun 2015-11-08 11:41:34
       Time zone: ... (CET, +0100)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no
Will now go ahead and check with Debian Jessie...

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sun Nov 08, 2015 12:06 pm

carriba wrote:Have disabled and deinstalled the "fake-hwclock" startup init scripts
You should be able to do the same with

Code: Select all

systemctl disable fake-hwclock
:)
I think running fake-hwclock is your problem. From a debian page
Some machines don't have a working realtime clock (RTC) unit, or no driver for the hardware that does exist. fake-hwclock is a simple set of scripts to save the kernel's current clock periodically (including at shutdown) and restore it at boot so that the system clock keeps at least close to realtime. This will stop some of the problems that may be caused by a system believing it has travelled in time back to 1970, such as needing to perform filesystem checks at every boot.
In short is is restoring system time to last shutdown time.

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sun Nov 08, 2015 1:53 pm

OK, so here is the situation when using Debian Jessie. I've dowloaded the latest image form the Raspberry Foundation site, image with date September 2015, and flashed it on an SD card.

I have modified the "boot.txt" file to include at the and of the file a line with "dtoverlay=i2c-rtc,ds3231", and no further changes.

Starting up the RPi device with the Debian Jessie OS, and after a successfull login. I'm getting the following:

Code: Select all

login as: pi
pi@192.168.0.12's password:

Last login: Thu Sep 24 15:32:58 2015
pi@raspberrypi ~ $ sudo su -

root@raspberrypi:~# uname -a
Linux raspberrypi 4.1.7-v7+ #817 SMP PREEMPT Sat Sep 19 15:32:00 BST 2015 armv7l GNU/Linux

root@raspberrypi:~# date ; hwclock ; timedatectl
Sun  8 Nov 12:25:20 UTC 2015
Thu 24 Sep 2015 15:35:39 UTC  -0.598538 seconds
      Local time: Sun 2015-11-08 12:25:21 UTC
  Universal time: Sun 2015-11-08 12:25:21 UTC
        RTC time: Thu 2015-09-24 15:34:39
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
root@raspberrypi:~#
root@raspberrypi:~# cat /etc/fake-hwclock.data
2015-09-24 15:32:47

root@raspberrypi:/etc# hwclock -w
root@raspberrypi:/etc# date ; hwclock ; timedatectl
Sun  8 Nov 12:29:11 UTC 2015
Sun 08 Nov 2015 12:29:11 UTC  -0.224082 seconds
      Local time: Sun 2015-11-08 12:29:11 UTC
  Universal time: Sun 2015-11-08 12:29:11 UTC
        RTC time: Sun 2015-11-08 12:29:11
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

root@raspberrypi:/etc# date ; hwclock ; timedatectl
Sun  8 Nov 12:38:01 UTC 2015
Sun 08 Nov 2015 12:38:02 UTC  -0.989121 seconds
      Local time: Sun 2015-11-08 12:38:02 UTC
  Universal time: Sun 2015-11-08 12:38:02 UTC
        RTC time: Sun 2015-11-08 12:38:02
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
Then, I went further and disabled the "fake-hwclock" daemon (using "systemctl disable fake-hwclock") and deinstalled the entire package with "apt-get remove fake-hwclock". I made sure that there is no link under the "/etc/rc?.d/" directories potentially pointing to "/etc/init.d/fake-hwclock" which I have deleted as well.

Thus, the RTC chip has and keeps its current time after the last sync with the NTP source, and there's definetly no "fake-hwclock" package installed.

Shutting down the RPi device to its halt state, unplug the device from power for a couple of minutes. Than after a while, power it up again, I'm getting the following results:

Code: Select all

login as: pi
pi@192.168.0.12's password:

Last login: Thu Jan  1 00:00:12 1970
pi@raspberrypi ~ $ sudo su -
root@raspberrypi:~# date ; hwclock ; timedatectl
Sun  8 Nov 13:01:16 UTC 2015
hwclock: The Hardware Clock registers contain values that are either invalid (e.g. 50th day of month) or beyond the range we can handle (e.g. Year 2095).
      Local time: Sun 2015-11-08 13:01:17 UTC
  Universal time: Sun 2015-11-08 13:01:17 UTC
        RTC time: Tue 1965-07-20 06:36:28
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

root@raspberrypi:~# date ; hwclock ; timedatectl
Sun  8 Nov 13:06:48 UTC 2015
hwclock: The Hardware Clock registers contain values that are either invalid (e.g. 50th day of month) or beyond the range we can handle (e.g. Year 2095).
      Local time: Sun 2015-11-08 13:06:49 UTC
  Universal time: Sun 2015-11-08 13:06:49 UTC
        RTC time: Tue 1965-07-20 06:36:28
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

root@raspberrypi:~# hwclock -w
root@raspberrypi:~# date ; hwclock ; timedatectl
Sun  8 Nov 13:07:12 UTC 2015
Sun 08 Nov 2015 13:07:12 UTC  -0.356924 seconds
      Local time: Sun 2015-11-08 13:07:12 UTC
  Universal time: Sun 2015-11-08 13:07:12 UTC
        RTC time: Sun 2015-11-08 13:07:12
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

root@raspberrypi:~# date ; hwclock ; timedatectl
Sun  8 Nov 13:10:11 UTC 2015
Sun 08 Nov 2015 13:10:11 UTC  -0.020294 seconds
      Local time: Sun 2015-11-08 13:10:11 UTC
  Universal time: Sun 2015-11-08 13:10:11 UTC
        RTC time: Sun 2015-11-08 13:10:11
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
I repeated the shutdown to a system halt, power off and on a couple of times, and the results are reproducable under Debbian Jessie, sic!

For me it looks like that something is resetting the RTC chip during the boot up time independent of the existance of the "fake-hwclock" or not. Check out yourself on above transcripts performed...

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sun Nov 08, 2015 2:11 pm

You have missed a bit for jessie. You need to comment out these lines

Code: Select all

if [ -e /run/systemd/system ] ; then
    exit 0
fi
in /lib/udev/hwclock-set

As you are not running ntp you may need to comment out these two lines too

Code: Select all

/sbin/hwclock --rtc=$dev --systz --badyear
/sbin/hwclock --rtc=$dev --systz
in the same file.
I am not sure on the last bit, mine are working fine with them in, but both have RTCs and run ntp

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Sun Nov 08, 2015 4:44 pm

Thank you for the feedback. I went ahead and have modified the file "/lib/udev/hwclock-set" towards the following contents:

Code: Select all

root@raspberrypi:~# cat /lib/udev/hwclock-set
#!/bin/sh
dev=$1
#if [ -e /run/systemd/system ] ; then
#    exit 0
#fi
if [ -e /run/udev/hwclock-set ]; then
    exit 0
fi
if [ -f /etc/default/rcS ] ; then
    . /etc/default/rcS
fi
# These defaults are user-overridable in /etc/default/hwclock
BADYEAR=no
HWCLOCKACCESS=yes
HWCLOCKPARS=
HCTOSYS_DEVICE=rtc0
if [ -f /etc/default/hwclock ] ; then
    . /etc/default/hwclock
fi
if [ yes = "$BADYEAR" ] ; then
#    /sbin/hwclock --rtc=$dev --systz --badyear
    /sbin/hwclock --rtc=$dev --hctosys --badyear
else
#    /sbin/hwclock --rtc=$dev --systz
    /sbin/hwclock --rtc=$dev --hctosys
fi
# Note 'touch' may not be available in initramfs
> /run/udev/hwclock-set
...and this may indeed have solved the problem :D

Above commented lines do write back the system date and time to the RTC chip, and then reads it out again. However system date and time might be wrong just after the boot up process !!

A login immediately after the reboot shows the following (and this time correct) output:

Code: Select all

root@raspberrypi:~# date ; hwclock ; timedatectl
Sun  8 Nov 16:40:41 UTC 2015
Sun 08 Nov 2015 16:40:41 UTC  -0.262643 seconds
      Local time: Sun 2015-11-08 16:40:41 UTC
  Universal time: Sun 2015-11-08 16:40:41 UTC
        RTC time: Sun 2015-11-08 16:40:41
       Time zone: Etc/UTC (UTC, +0000)
     NTP enabled: no
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
I will now go ahead and check out the startup configuration files with UbuntuMATE...

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Mon Nov 09, 2015 9:23 am

OK, I went ahead and have applied the same changes on the UbuntuMATE 15.10 distribution as described in my previous posting.

When having the "hake-hwclock" daemon running during startup, I'm getting the following results below displaying yesterday's date and time and then waiting a litlle bit, the systems' date and time gets synchronised with NTP, and apparently the RTC chip updated, too:

Code: Select all

login as: user
user@ubox.local's password:
Welcome to Ubuntu 15.10 (GNU/Linux 4.1.10-v7+ armv7l)
Last login: Sun Nov  8 23:09:12 2015
user@ubox:~$ sudo su -
[sudo] password for user:
root@ubox:/sbin# uname -a
Linux ubox 4.1.10-v7+ #821 SMP PREEMPT Sat Oct 10 00:16:28 BST 2015 armv7l armv7l armv7l GNU/Linux
root@ubox:~# date ; hwclock ; timedatectl
Sun Nov  8 23:18:40 CET 2015
Sun 08 Nov 2015 23:18:40 CET  .252887 seconds
      Local time: Sun 2015-11-08 23:18:41 CET
  Universal time: Sun 2015-11-08 22:18:41 UTC
        RTC time: Sun 2015-11-08 22:18:41
       Time zone: ... (CET, +0100)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no

root@ubox:~# date ; hwclock ; timedatectl
Mon Nov  9 09:10:24 CET 2015
Mon 09 Nov 2015 09:10:24 CET  .577058 seconds
      Local time: Mon 2015-11-09 09:10:24 CET
  Universal time: Mon 2015-11-09 08:10:24 UTC
        RTC time: Mon 2015-11-09 08:10:25
       Time zone: ... (CET, +0100)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no
Deactivating and deinstalling the "fake-hwclock" daemon completely, I'm getting the following results:

Code: Select all

login as: user
user@ubox.local's password:
Welcome to Ubuntu 15.10 (GNU/Linux 4.1.10-v7+ armv7l)
Last login: Thu Jan  1 01:00:32 1970 from 192.168.0.20
user@ubox:~$ sudo su -
[sudo] password for user:
root@ubox:~# date ; hwclock ; timedatectl
Thu Jan  1 01:00:46 CET 1970
hwclock: The Hardware Clock registers contain values that are either invalid (e. g. 50th day of month) or beyond the range we can handle (e.g. Year 2095).
      Local time: Thu 1970-01-01 01:00:46 CET
  Universal time: Thu 1970-01-01 00:00:46 UTC
        RTC time: Tue 1965-07-20 06:36:28
       Time zone: Europe/Monaco (CET, +0100)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no

root@ubox:~# date ; hwclock ; timedatectl
Mon Nov  9 09:22:40 CET 2015
hwclock: The Hardware Clock registers contain values that are either invalid (e.g. 50th day of month) or beyond the range we can handle (e.g. Year 2095).
      Local time: Mon 2015-11-09 09:22:41 CET
  Universal time: Mon 2015-11-09 08:22:41 UTC
        RTC time: Tue 1965-07-20 06:36:28
       Time zone: ... (CET, +0100)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no

root@ubox:~# hwclock -w
root@ubox:~# date ; hwclock ; timedatectl
Mon Nov  9 09:23:15 CET 2015
Mon 09 Nov 2015 09:23:15 CET  .266866 seconds
      Local time: Mon 2015-11-09 09:23:16 CET
  Universal time: Mon 2015-11-09 08:23:16 UTC
        RTC time: Mon 2015-11-09 08:23:16
       Time zone: ... (CET, +0100)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no
Concluding, there must be another program running during the bootup process that writes back the system date and time to the RTC chip, and incorrectly overwriting the correct date and time stored in the RTC chip.

I wnet even further and have commented out everything in the "/lib/udev/hwclock-set" script as outlined with:

Code: Select all

#!/bin/sh
dev=$1
#if [ -e /run/systemd/system ] ; then
#    exit 0
#fi
#if [ -e /run/udev/hwclock-set ]; then
#    exit 0
#fi
if [ -f /etc/default/rcS ] ; then
    . /etc/default/rcS
fi
# These defaults are user-overridable in /etc/default/hwclock
BADYEAR=no
HWCLOCKACCESS=yes
HWCLOCKPARS=
HCTOSYS_DEVICE=rtc0
if [ -f /etc/default/hwclock ] ; then
    . /etc/default/hwclock
fi
if [ yes = "$BADYEAR" ] ; then
#    /sbin/hwclock --rtc=$dev --systz --badyear
#    /sbin/hwclock --rtc=$dev --hctosys --badyear
else
#    /sbin/hwclock --rtc=$dev --systz
#    /sbin/hwclock --rtc=$dev --hctosys
fi
# Note 'touch' may not be available in initramfs
> /run/udev/hwclock-set
However even there, still the same results, and still the same sitation, sic!
For comparison, here the contents of the "/boot/cmdline.txt" file for
  • Debian Jessie: dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
  • UbuntuMATE: dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 elevator=deadline rootwait logo.nologo
Thus, I need to dig further through some other files that may erroneously update the system date and time to the RTC chip during the boot up process...

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Mon Nov 09, 2015 9:44 am

Interesting!
I am sure you need to get rid of fake-hwclock for good. It's only a work around for systems with no RTC. If it works it will set system time to last shutdown, possibly overwriting your RTC.

My feeling is that at least one of

Code: Select all

if [ -e /run/systemd/system ] ; then
    exit 0
fi
if [ -e /run/udev/hwclock-set ]; then
    exit 0
fi
is needed. You've tried without the systemd section, try leaving that in and comenting the other.

Is there anything in syslog about setting hwclock or RTC during shutdown?

Failing that you could do a system wide search for hwclock or hwclock-set but it may take a while ;)

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Mon Nov 09, 2015 11:36 am

Yes, have commented everything in the "/lib/udev/hwclock-set" script to see whether there's anything else writing the RTC chip.

During the sutdown I have found the following entries in the "/var/log/syslog" file:

Code: Select all

Nov  9 09:23:30 ubox systemd[1]: Stopped target Sound Card.
Nov  9 09:23:30 ubox systemd[1]: Stopping Authenticate and Authorize Users to Run Privileged Tasks...
Nov  9 09:23:30 ubox systemd[1]: Stopping TLP system startup/shutdown...
Nov  9 09:23:30 ubox systemd[1]: Stopped Stop ureadahead data collection 45s after completed startup.
Nov  9 09:23:30 ubox systemd[1]: Stopped target Timers.
Nov  9 09:23:30 ubox systemd[1]: Stopped Daily Cleanup of Temporary Directories.
Nov  9 09:23:30 ubox systemd[1]: Stopping Time & Date Service...
Nov  9 09:23:30 ubox systemd[1]: Stopped Setup Virtual Console.
Nov  9 09:23:30 ubox systemd[1]: Stopping User Manager for UID 1000...
Nov  9 09:23:30 ubox systemd[717]: Reached target Shutdown.
Nov  9 09:23:30 ubox systemd[717]: Starting Exit the Session...
Nov  9 09:23:30 ubox systemd[717]: Stopped target Default.
Nov  9 09:23:30 ubox systemd[717]: Stopped target Basic System.
Nov  9 09:23:30 ubox systemd[717]: Stopped target Sockets.
Nov  9 09:23:30 ubox systemd[717]: Stopped target Timers.
Nov  9 09:23:30 ubox systemd[717]: Stopped target Paths.
Nov  9 09:23:30 ubox systemd[1]: Stopping Session c1 of user "user".
Nov  9 09:23:30 ubox systemd[1]: Starting Unattended Upgrades Shutdown...
Nov  9 09:23:30 ubox systemd[1]: Removed slice system-systemd\x2dfsck.slice.
Nov  9 09:23:30 ubox systemd[717]: Received SIGRTMIN+24 from PID 1057 (kill).
Nov  9 09:23:30 ubox tlp[1052]: Error: TLP power save is disabled. Set TLP_ENABLE=1 in /etc/default/tlp.
Nov  9 09:23:30 ubox systemd[1]: Stopped Authenticate and Authorize Users to Run Privileged Tasks.
Nov  9 09:23:30 ubox systemd[1]: Stopped Time & Date Service.
Nov  9 09:23:30 ubox systemd[1]: Started Store Sound Card State.
Nov  9 09:23:30 ubox systemd[1]: tlp.service: Control process exited, code=exited status=1
Nov  9 09:23:30 ubox systemd[1]: Stopped TLP system startup/shutdown.
Nov  9 09:23:30 ubox systemd[1]: tlp.service: Unit entered failed state.
Nov  9 09:23:30 ubox systemd[1]: tlp.service: Failed with result 'exit-code'.
Nov  9 09:23:31 ubox systemd[1]: Stopped User Manager for UID 1000.
Nov  9 09:23:31 ubox systemd[1]: Stopped Session c1 of user manuel.
Nov  9 09:23:31 ubox systemd[1]: Removed slice user-1000.slice.
Nov  9 09:23:31 ubox systemd[1]: Stopped target Multi-User System.
And then during the startup, I have found the following entries:

Code: Select all

Jan  1 01:00:34 ubox systemd[707]: Startup finished in 131ms.
Jan  1 01:00:34 ubox systemd[1]: Started User Manager for UID 1000.
Jan  1 01:00:48 ubox rsyslogd-2007: action 'action 10' suspended, next retry is Thu Jan  1 01:01:18 1970 [v8.12.0 try http://www.rsyslog.com/e/2007 ]
Jan  1 01:00:53 ubox dbus[353]: [system] Activating via systemd: service name='org.freedesktop.timedate1' unit='dbus-org.freedesktop.timedate1.service'
Jan  1 01:00:53 ubox systemd[1]: Starting Time & Date Service...
Jan  1 01:00:53 ubox dbus[353]: [system] Successfully activated service 'org.freedesktop.timedate1'
Jan  1 01:00:53 ubox systemd[1]: Started Time & Date Service.
Jan  1 01:00:54 ubox systemd[1]: Starting Stop ureadahead data collection...
Jan  1 01:00:54 ubox systemd[1]: Stopped Read required files in advance.
Jan  1 01:00:54 ubox systemd[1]: Started Stop ureadahead data collection.
Nov  9 11:55:52 ubox systemd[707]: Time has been changed
Nov  9 11:55:52 ubox rsyslogd-2007: action 'action 10' suspended, next retry is Mon Nov  9 11:56:22 2015 [v8.12.0 try http://www.rsyslog.com/e/2007 ]
Nov  9 11:55:52 ubox systemd[1]: Time has been changed
Thus, I need to see whether there's any other "Systemd" service definition file under either the "/lib/systemd/system" directory or any other diretory that I might have missed until now...
Last edited by carriba on Tue Nov 10, 2015 4:51 pm, edited 1 time in total.

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Mon Nov 09, 2015 5:24 pm

I have found a big error in my earlier suggestions after looking at one of my jessie Pis

It still has fake-hwclock installed (as well as hwclock). Removing it causes the boot logs to have a 1-Jan-1970 timestamp until corrected
...and don't understand at all why removing it messes things up

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Mon Nov 09, 2015 5:37 pm

That's why I normally still keep and like to keep "fake-hwclock" installed so that I do not get the 1 Jan 1970 time stamp in my boot up process logs.

Now reading further through the "Systemd" documentation, the entire boot up process being run in a "initramfs" until all FS on the SD card are mounted properly.

So, somewhere in the "Systemd" init chain I need to find the right state where the "/dev" is being mounted and the device file "/dev/rtc0" is being created. Then, I can read the date & time form the RTC chip and initialise the OS kernel with the right date & time.

Browsing through the "/lib/systemd/system" services files I've found at least 2 files that handle the date and time synchronisation and a good starting point is with https://wiki.gentoo.org/wiki/Systemd that I'm following right now...

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Mon Nov 09, 2015 6:24 pm

It's complicated - probably because it's so new

The Description field from the systemd script appears as the syslog entry so that may help you track things down

I'm getting more and more confused!

User avatar
carriba
Posts: 181
Joined: Tue Nov 18, 2014 5:55 pm
Contact: ICQ

Re: UbuntuMATE 15.10 keeps the time of last shutdown in RTC

Tue Nov 10, 2015 12:55 pm

I see it in the same way, I can update and configure all the "Systemd" services, however not sure yet how the mechanism is with the "Systemd" startup of services and if and why it is indeed overwriting the RTC chip with the system date and time known during the bootup process.

I have created a post in the "UbuntuMATE-RPi 2 B" forum to look into this further. Feel free to consult the exchanges under the URL "https://ubuntu-mate.community/t/ubuntum ... ootup/2750".

I will post an update, once I get it resolved and/or have further news on this...

Return to “Other”