RTC misbehaving [Resolved]

Post Reply
User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

RTC misbehaving [Resolved]

Post by jaym » Sat Dec 17, 2016 11:55 pm

My C2 is running meveric's minimal Jessie64 OS, headless, and it includes HK's PCF8563 RTC Module, configured per the instructions here: http://odroid.com/dokuwiki/doku.php?id=en:pcf8563rtc

I am able to read, write, and sync the RTC reliably using the hwclock commands, but when I reboot the C2, the RTC always reports 00:00 1 Jan 1970 when /etc/rc.local starts up. (I have added a hwclock -r to the beginning of rc.local, just before the hwclock -s step). As a result, when the hwclock -s executes, the system time gets set to 00:00 1 Jan 1970, only reverting to the correct time once the ntp daemon gets around to a time check, usually a few minutes later.

I have confirmed that if I set the RTC to the proper time via hwclock -w, it does not lose this time if I unplug it from the C2, wait a while, and re-connect it. The battery is doing its job.

I have also confirmed that if I set the RTC to the current time, shut down the C2, and then remove the RTC, I can reconnect the RTC after the C2 has been rebooted, and the RTC will continue to show the current time.

However, if I connect the RTC and then boot the C2, the RTC gets reset to zero (ie, 00:00 1 Jan 1970) at some point during the boot process. How do I find what process is doing this? The RTC is useless if something resets it before rc.local can use it to set the system clock.

(I switched to Ubuntu MATE and repeated the testing, with the same result.)
Last edited by jaym on Sun Jan 29, 2017 11:43 pm, edited 1 time in total.

User avatar
odroid
Site Admin
Posts: 34109
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 666 times
Been thanked: 611 times
Contact:

Re: RTC misbehaving

Post by odroid » Sun Dec 18, 2016 11:27 am

You might need to disable the NTP service.
It probably resets the RTC if the NTP sync fails or too slow.
http://odroid.com/dokuwiki/doku.php?id= ... tp_service

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by jaym » Mon Dec 19, 2016 9:53 pm

Thanks for your reply. Yes, removing NTP stopped the RTC reset. Rather than just remove it, I installed chrony, an NTP alternative, and the installation process removes the NTP package. The RTC is no longer reset during boot, and hwclock -s (in /etc/rc.local) successfully syncs the system clock to the RTC about 22 seconds into the boot process. (Dec 31 19:00 is Jan 01 00:00 UTC translated to Eastern Standard Time in the US)

Code: Select all

Dec 31 19:00:22 localhost rc.local[335]: RTC = Mon 19 Dec 2016 06:54:24 AM EST  -0.987140 seconds
Dec 19 06:54:25 localhost systemd[1]: Time has been changed
Dec 19 06:54:25 localhost chronyd[356]: Forward time jump detected!
Dec 19 06:54:26 localhost rc.local[335]: SYS clock = Mon Dec 19 06:54:26 EST 2016
There are 1325 lines of "Dec 31" in the syslog before the time gets corrected via rc.local.

Is there a way to make the kernel sync with the RTC earlier in the boot process?

User avatar
rooted
Posts: 7600
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 658 times
Been thanked: 174 times
Contact:

Re: RTC misbehaving

Post by rooted » Tue Dec 20, 2016 2:17 am

If the RTC driver is built into the kernel (*) RTC works properly and sets the time early in the boot process, if built as a module (m) it gets loaded too late and doesn't always function properly.

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by jaym » Tue Dec 20, 2016 6:56 am

Thanks, rooted. After lots of testing over the past couple days, I can emphatically agree with "doesn't always function properly."

Guess it's time I learned how to hack the kernel.

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by jaym » Sat Dec 24, 2016 5:10 am

Took me a while to figure out how to create a custom kernel, but moving the RTC driver (and i2c driver) into the kernel did the trick. Log entries in messages and syslog always have 'real' timestamps now -- no more Jan 01 00:00 entries. And there was no need for modifications to /etc/rc.local. Syncing the RTC and system clock happen automagically, in both directions.

Thanks to odriod and rooted for the help.

User avatar
rooted
Posts: 7600
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 658 times
Been thanked: 174 times
Contact:

Re: RTC misbehaving

Post by rooted » Sat Dec 24, 2016 7:41 am

Thanks for reporting back that it worked.

@odroid
RTC won't generally work correctly when built as a module, perhaps it should be built in from now on?

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by jaym » Sat Dec 24, 2016 7:52 am

I actually did think about asking meveric to add it to the kernel (since I'm using his distro), but figured I wouldn't learn much via that approach.

Since HK sells the RTC, I agree that it makes sense that their kernel should support it. And since they actually know how to build kernels, it should be a lot easier for them to add it than it was for me. :-)

User avatar
odroid
Site Admin
Posts: 34109
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 666 times
Been thanked: 611 times
Contact:

Re: RTC misbehaving

Post by odroid » Sat Dec 24, 2016 1:07 pm

We can make the RTC driver built in.
But the I2C driver also should be built in.
In that case, those two SDA/SCL pins can't be used as a GPIO.
Is there any other negative side effect?

User avatar
rooted
Posts: 7600
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 658 times
Been thanked: 174 times
Contact:

Re: RTC misbehaving

Post by rooted » Sat Dec 24, 2016 1:26 pm

odroid wrote:We can make the RTC driver built in.
But the I2C driver also should be built in.
In that case, those two SDA/SCL pins can't be used as a GPIO.
Is there any other negative side effect?
I think if the modules were loaded from initramfs RTC would work as intended, although I haven't tested this theory.

User avatar
meveric
Posts: 11002
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2, H2 (J4105), GoA, C4
Has thanked: 37 times
Been thanked: 337 times
Contact:

Re: RTC misbehaving

Post by meveric » Thu Dec 29, 2016 5:39 am

I've just tried this today.
I added both aml_i2c and rtc_pcf8563 to initramfs.
I can't find any issue. NTP and hwclock running side by side and I don't see any issues at all.

In fact I can't seem to trigger any clock that is not set correctly.
Even if I remove all cable for several minutes (still having the RTC plugged in) and boot the system up again.
The first log entry in syslog already has the correct timestamp, even without calling hwclock -s it seems.
The system has no network connection what so ever, or better it only has WLAN which takes about 1~2 minutes after boot until it found and connected to my hidden network.
So as long as I have the RTC plugged into the ODROID I always have the correct time.

I can do hwclock -s/-r/-w without issues even with having NTP installed and activated.

=====================================

I did another test, once again after turning the device off, I unplugged all cables and waited 10 minutes.
After I bootet up, once again I was presented with a time right of the RTC, the first entry in the syslog already had a time.
BUT, I got several messages: rtc-pcf8563 1-0051: low voltage detected, date/time is not reliable.
And the time was off about 5minutes. Checking hwclock -r it showed the wrong time.
Shortly after the network connected to my WLAN NTP updated my clock to the correct time, and hwclock -r still reports the wrong time (about 5min behind).
hwclock did adjust itself after a longer periode of time (10~20min).

