RTC not quite working. Use something besides systemd-timesyn

Ask questions about Arch Linux ARM. Please search before making a new topic.

RTC not quite working. Use something besides systemd-timesyn

Postby eponymous » Mon Mar 07, 2016 7:38 am

I have a Raspberry Pi 2 Model B plugged into another board that includes a DS1307 RTC (with battery backup) connected via i2c. I struggled a bit to get it "working," but both hwclock and timedatectl can now see the RTC.
The behavior I think I want is:
    1. RTC to set the system clock early in the boot process
    2. NTP connection to be established and used to update the system clock
    3. System clock periodically used to update the RTC
    3. System clock used to set the RTC right before shutdown

systemd-timesyncd only seems to be doing 2 and 3:

Immediately after booting up:
$this->bbcode_second_pass_code('', 'user@ospi ~ $ sudo timedatectl
Local time: Sun 2016-03-06 21:36:56 PST
Universal time: Mon 2016-03-07 05:36:56 UTC
RTC time: Mon 2016-02-22 14:42:16
Time zone: America/Los_Angeles (PST, -0800)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no
')

A few minutes later:
$this->bbcode_second_pass_code('', 'user@ospi ~ $ sudo timedatectl
Local time: Sun 2016-03-06 21:51:59 PST
Universal time: Mon 2016-03-07 05:51:59 UTC
RTC time: Mon 2016-03-07 05:51:59
Time zone: America/Los_Angeles (PST, -0800)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no
')

The initial RTC time of "Mon 2016-02-22 14:42:16" is suspiciously consistent boot to boot and also matches the time stamps I see with journalctl prior to:

$this->bbcode_second_pass_code('', '
Feb 22 06:40:27 ospi systemd[1]: Starting RPC bind service...
Feb 22 06:40:27 ospi systemd[1]: Started RPC bind service.
Feb 22 06:40:27 ospi rpc.statd[334]: Running as root. chown /var/lib/nfs to choose different user
Feb 22 06:40:28 ospi systemd[1]: Started NFS status monitor for NFSv2/3 locking..
Mar 06 21:35:08 ospi systemd[1]: Time has been changed
Mar 06 21:35:08 ospi systemd[1]: Mounted /mnt/nas/ospi.
Mar 06 21:35:08 ospi systemd[1]: Started Open Sprinkler (Unified) Raspberry Pi.
Mar 06 21:35:08 ospi systemd[1]: Reached target Multi-User System.
')

Somewhat suspicious:
$this->bbcode_second_pass_code('', '
Feb 22 06:40:16 ospi kernel: usbcore: registered new interface driver rtl8192cu
Feb 22 06:40:16 ospi kernel: bcm2835-rng 3f104000.rng: hwrng registered
Feb 22 06:40:16 ospi systemd[1]: Found device /dev/ttyAMA0.
Feb 22 06:40:17 ospi kernel: i2c i2c-1: Failed to register i2c client ds1307 at 0x68 (-16)
Feb 22 06:40:17 ospi kernel: gpiomem-bcm2835 3f200000.gpiomem: Initialised: Registers at 0x3f200000
Feb 22 06:40:17 ospi kernel: i2c i2c-1: Failed to register i2c client ds1307 at 0x68 (-16)
Feb 22 06:40:17 ospi kernel: rtc-ds1307 1-0068: rtc core: registered ds1307 as rtc0
Feb 22 06:40:17 ospi kernel: rtc-ds1307 1-0068: 56 bytes nvram
Feb 22 06:40:16 ospi systemd[1]: Listening on Load/Save RF Kill Switch Status /dev/rfkill Watch.
Feb 22 06:40:16 ospi systemd[1]: Reached target Sound Card.
')

Per this, I am creating the RTC device with
$this->bbcode_second_pass_code('', '
user@ospi /etc/udev/rules.d $ more /etc/udev/rules.d/99-i2c-rtc.rules
ACTION=="add", SUBSYSTEM=="i2c", ATTR{name}=="3f804000.i2c", ATTR{new_device}="ds1307 0x68"
')

With the network disconnected, the RTC time is correct, but the system clock is wrong:
$this->bbcode_second_pass_code('', '
Local time: Mon 2016-02-22 06:40:36 PST
Universal time: Mon 2016-02-22 14:40:36 UTC
RTC time: Mon 2016-03-07 07:04:10
Time zone: America/Los_Angeles (PST, -0800)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no
')

But if you wait about a minute, the system clock decides it's correct and overwrites the RTC:
$this->bbcode_second_pass_code('', ' Local time: Mon 2016-02-22 06:41:58 PST
Universal time: Mon 2016-02-22 14:41:58 UTC
RTC time: Mon 2016-02-22 14:41:58
Time zone: America/Los_Angeles (PST, -0800)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no
')

This makes me think that the system clock is what "wants" to be set to 2016-02-22, that the RTC is set from the system clock early in the boot (if there's a network connection), the system clock is then corrected by NTP (if NTP is available), and the RTC is eventually set to system time. But how to fix it?
Do I need to move away from systemd-timesyncd? To what? Is the RTC misconfigured?
eponymous
 
Posts: 4
Joined: Mon Mar 07, 2016 7:32 am

Re: RTC not quite working. Use something besides systemd-tim

Postby WarheadsSE » Mon Mar 07, 2016 3:24 pm

Does this system have a fakeclock installed?
Core Developer
Remember: Arch Linux ARM is entirely community donation supported!
WarheadsSE
Developer
 
Posts: 6807
Joined: Mon Oct 18, 2010 2:12 pm

Re: RTC not quite working. Use something besides systemd-tim

Postby eponymous » Tue Mar 08, 2016 3:33 am

I don't think so. I don't think I've installed one and I can't find one anywhere.

$this->bbcode_second_pass_code('', '
$ sudo pacman --query fake-hwclock
error: package 'fake-hwclock' was not found
')

$this->bbcode_second_pass_code('', '
$ sudo grep -rl 'fake' /usr/lib/systemd/*
/usr/lib/systemd/systemd-export
/usr/lib/systemd/systemd-import
/usr/lib/systemd/systemd-journald
/usr/lib/systemd/systemd-machined
/usr/lib/systemd/systemd-pull
$ sudo grep -rl 'fake' /etc/systemd/system/*
')

Is there anywhere else you'd like me to check?
eponymous
 
Posts: 4
Joined: Mon Mar 07, 2016 7:32 am

Re: RTC not quite working. Use something besides systemd-tim

Postby banirne » Fri Mar 18, 2016 11:37 am

Same here: System start time is always Feb 22 15:40:25 and is changed by NTP later during boot. Du to the wrong start time fsck always corrects /dev/md0: Superblock last write time.

What can I do to fix this?
banirne
 
Posts: 5
Joined: Fri Mar 18, 2016 11:33 am

Re: RTC not quite working. Use something besides systemd-tim

Postby WarheadsSE » Fri Mar 18, 2016 2:19 pm

Consider adding in fakeclock, as this is meant for systems without fully integrated RTC's. It will save your time on shutdown, so that when the system boots, it will have that time as opposed to the date of your installation tarball.
Core Developer
Remember: Arch Linux ARM is entirely community donation supported!
WarheadsSE
Developer
 
Posts: 6807
Joined: Mon Oct 18, 2010 2:12 pm

Re: RTC not quite working. Use something besides systemd-tim

Postby eponymous » Fri Mar 18, 2016 4:10 pm

What do you mean by "fully integrated?" If a hardware clock is installed why is the fake clock package necessary?
eponymous
 
Posts: 4
Joined: Mon Mar 07, 2016 7:32 am

Re: RTC not quite working. Use something besides systemd-tim

Postby banirne » Fri Mar 18, 2016 8:52 pm

After installing fake-hwclock time is set early during boot. Thanks!
banirne
 
Posts: 5
Joined: Fri Mar 18, 2016 11:33 am

Re: RTC not quite working. Use something besides systemd-tim

Postby banirne » Sat Mar 19, 2016 5:31 pm

Digging a bit deeper it looks like an Arch Kernel problem. With Debian and bodis Kernel 4.4 the onboard RTC works as expected:

$this->bbcode_second_pass_code('', '
[ 2.250325] rtc-pcf8563 0-0051: chip found, driver version 0.4.4
[ 2.262201] rtc-pcf8563 0-0051: rtc core: registered rtc-pcf8563 as rtc0
[ 2.320275] rtc-pcf8563 0-0051: setting system clock to 2016-03-19 16:21:25 UTC (1458404485)
')
banirne
 
Posts: 5
Joined: Fri Mar 18, 2016 11:33 am

Re: RTC not quite working. Use something besides systemd-tim

Postby WarheadsSE » Sun Mar 20, 2016 7:21 pm

Please check the kernel configs for differences in relation to this module
Core Developer
Remember: Arch Linux ARM is entirely community donation supported!
WarheadsSE
Developer
 
Posts: 6807
Joined: Mon Oct 18, 2010 2:12 pm

Re: RTC not quite working. Use something besides systemd-tim

Postby banirne » Sun Mar 20, 2016 10:59 pm

Bodhi kernel conf:
$this->bbcode_second_pass_code('', '
CONFIG_I2C_MV64XXX=y
CONFIG_RTC_DRV_PCF8563=y
')

Arch conf uses "m" instead of "y"
banirne
 
Posts: 5
Joined: Fri Mar 18, 2016 11:33 am

Next

Return to User Questions

Who is online

Users browsing this forum: No registered users and 18 guests