It looks like a failure of the battery, but that way it's kinda proven that hwclock is working correctly, since even the wrong clock from the RTC is correctly set upon boot, and gets later synct with correct time of NTP.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
odroid
Site Admin
Posts: 34109
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 666 times
Been thanked: 611 times
Contact:

Re: RTC misbehaving

Post by odroid » Thu Dec 29, 2016 11:16 am

Thank you for the valuable test.

Is it easy to insert/remove the modules into/from initramfs ?
Can you give us an instruction to generate/update the initramfs on Ubunut & Debian?

Because many other people want to keep using the two pins as normal GPIOs instead of I2C, we need to let them know.


BTW, please measure the voltage of the coin battery if you have a DMM.

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by jaym » Sat Dec 31, 2016 2:28 am

Regarding the 'low voltage detected' message, during my testing I saw this message if, while the C2 was powered-off, I removed the battery momentarily and then reinserted it before booting the C2. It seems this clock chip notices if battery power is interrupted, and tells you about it later. So 'low voltage detected' doesn't necessarily mean that it is low right now, but has been low some time in the past, while the clock was running on the battery.

I would also be interested in instructions for adding the two drivers to initramfs.

ABo
Posts: 14
Joined: Thu Oct 06, 2016 11:34 pm
languages_spoken: german english
ODROIDs: ODROID-C2
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by ABo » Sun Jan 01, 2017 12:00 am

moin...
i did everything as the wiki told me (months ago)...
i even removed NTP (where i actually don't see any reason - but i did).
for sure: RTC is keeping the time! :-)
BUT on every reboot/start-up i have to hwclock -s manually via terminal :-(
this is quite useless...
and it is quite boring to 'fdtput -t s /media/boot/meson64_odroidc2.dtb /i2c@c1108500/pcf8563@51 status "okay"' and rebooting on every kernel-update :-(
which info do you need for solving the prob¿
thank you in advance & greetinx

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by jaym » Mon Jan 02, 2017 3:10 am

The problem you describe sounds just like the behavior I was seeing. As suggested by rooted, above, building the RTC and i2c drivers into the kernel fixes this problem. I have not used hwclock at all since making this change. Meveric has since demonstrated that building these drivers into initramfs also solves the problem.

There have been no kernel updates since I built these drivers into my kernel, so I cannot yet speak to how much work will be required to restore RTC function after the update.

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by jaym » Tue Jan 03, 2017 12:29 am

Meveric,

This morning I tried your setup-odroid script's rtc_support option on a fresh install of Jesse64, upgraded to 3.14.79+. The script appeared to complete without error, and I rebooted at the end. A check of syslog shows that the log entries have the Jan 01 00:00 timestamps until well into the boot process, essentially the same behavior I saw when I started this thread on 17 Dec. And yes, this was done on Jan 02 :-)

So I started over, repeating the process: flashing the image, update/upgrade/dist-upgrade, rebooting, and then running the rtc_support option from setup-odroid script. No errors, warnings, or other miscues, and yet, after the reboot, syslog is still showing Jan 01 until near the end of the boot process.

So on my headless C2, at least, it appears that the initramfs method does not yield the same results as building the drivers into the kernel.

Any suggestions for further investigation?

User avatar
meveric
Posts: 11002
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2, H2 (J4105), GoA, C4
Has thanked: 37 times
Been thanked: 337 times
Contact:

Re: RTC misbehaving

Post by meveric » Sun Jan 08, 2017 12:41 am

odroid wrote:Thank you for the valuable test.

Is it easy to insert/remove the modules into/from initramfs ?
Can you give us an instruction to generate/update the initramfs on Ubunut & Debian?
Sorry I missed the answers here since I normally am not in the "Hardware and peripherals" section of the forums :(
Anyway yes it's rather easy. You have to put the modules into /etc/initramfs-tools/modules same as you would in /etc/modules.
After that you have to completely rebuild initrd.img and uInitrd in order to make it work.
odroid wrote:BTW, please measure the voltage of the coin battery if you have a DMM.
Sadly I don't. One of the reasons why I'm not in this part of the forum, I lack the tools (and probably the skills) to make things happen.

btw. If there's any further discussion, please let me know via PM, or else I might miss it again.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
meveric
Posts: 11002
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2, H2 (J4105), GoA, C4
Has thanked: 37 times
Been thanked: 337 times
Contact:

Re: RTC misbehaving

Post by meveric » Sun Jan 08, 2017 1:11 am

jaym wrote:So on my headless C2, at least, it appears that the initramfs method does not yield the same results as building the drivers into the kernel.

Any suggestions for further investigation?
Hmm hard to tell, I'll do some more tests myself.
I kinda wonder why it was working for me. Pretty much on the first try.

Can you post output of:

Code: Select all

cat /etc/rc.local
cat /etc/initramfs-tools/modules
cat /etc/kernel/postinst.d/rtc
Currently doing a new test.
4:49 pm (CET) I turned off the ODROID C2, unplugged Power, HDMI, and even RTC module.
5:06 pm (CET) plugged everything back in and turned the device back on. Time shows correctly 5:07 pm (CET) after booting without internet

checking syslog:

Code: Select all

Jan  7 16:47:52 localhost systemd[1]: Stopped Enable support for additional executable binary formats.
Jan  7 16:47:52 localhost systemd[687]: Starting Exit the Session...
Jan  7 16:47:52 localhost systemd[1]: Stopping Network Manager...
Jan  7 16:47:52 localhost systemd[1]: Stopping Login Prompts.
Jan  7 16:47:53 localhost systemd[1]: Stopped target Login Prompts.
Jan  7 16:47:53 localhost systemd[1]: Stopping Getty on tty1...
Jan  7 16:47:53 localhost systemd[1]: Stopping Serial Getty on ttyS0...
Jan  7 16:47:53 localhost systemd[1]: Stopping LSB: Starts LIRC daemon....
Jan  7 16:47:53 localhost systemd[687]: Received SIGRTMIN+24 from PID 9182 (kill).
Jan  7 16:47:53 localhost rsyslogd: [origin software="rsyslogd" swVersion="8.4.2" x-pid="605" x-info="http://www.rsyslog.com"] exiting on signal 15.
Jan  7 17:07:02 localhost systemd-modules-load[226]: Failed to find module 'lp'
Jan  7 17:07:02 localhost systemd-modules-load[226]: Failed to find module 'ppdev'
Jan  7 17:07:02 localhost systemd-modules-load[226]: Failed to find module 'parport_pc'
Jan  7 17:07:02 localhost rsyslogd: [origin software="rsyslogd" swVersion="8.4.2" x-pid="601" x-info="http://www.rsyslog.com"] start
Jan  7 17:07:02 localhost kernel: [    0.000000] Initializing cgroup subsys cpuset
Jan  7 17:07:02 localhost kernel: [    0.000000] Initializing cgroup subsys cpu
Jan  7 17:07:02 localhost kernel: [    0.000000] Initializing cgroup subsys cpuacct
Jan  7 17:07:02 localhost kernel: [    0.000000] Linux version 3.14.79+ (root@odroid-jessie64) (gcc version 4.9.2 (Debian/Linaro 4.9.2-10) ) #1 SMP PREEMPT Thu Dec 15 13:09:19 CET 2016
Jan  7 17:07:02 localhost kernel: [    0.000000] CPU: AArch64 Processor [410fd034] revision 4
Jan  7 17:07:02 localhost kernel: [    0.000000] secmon: share mem setup
Jan  7 17:07:02 localhost kernel: [    0.000000] Reserved memory: initialized node linux,secmon, compatible id aml_secmon_memory
Jan  7 17:07:02 localhost kernel: [    0.000000] __reserved_mem_alloc_size: linux,meson-fb
Jan  7 17:07:02 localhost kernel: [    0.000000] fb: Reserved memory: created fb at 0x0000000078000000, size 128 MiB
Jan  7 17:07:02 localhost kernel: [    0.000000] Reserved memory: initialized node linux,meson-fb, compatible id amlogic, fb-memory
Jan  7 17:07:02 localhost kernel: [    0.000000] __reserved_mem_alloc_size: linux,di
Jan  7 17:07:02 localhost kernel: [    0.000000] DI reserved memory: created CMA memory pool at 0x0000000076200000, size 30 MiB
Jan  7 17:07:02 localhost kernel: [    0.000000] Reserved memory: initialized node linux,di, compatible id amlogic, di-mem
Jan  7 17:07:02 localhost kernel: [    0.000000] __reserved_mem_alloc_size: linux,ion-dev
Jan  7 17:07:02 localhost kernel: [    0.000000] ppmgr share mem setup
Jan  7 17:07:02 localhost kernel: [    0.000000] linux,ion-dev add multi user:ffffffc001ca9438
Jan  7 17:07:02 localhost kernel: [    0.000000] Reserved memory: initialized node linux,ion-dev, compatible id amlogic, idev-mem
Jan  7 17:07:02 localhost kernel: [    0.000000] __reserved_mem_alloc_size: linux,codec_mm_cma
Jan  7 17:07:02 localhost kernel: [    0.000000] Reserved memory: created CMA memory pool at 0x0000000067c00000, size 188 MiB
Jan  7 17:07:02 localhost kernel: [    0.000000] Reserved memory: initialized node linux,codec_mm_cma, compatible id shared-dma-pool
Jan  7 17:07:02 localhost kernel: [    0.000000] __reserved_mem_alloc_size: linux,picdec
Jan  7 17:07:02 localhost kernel: [    0.000000] Reserved memory: created CMA memory pool at 0x0000000064c00000, size 48 MiB
Jan  7 17:07:02 localhost kernel: [    0.000000] Reserved memory: initialized node linux,picdec, compatible id shared-dma-pool
Jan  7 17:07:02 localhost kernel: [    0.000000] __reserved_mem_alloc_size: linux,codec_mm_reserved
Jan  7 17:07:02 localhost kernel: [    0.000000] codec_mm:vdec: reserved mem setup
Jan  7 17:07:02 localhost kernel: [    0.000000] Reserved memory: initialized node linux,codec_mm_reserved, compatible id amlogic, codec-mm-reserved
Jan  7 17:07:02 localhost kernel: [    0.000000] cma: Reserved 8 MiB at 60000000
Jan  7 17:07:02 localhost kernel: [    0.000000] On node 0 totalpages: 486912
Jan  7 17:07:02 localhost kernel: [    0.000000]   Normal zone: 8568 pages used for memmap
Jan  7 17:07:02 localhost kernel: [    0.000000]   Normal zone: 0 pages reserved
Jan  7 17:07:02 localhost kernel: [    0.000000]   Normal zone: 486912 pages, LIFO batch:31
Jan  7 17:07:02 localhost kernel: [    0.000000] psci: probing function IDs from device-tree
Jan  7 17:07:02 localhost kernel: [    0.000000] PERCPU: Embedded 12 pages/cpu @ffffffc074195000 s19584 r8192 d21376 u49152
Jan  7 17:07:02 localhost kernel: [    0.000000] pcpu-alloc: s19584 r8192 d21376 u49152 alloc=12*4096
Jan  7 17:07:02 localhost kernel: [    0.000000] pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3
Jan  7 17:07:02 localhost kernel: [    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 478344
Jan  7 17:07:02 localhost kernel: [    0.000000] Kernel command line: coherent_pool=2M root=/dev/mapper/hdd-root rootwait ro consoleblank=0 console=ttyS0,115200n8 console=tty0 no_console_suspend hdmitx=cec0  hdmimode=1080p60hz m_bpp=24 v
out= fsck.repair=yes elevator=noop disablehpd=true  max_freq=1536 maxcpus=4 monitor_onoff=false net.ifnames=0
Jan  7 17:07:02 localhost kernel: [    0.000000] logo: get hdmimode: 1080p60hz
Jan  7 17:07:02 localhost kernel: [    0.000000] dvfs [get_max_freq] - max_freq : 1536000000
Jan  7 17:07:02 localhost kernel: [    0.000000] PID hash table entries: 4096 (order: 3, 32768 bytes)
Jan  7 17:07:02 localhost kernel: [    0.000000] Dentry cache hash table entries: 262144 (order: 9, 2097152 bytes)
Jan  7 17:07:02 localhost kernel: [    0.000000] Inode-cache hash table entries: 131072 (order: 8, 1048576 bytes)
Jan  7 17:07:02 localhost kernel: [    0.000000] Memory: 1503360K/1947648K available (7987K kernel code, 840K rwdata, 2904K rodata, 907K init, 4225K bss, 444288K reserved)
Jan  7 17:07:02 localhost kernel: [    0.000000] Virtual kernel memory layout:
Jan  7 17:07:02 localhost kernel: [    0.000000]     vmalloc : 0xffffff8000000000 - 0xffffff8040000000   (  1024 MB)
Jan  7 17:07:02 localhost kernel: [    0.000000]     vmemmap : 0xffffff8040010000 - 0xffffff80421d0000   (    33 MB)
Jan  7 17:07:02 localhost kernel: [    0.000000]     modules : 0xffffffbffc000000 - 0xffffffc000000000   (    64 MB)
Jan  7 17:07:02 localhost kernel: [    0.000000]     memory  : 0xffffffc000000000 - 0xffffffc078000000   (  1920 MB)
Jan  7 17:07:02 localhost kernel: [    0.000000]       .init : 0xffffffc001b24000 - 0xffffffc001c06c80   (   908 kB)
Jan  7 17:07:02 localhost kernel: [    0.000000]       .text : 0xffffffc001080000 - 0xffffffc001b23dc4   ( 10896 kB)
Jan  7 17:07:02 localhost kernel: [    0.000000]       .data : 0xffffffc001c07000 - 0xffffffc001cd92b0   (   841 kB)
Jan  7 17:07:02 localhost kernel: [    0.000000] SLUB: HWalign=64, Order=0-1, MinObjects=0, CPUs=4, Nodes=1
Jan  7 17:07:02 localhost kernel: [    0.000000] Preemptible hierarchical RCU implementation.
Jan  7 17:07:02 localhost kernel: [    0.000000] NR_IRQS:64 nr_irqs:64 0
Jan  7 17:07:02 localhost kernel: [    0.000005] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483648000ns
Jan  7 17:07:02 localhost kernel: [    0.000026] mclk->mux_reg =ffffff8000002990,mclk->reg =ffffff800000a994
Jan  7 17:07:02 localhost kernel: [    0.000072] local timer MESON TIMER-G mclk->mux_reg =ffffff8000002990,mclk->reg =ffffff800000c998
Jan  7 17:07:02 localhost kernel: [    0.000095] local timer MESON TIMER-H mclk->mux_reg =ffffff8000002990,mclk->reg =ffffff800000e99c
Jan  7 17:07:02 localhost kernel: [    0.000116] local timer MESON TIMER-I mclk->mux_reg =ffffff8000002990,mclk->reg =ffffff80000109a0
Jan  7 17:07:02 localhost kernel: [    0.000127] Switching to timer-based delay loop
judging by the output I don't think "hwclock -s" is actually needed at all.

Edit:
Next test:
5:18 pm (CET) turned off the device and removed RTC
After restart Time is at 1 Jan 01:00

So RTC seems to work correctly.

Next test:
disabled hwclock -s in /etc/rc.local
turned off the device.

5:26 pm (CET) completely unplugging Power, HDMI, RTC again.
-> switched to XU4 and watched an episode of Darkwing Duck :D
5:50 pm (CET) thinking about watching another episode ;)
5:51 pm (CET) booting up the ODROID with everything plugged back in.

-.- that didn't work out.. it seems the RTC couldn't hold the time cause even an manual hwclock -s did not recover the time.
Guess I have to check if I can find a new battery somewhere.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
rooted
Posts: 7600
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 658 times
Been thanked: 174 times
Contact:

Re: RTC misbehaving

Post by rooted » Sun Jan 08, 2017 1:59 am

It isn't, it's set through the kernel and the internal clock interface. No outside dependence (other than the RTC hardware of course).

Far as notifications, we need the @user forum plugin.

User avatar
meveric
Posts: 11002
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2, H2 (J4105), GoA, C4
Has thanked: 37 times
Been thanked: 337 times
Contact:

Re: RTC misbehaving

Post by meveric » Sun Jan 08, 2017 2:26 am

rooted wrote:It isn't, it's set through the kernel and the internal clock interface. No outside dependence (other than the RTC hardware of course).

Far as notifications, we need the @user forum plugin.
I just subscribed to the topic, that way I get mail notifications ;)
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
rooted
Posts: 7600
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 658 times
Been thanked: 174 times
Contact:

Re: RTC misbehaving

Post by rooted » Sun Jan 08, 2017 4:51 am

The RTC for my CarPC has been unplugged for about a month, I will boot it up and see that it's still correct.

User avatar
meveric
Posts: 11002
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2, H2 (J4105), GoA, C4
Has thanked: 37 times
Been thanked: 337 times
Contact:

Re: RTC misbehaving

Post by meveric » Sun Jan 08, 2017 5:38 am

similar as motherboards, these batteries should be able to keep the time for years.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
rooted
Posts: 7600
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 658 times
Been thanked: 174 times
Contact:

Re: RTC misbehaving

Post by rooted » Sun Jan 08, 2017 9:27 am

meveric wrote:similar as motherboards, these batteries should be able to keep the time for years.
So you're already sure the battery is going dead on yours, I thought you weren't 100% the fix is working.

User avatar
meveric
Posts: 11002
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2, H2 (J4105), GoA, C4
Has thanked: 37 times
Been thanked: 337 times
Contact:

Re: RTC misbehaving

Post by meveric » Sun Jan 08, 2017 9:37 am

rooted wrote:So you're already sure the battery is going dead on yours, I thought you weren't 100% the fix is working.
I'm not 100% sure, but I wonder why hwclock shows 01. Jan 1970 that should only happen if the data stored got lost and currently I don't know why else the data should get lost besides a dead battery.
All tests with only a short while of disconnect (10~15min) seemed to have worked correctly.
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by jaym » Sun Jan 08, 2017 10:53 pm

meveric & rooted, I appreciate your continuing to pursue this.

I created a fresh instance of Jesse64, updated it to 3.14.79+, connected via SSH and ran setup-odroid, selecting the RTC support option. After the reboot, I collected the information you requested:

Code: Select all

root@odroid-jessie64:~# cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.



##### RTC Module #####

hwclock -s

##### RTC Module End #####

exit 0

root@odroid-jessie64:~# cat /etc/initramfs-tools/modules
# List of modules that you want to include in your initramfs.
# They will be loaded at boot time in the order below.
#
# Syntax:  module_name [args ...]
#
# You must run update-initramfs(8) to effect this change.
#
# Examples:
#
# raid1
# sd_mod
aml_i2c
rtc_pcf8563

root@odroid-jessie64:~# cat /etc/kernel/postinst.d/rtc
#!/bin/sh
fdtput -t s /boot/meson64_odroidc2.dtb /i2c@c1108500/pcf8563@51 status "okay"
I continue to see Jan 01 entries in syslog, and executing hwclock -r after a reboot shows that the RTC is coming up zero (jan 01 00:00) on every boot.

It occurred to me that perhaps I was checking syslog, rebooting, checking syslog, etc, without waiting long enough for the kernel to write the system time to the RTC (via the 'eleven-minute-mode' discussed in the hwclock man page), so I used hwclock -w to force the sync (first line of syslog listing, below), and then rebooted. syslog showed that this one time, the RTC's time survived the reboot, and so syslog's first entry after the reboot had the correct time.

Code: Select all

Jan  7 22:37:22 localhost systemd[1]: Started Synchronise Hardware Clock to System Clock.
Jan  7 22:37:22 localhost systemd[1]: Stopping system-ifup.slice.
Jan  7 22:37:22 localhost systemd[1]: Removed slice system-ifup.slice.
Jan  7 22:37:22 localhost systemd[1]: Stopping Sound Card.
Jan  7 22:37:22 localhost systemd[1]: Stopped target Sound Card.
Jan  7 22:37:22 localhost systemd[1]: Stopping Graphical Interface.
Jan  7 22:37:22 localhost systemd[1]: Stopped target Graphical Interface.
Jan  7 22:37:22 localhost systemd[1]: Stopping Multi-User System.
Jan  7 22:37:22 localhost rsyslogd-2007: action 'action 17' suspended, next retry is Sat Jan  7 22:37:52 2017 [try http://www.rsyslog.com/e/2007 ]
Jan  7 22:37:22 localhost systemd[1]: Stopped target Multi-User System.
Jan  7 22:37:22 localhost systemd[1]: Stopping OpenBSD Secure Shell server...
Jan  7 22:37:22 localhost systemd[1]: Stopping Regular background program processing daemon...
Jan  7 22:37:22 localhost systemd[1]: Stopping Login Prompts.
Jan  7 22:37:22 localhost systemd[1]: Stopped target Login Prompts.
Jan  7 22:37:22 localhost systemd[1]: Stopping Getty on tty6...
Jan  7 22:37:22 localhost systemd[1]: Stopping Getty on tty5...
Jan  7 22:37:22 localhost systemd[1]: Stopping Getty on tty4...
Jan  7 22:37:22 localhost systemd[1]: Stopping Getty on tty3...
Jan  7 22:37:22 localhost systemd[1]: Stopping Getty on tty2...
Jan  7 22:37:22 localhost systemd[1]: Stopping Getty on tty1...
Jan  7 22:37:22 localhost systemd[1]: Stopping Serial Getty on ttyS0...
Jan  7 22:37:22 localhost systemd[1]: Stopping getty on tty2-tty6 if dbus and logind are not available...
Jan  7 22:37:22 localhost systemd[1]: Stopped getty on tty2-tty6 if dbus and logind are not available.
Jan  7 22:37:22 localhost systemd[1]: Stopping LSB: Set the CPU Frequency Scaling governor to "ondemand"...
Jan  7 22:37:22 localhost systemd[1]: Stopping LSB: Start NTP daemon...
Jan  7 22:37:22 localhost rsyslogd: [origin software="rsyslogd" swVersion="8.4.2" x-pid="363" x-info="http://www.rsyslog.com"] exiting on signal 15.


Jan  7 22:37:40 localhost kernel: [    0.000000] Initializing cgroup subsys cpuset
Jan  7 22:37:40 localhost kernel: [    0.000000] Initializing cgroup subsys cpu
Jan  7 22:37:40 localhost kernel: [    0.000000] Initializing cgroup subsys cpuacct
Jan  7 22:37:40 localhost kernel: [    0.000000] Linux version 3.14.79+ (root@odroid-jessie64) (gcc version 4.9.2 (Debian/Linaro 4.9.2-10) ) #1 SMP PREEMPT Thu Dec 15 13:09:19 CET 2016
Jan  7 22:37:40 localhost kernel: [    0.000000] CPU: AArch64 Processor [410fd034] revision 4
I have repeated this reboot process multiple times, but the one shown above is the only instance in which the RTC's time survived the reboot.

Pretty sure the problem is not hardware, because this C2+RTC works flawlessly when booted from a different microSD which has the drivers built into the kernel.

Continuing to test, more later...

User avatar
rooted
Posts: 7600
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 658 times
Been thanked: 174 times
Contact:

Re: RTC misbehaving

Post by rooted » Mon Jan 09, 2017 12:24 am

Does Jessie64 use initramfs? Is it loading the correct initramfs?

One is on /boot and one /media/boot

Also setting the time from RTC must be enabled in the kernel.

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by jaym » Mon Jan 09, 2017 1:42 am

There is no /media/boot directory in my instance of Jesse64. (Isn't that an Ubuntu thing?)

Code: Select all

root@odroid-jessie64:~# ls -Al /media
total 0
/boot looks like this:

Code: Select all

root@odroid-jessie64:~# ls -Alh /boot
total 27M
-rwxr-xr-x 1 root root 5.9K Jan  7 21:04 boot.ini
-rwxr-xr-x 1 root root 109K Dec 15 11:47 config-3.14.79+
-rwxr-xr-x 1 root root  13M Jan  7 21:03 Image
-rwxr-xr-x 1 root root 3.9M Jan  7 22:32 initrd.img-3.14.79+
-rwxr-xr-x 1 root root  29K Jan  7 22:32 meson64_odroidc2.dtb
-rwxr-xr-x 1 root root 2.8M Dec 15 12:49 System.map-3.14.79+
-rwxr-xr-x 1 root root 3.9M Jan  7 22:32 uInitrd
-rwxr-xr-x 1 root root 3.9M Jan  7 22:32 uInitrd-3.14.79+
How does one go about enabling "setting the time from RTC" in the kernel?

In my kernel that contains the RTC and i2c drivers, the RTC "just works". I didn't do anything to enable it.

User avatar
rooted
Posts: 7600
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 658 times
Been thanked: 174 times
Contact:

Re: RTC misbehaving

Post by rooted » Mon Jan 09, 2017 2:36 am

Then it's already enabled in the kernel else it wouldn't have work when you built the module in.

I wasn't sure about Debian 64 having /media/boot, being it doesn't it certainly isn't that. To make certain the modules are being loaded from initramfs try moving the two modules from /lib/modules/3.4.79+/etc..etc and reboot and check they are indeed loaded with lsmod.

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by jaym » Mon Jan 09, 2017 5:44 am

Took me a few minutes to track down the i2c module. The RTC module's location was a bit more obvious. I moved them both to a folder I created, /save_modules

Code: Select all

root@odroid-jessie64:~# mv /lib/modules/3.14.79+/kernel/drivers/rtc/rtc-pcf8563.ko /save_modules/
root@odroid-jessie64:~# mv /lib/modules/3.14.79+/kernel/drivers/amlogic/i2c/aml_i2c.ko /save_modules/
After the reboot:

Code: Select all

root@odroid-jessie64:~# lsmod
Module                  Size  Used by
spidev                  6475  0 
w1_gpio                 3761  0 
spi_gpio                6778  0 
spi_bitbang             4063  1 spi_gpio
wire                   25591  1 w1_gpio
gxbb_wdt                3443  0 
sx865x                  5179  0 
ipv6                  376052  18 
autofs4                28105  2 
rtc_pcf8563             3956  0 
aml_i2c                16711  0 
So it seems they are coming from initramfs.

User avatar
rooted
Posts: 7600
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Has thanked: 658 times
Been thanked: 174 times
Contact:

Re: RTC misbehaving

Post by rooted » Mon Jan 09, 2017 5:50 am

Okay so that lets us know using initramfs isn't reliable in all cases.

Thanks for testing .

schallee
Posts: 6
Joined: Fri Jan 27, 2017 8:56 am
languages_spoken: english
ODROIDs: C2 XUL4
Has thanked: 0
Been thanked: 1 time
Contact:

Re: RTC misbehaving

Post by schallee » Fri Jan 27, 2017 10:51 am

Hey all. I finally figured all of this out and since this thread is recent I'll reply to it. First how to make it work and then discussion of why:

First, create /etc/initramfs-tools/hooks/c2-rtc with the following content

Code: Select all


#!/bin/sh
PREREQ=""
prereqs()
{
        echo "$PREREQ"
}

case $1 in
        prereqs)
                prereqs
                exit 0
        ;;
esac

. /usr/share/initramfs-tools/hook-functions

manual_add_modules aml_i2c rtc_pcf8563

copy_exec /sbin/hwclock

Create the file /etc/initramfs-tools/scripts/init-premount/c2-rtc with the following content:

Code: Select all

#!/bin/sh
#
# initramfs-tools init-premount script to set time from rtc on the ODROID C2

PREREQ=""
prereqs()
{
        echo "$PREREQ"
}

case $1 in
        prereqs)
                prereqs
                exit 0
        ;;
esac

. /scripts/functions

log_begin_msg "Setting system time from C2 RTC"
if hwclock -s; then
        log_end_msg
else
        log_warning_msg "Unable to set system time from C2 RTC"
fi
Regenerate your initramfs. Replace KERNEL_VERSION with whatever kernel version you're using. 3.14.79-104 in my case.

Code: Select all

update-initramfs -uk KERNEL_VERSION
Make a uImage from your initramfs:

Code: Select all

mkimage -A arm64 -O linux -T ramdisk -a 0x0 -e 0x0 -n initrd.img-KERNEL_VERSION -d /boot/initrd.img-KERNEL_VERSION /root/uInitrd
Next you need to configure uboot to use your new initramfs. First, backup /media/boot/uInitrd in case something goes wrong:

Code: Select all

mv /media/boot/uInitrd /media/boot/uInitrd.bak
Then copy your new one over:

Code: Select all

cp /root/uInitrd /media/boot/uInitrd
Then reboot. In the text that flies by there should be:

Code: Select all

Setting system time from C2 RTC ... done.
Hopefully you're good to go with the RTC being used to initialize the system time before logging starts.

So. What is going on.

The kernel attempts to set the time to whatever RTC is compiled in as part of the boot process before the initramfs. If you have the i2c and rtc modules compiled into your kernel this is what happens. If you put those modules into /etc/initramfs-tools/modules then the modules are loaded after the kernel has tried to get the time from the RTC. This is why the results are different between compiled in and just loaded by the initramfs. With the initramfs loading the modules the time is still not set to the RTC until the /etc/rc.local hwclock -s line is run.

This all gets more confusing when different inits are used. Pre-systemd sysvinit scripts in debian based systems seemed to set the RTC just fine if the modules were loaded. systemd seems to just asume the kernel already did it. This seems to have caused significant confusion about modularized RTCs for everything from the C2 to beaglebones to raspberry pis changing from wheezy to jessie.This gets even worse because the issue doesn't show up on x86 as usually the standard cmos rtc drivers are compiled in by distros.

With the kernel not setting the time from the RTC because the drivers aren't compiled in and systemd not setting the time from the RTC because it assumes the kernel did it we have to do it ourselves after the kernel fails because it has no RTC drivers and before systemd assumes its already set. To do this we need to modify the initramfs to both load the modules and set the system time from the RTC. The above does this by adding a hook script (/etc/initramfs-tools/hooks/c2-rtc) to the initramfs-tools that causes the modules and hwclock to be included in the initramfs. The second script is run at initramfs time before the root filesystem is mounted (/etc/initramfs-tools/scripts/init-premount). This script just runs 'hwclock -s' as our requested modules are already loaded when it is run.

I've tested this on my C2 running the stock ubutu image with updates. This should work for a debian distro as well with the location of the uInitrd changed.

One caveat is that there is a fixrtc in the stock initramfs tools that attempts to set the system time to the last mount time for the root filesystem if there is a kernel command line option enabling it and the RTC returns something before build time (or is it mount time... I'd have to check again). initramfs-tools doesn't guarantee ordering so if both the above scripts and the fixrtc script is triggered you may have interesting results.

If the hardkernel folks are watching this I'd suggest creating a .deb in your repo that adds the above. Then folks with a RTC would just have to apt-get install it. Alternatively the above could be included in the default image but only activated if a kernel command line setting is added to the boot.ini.

Cheers
These users thanked the author schallee for the post:
Kahana82 (Thu Nov 07, 2019 12:24 am)

User avatar
meveric
Posts: 11002
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2, H2 (J4105), GoA, C4
Has thanked: 37 times
Been thanked: 337 times
Contact:

Re: RTC misbehaving

Post by meveric » Fri Jan 27, 2017 9:46 pm

Nice work, thanks I'm gonna try to see if I can reproduce the same outcome on my Debian Jessie images :)
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving

Post by jaym » Sat Jan 28, 2017 9:01 am

Hello, schallee. I followed your instructions on a fresh copy of meveric's Debian Jesse (updated to 3.14.79+). All seemed OK - no unexpected errors - but when I rebooted the C2, the RTC did not set the correct time. In fact, the RTC did not work at all:

From syslog:

Code: Select all

Jan  1 00:00:10 localhost kernel: [    3.733019] drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
(The Console showed the same message.)

I tried hwclock-r, which confirmed that the clock was not available:

Code: Select all

root@odroid-jessie64:~# hwclock -r
hwclock: Cannot access the Hardware Clock via any known method.

root@odroid-jessie64:~# hwclock --debug
hwclock from util-linux 2.25.2
hwclock: cannot open /dev/rtc: No such file or directory
No usable clock interface found.
hwclock: Cannot access the Hardware Clock via any known method.

UPDATE: Upon reflection, I realized that the RTC was failing because it had not yet been configured, so I ran meveric's setup-odroid script and chose the rtc_support option. After the necessary reboot, the C2's RTC is now working exactly as it should. :-) :-)

The combination of shallee's instructions, followed by meveric's setup-odroid: rtc_support has done the trick.

Thanks to all for unearthing a solution that does not require compiling a new kernel.


For the benefit of others who may give this a try, creating shallee's two scripts by copy & paste will cause problems, because forum formatting has changed the 'space' characters included in the text to "unicode non-breaking" spaces, which cause errors when the scripts are executed. Retype the scripts using conventional 'space' characters. (Credit for solving this problem goes to http://www.shellcheck.net.)

schallee
Posts: 6
Joined: Fri Jan 27, 2017 8:56 am
languages_spoken: english
ODROIDs: C2 XUL4
Has thanked: 0
Been thanked: 1 time
Contact:

Re: RTC misbehaving [Resolved]

Post by schallee » Mon Jan 30, 2017 4:45 am

Sorry. Yeah. I believe I forgot that the FDT stuff DOES need to be done as well as what I said. I'll update/edit when I have a chance and figure out how to do it (I don't do forums much...).

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving [Resolved]

Post by jaym » Mon Jan 30, 2017 8:37 am

Here's the relevant code from meveric's setup-odroid script. I hope it's helpful.

Code: Select all

rtc_support(){
	# activate required module on boot
	if [ `cat /etc/initramfs-tools/modules | grep -c aml_i2c` -lt 1 ]; then
		echo "aml_i2c" >> /etc/initramfs-tools/modules
		if [ `cat /etc/initramfs-tools/modules | grep -c rtc_pcf8563` -lt 1 ]; then
			echo "rtc_pcf8563" >> /etc/initramfs-tools/modules
			update-initramfs -d -k `uname -r`
			update-initramfs -c -k `uname -r`
			update-initramfs -u -k `uname -r`
		else
			update-initramfs -d -k `uname -r`
			update-initramfs -c -k `uname -r`
			update-initramfs -u -k `uname -r`
		fi
	elif [ `cat /etc/initramfs-tools/modules | grep -c rtc_pcf8563` -lt 1 ]; then
		echo "rtc_pcf8563" >> /etc/initramfs-tools/modules
		update-initramfs -d -k `uname -r`
		update-initramfs -c -k `uname -r`
		update-initramfs -u -k `uname -r`
	fi		
	# make sure device-tree-compiler is installed
	apt-get install -y device-tree-compiler
	# make sure this is done on each Kernel update
	if [ ! -f /etc/kernel/postinst.d/rtc ]; then
		echo '#!/bin/sh
fdtput -t s /boot/meson64_odroidc2.dtb /i2c@c1108500/pcf8563@51 status "okay"' > /etc/kernel/postinst.d/rtc
		chmod +x /etc/kernel/postinst.d/rtc
		# set option for current Kernel
		/etc/kernel/postinst.d/rtc
	fi
	# get time from RTC on boot
	[ `cat /etc/rc.local | grep 'hwclock -s' | wc -l` -lt 1 ] && sed -i "s/^exit 0/##### RTC Module #####\n\nhwclock -s\n\n##### RTC Module End #####\n\nexit 0/" /etc/rc.local
	msgbox "RTC Module activated"
	REBOOT=1
}

User avatar
meveric
Posts: 11002
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go, H2 (N4100), N2, H2 (J4105), GoA, C4
Has thanked: 37 times
Been thanked: 337 times
Contact:

Re: RTC misbehaving [Resolved]

Post by meveric » Wed Feb 08, 2017 1:01 am

I've updated my setup-odroid script to incorporate the suggested scripts, hopefully this works as intended, I sadly haven't had time to test it yet :(
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving [Resolved]

Post by jaym » Sun Feb 12, 2017 4:54 am

I tried the updated setup-odroid script on a fresh install of Jesse (3.14.79+). After the reboot, the RTC is not functional, with symptoms identical to a system without the necessary rtc and i2c drivers:

Code: Select all

root@odroid-jessie64:~# lsmod
Module                  Size  Used by
sg                     29764  0 
spidev                  6475  0 
w1_gpio                 3761  0 
spi_gpio                6778  0 
spi_bitbang             4063  1 spi_gpio
wire                   25591  1 w1_gpio
gxbb_wdt                3443  0 
meson_gpiomem           4024  0 
ipv6                  376052  24 
autofs4                28105  2
 
root@odroid-jessie64:~# hwclock -r
hwclock: Cannot access the Hardware Clock via any known method.
hwclock: Use the --debug option to see the details of our search for an access method.
I noticed that the uInitrd file was missing, so I added a step:

Code: Select all

mkimage -A arm64 -O linux -T ramdisk -a 0x0 -e 0x0 -n uInitrd -d /boot/initrd.img-`uname -r` /boot/uInitrd
This command ran without error, so I repeated the /etc/kernel/postinst.d/rtc and rebooted. The result was the same.

As a check on my sanity, I created a fresh microSD and repeated the process, this time following schallee's instructions manually and then running the old (Dec 2016) version of setup-odroid. After the reboot, the RTC worked as expected, the drivers were visible via lsmod, and hwclock functioned as it should.

Code: Select all

root@odroid-jessie64:~# lsmod
Module                  Size  Used by
sg                     29764  0 
w1_gpio                 3761  0 
spidev                  6475  0 
spi_gpio                6778  0 
spi_bitbang             4063  1 spi_gpio
wire                   25591  1 w1_gpio
gxbb_wdt                3443  0 
sx865x                  5179  0 
meson_gpiomem           4024  0 
ipv6                  376052  24 
autofs4                28105  2 
rtc_pcf8563             3956  0 
aml_i2c                16711  0 


root@odroid-jessie64:~# hwclock -r
Sat 11 Feb 2017 01:29:55 PM UTC  -0.973509 seconds
My third attempt consisted of the steps included in the latest setup-odroid, but I executed them manually, so I could do some data collection between the steps. Initially, everything worked as expected:

Code: Select all

lsinitramfs /boot/initrd.img-3.14.79+
confirmed that the two drivers were present in the initrd.img file, and mounting and examining the contents of uInitrd confirmed that the drivers were present there, too. But after a reboot, the RTC and hwclock do not work, and the drivers are not present in the lsmod listing, just as in my initial attempt.

I have more time than talent, so I'll keep at it, trying to figure out what's missing. Suggestions are welcome.

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving [Resolved]

Post by jaym » Wed Feb 15, 2017 9:05 pm

As I noted earlier, the most recent version of meveric's setup-odroid script was not working reliably to enable/disable the RTC module on my headless C2, which is running meveric's Jesse 64. Drawing heavily on the work of meveric and schallee, I have cobbled together an updated version of the rtc-support segment of the setup-odriod script. This code reliably enables and disables the RTC module on my C2. It requires the current (3.14.79-20170207-C2) update of Jesse 64.

Code: Select all

rtc_support(){

  if		[ ! -f /etc/initramfs-tools/hooks/c2-rtc ] || [ ! -f /etc/initramfs-tools/scripts/init-premount/c2-rtc ]; then

	echo "We are activating the RTC Module"
 
	cp /usr/local/share/setup-odroid/rtc/c2-rtc-hook /etc/initramfs-tools/hooks/c2-rtc
	cp /usr/local/share/setup-odroid/rtc/c2-rtc-script /etc/initramfs-tools/scripts/init-premount/c2-rtc
		
	echo "aml_i2c" >> /etc/initramfs-tools/modules
	echo "rtc_pcf8563" >> /etc/initramfs-tools/modules

	update-initramfs -d -k `uname -r`
	update-initramfs -c -k `uname -r`
	update-initramfs -u -k `uname -r`

	mkimage -A arm64 -O linux -T ramdisk -a 0x0 -e 0x0 -n uInitrd -d /boot/initrd.img-3.14.79+ /root/uInitrd

	mv /boot/uInitrd /boot/uInitrd.bak
	cp /root/uInitrd /boot/uInitrd

	# make sure device-tree-compiler is installed
	apt-get install -y device-tree-compiler

	# make sure this is done on each Kernel update
 		if [ ! -f /etc/kernel/postinst.d/rtc ]; then
			echo '#!/bin/sh
fdtput -t s /boot/meson64_odroidc2.dtb /i2c@c1108500/pcf8563@51 status "okay"' > /etc/kernel/postinst.d/rtc
			chmod +x /etc/kernel/postinst.d/rtc
		fi

	# set option for current Kernel
	/etc/kernel/postinst.d/rtc

	msgbox "RTC Module activated"


  else

	echo  "We are deactivating the RTC Module"

	rm /etc/initramfs-tools/scripts/init-premount/c2-rtc
	rm /etc/initramfs-tools/hooks/c2-rtc
	rm /etc/kernel/postinst.d/rtc

	#  strip out the rtc and i2c drivers from the module list

	FILE=/etc/initramfs-tools/modules
	TMPFILE=/var/tmp/scratch
	MOD1="aml_i2c"
	MOD2="rtc_pcf8563"

	cp $FILE $TMPFILE      # create a working copy 
	echo "" > $FILE        # clear the original
	cat $TMPFILE | grep -v $MOD1 | grep -v $MOD2 > $FILE
	rm $TMPFILE            # clean up

	#  create initramfs which does not contain the rtc and i2c drivers

	update-initramfs -d -k `uname -r`
	update-initramfs -c -k `uname -r`
	update-initramfs -u -k `uname -r`

	mkimage -A arm64 -O linux -T ramdisk -a 0x0 -e 0x0 -n uInitrd -d /boot/initrd.img-3.14.79+ /root/uInitrd

	mv /boot/uInitrd /boot/uInitrd.bak
	cp /root/uInitrd /boot/uInitrd

	msgbox "RTC Module deactivated"
  fi
	REBOOT=1
}

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving [Resolved]

Post by jaym » Wed Mar 22, 2017 8:48 am

Finally had a chance to test the changes to the rtc_support section of the setup-odroid script more thoroughly, and found that a correction is necessary:

I added the -t switch to the update-initramfs instructions, and the script now enables & disables the RTC correctly.

Code: Select all

rtc_support(){

  if      [ ! -f /etc/initramfs-tools/hooks/c2-rtc ] || [ ! -f /etc/initramfs-tools/scripts/init-premount/c2-rtc ]; then

   echo "We are activating the RTC Module"
 
   cp /usr/local/share/setup-odroid/rtc/c2-rtc-hook /etc/initramfs-tools/hooks/c2-rtc
   cp /usr/local/share/setup-odroid/rtc/c2-rtc-script /etc/initramfs-tools/scripts/init-premount/c2-rtc
      
   echo "aml_i2c" >> /etc/initramfs-tools/modules
   echo "rtc_pcf8563" >> /etc/initramfs-tools/modules

   update-initramfs -d -k `uname -r` -t
   update-initramfs -c -k `uname -r` -t
   update-initramfs -u -k `uname -r` -t

   mkimage -A arm64 -O linux -T ramdisk -a 0x0 -e 0x0 -n uInitrd -d /boot/initrd.img-3.14.79+ /root/uInitrd

   mv /boot/uInitrd /boot/uInitrd.bak
   cp /root/uInitrd /boot/uInitrd

   # make sure device-tree-compiler is installed
   apt-get install -y device-tree-compiler

   # make sure this is done on each Kernel update
       if [ ! -f /etc/kernel/postinst.d/rtc ]; then
         echo '#!/bin/sh
fdtput -t s /boot/meson64_odroidc2.dtb /i2c@c1108500/pcf8563@51 status "okay"' > /etc/kernel/postinst.d/rtc
         chmod +x /etc/kernel/postinst.d/rtc
      fi

   # set option for current Kernel
   /etc/kernel/postinst.d/rtc

   msgbox "RTC Module activated"


  else

   echo  "We are deactivating the RTC Module"

   rm /etc/initramfs-tools/scripts/init-premount/c2-rtc
   rm /etc/initramfs-tools/hooks/c2-rtc
   rm /etc/kernel/postinst.d/rtc

   #  strip out the rtc and i2c drivers from the module list

   FILE=/etc/initramfs-tools/modules
   TMPFILE=/var/tmp/scratch
   MOD1="aml_i2c"
   MOD2="rtc_pcf8563"

   cp $FILE $TMPFILE      # create a working copy 
   echo "" > $FILE        # clear the original
   cat $TMPFILE | grep -v $MOD1 | grep -v $MOD2 > $FILE
   rm $TMPFILE            # clean up

   #  create initramfs which does not contain the rtc and i2c drivers

   update-initramfs -d -k `uname -r` -t
   update-initramfs -c -k `uname -r` -t
   update-initramfs -u -k `uname -r` -t

   mkimage -A arm64 -O linux -T ramdisk -a 0x0 -e 0x0 -n uInitrd -d /boot/initrd.img-3.14.79+ /root/uInitrd

   mv /boot/uInitrd /boot/uInitrd.bak
   cp /root/uInitrd /boot/uInitrd

   msgbox "RTC Module deactivated"
  fi
   REBOOT=1
}

User avatar
jaym
Posts: 29
Joined: Sat Dec 17, 2016 11:53 pm
languages_spoken: english
ODROIDs: C2, HC1, H2
Location: VA, USA
Has thanked: 0
Been thanked: 0
Contact:

Re: RTC misbehaving [Resolved]

Post by jaym » Sat Mar 25, 2017 6:46 pm

One last tweak, removing the special case of the current version of meveric's Jesse (3.14.79+) and inserting the general case (`uname -r'), in the two mkimage statements:

Code: Select all

rtc_support(){

  if      [ ! -f /etc/initramfs-tools/hooks/c2-rtc ] || [ ! -f /etc/initramfs-tools/scripts/init-premount/c2-rtc ]; then

   echo "We are activating the RTC Module"
 
   cp /usr/local/share/setup-odroid/rtc/c2-rtc-hook /etc/initramfs-tools/hooks/c2-rtc
   cp /usr/local/share/setup-odroid/rtc/c2-rtc-script /etc/initramfs-tools/scripts/init-premount/c2-rtc
      
   echo "aml_i2c" >> /etc/initramfs-tools/modules
   echo "rtc_pcf8563" >> /etc/initramfs-tools/modules

   update-initramfs -d -k `uname -r` -t
   update-initramfs -c -k `uname -r` -t
   update-initramfs -u -k `uname -r` -t

   mkimage -A arm64 -O linux -T ramdisk -a 0x0 -e 0x0 -n uInitrd -d /boot/initrd.img-`uname -r` /root/uInitrd

   mv /boot/uInitrd /boot/uInitrd.bak
   cp /root/uInitrd /boot/uInitrd

   # make sure device-tree-compiler is installed
   apt-get install -y device-tree-compiler

   # make sure this is done on each Kernel update
       if [ ! -f /etc/kernel/postinst.d/rtc ]; then
         echo '#!/bin/sh
fdtput -t s /boot/meson64_odroidc2.dtb /i2c@c1108500/pcf8563@51 status "okay"' > /etc/kernel/postinst.d/rtc
         chmod +x /etc/kernel/postinst.d/rtc
      fi

   # set option for current Kernel
   /etc/kernel/postinst.d/rtc

   msgbox "RTC Module activated"


  else

   echo  "We are deactivating the RTC Module"

   rm /etc/initramfs-tools/scripts/init-premount/c2-rtc
   rm /etc/initramfs-tools/hooks/c2-rtc
   rm /etc/kernel/postinst.d/rtc

   #  strip out the rtc and i2c drivers from the module list

   FILE=/etc/initramfs-tools/modules
   TMPFILE=/var/tmp/scratch
   MOD1="aml_i2c"
   MOD2="rtc_pcf8563"

   cp $FILE $TMPFILE      # create a working copy 
   echo "" > $FILE        # clear the original
   cat $TMPFILE | grep -v $MOD1 | grep -v $MOD2 > $FILE
   rm $TMPFILE            # clean up

   #  create initramfs which does not contain the rtc and i2c drivers

   update-initramfs -d -k `uname -r` -t
   update-initramfs -c -k `uname -r` -t
   update-initramfs -u -k `uname -r` -t

   mkimage -A arm64 -O linux -T ramdisk -a 0x0 -e 0x0 -n uInitrd -d /boot/initrd.img-`uname -r` /root/uInitrd

   mv /boot/uInitrd /boot/uInitrd.bak
   cp /root/uInitrd /boot/uInitrd

   msgbox "RTC Module deactivated"
  fi
   REBOOT=1
}

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 3 guests