How to change default hwclock on BBB Debian to always be /dev/rtc1?

3,153 views
Skip to first unread message

Robert Hurd

unread,
Jan 10, 2016, 11:35:09 AM1/10/16
to BeagleBoard
I've added an external battery backup real time clock (Adafruit's Chronodot) via I2C to my BBB. I've successfully managed to add it as a module in Debian 8.2 using Adafruit guide, and it is now accessible via hwclock using the override command hwclock -r -f /dev/rtc1.

Reading around the web it states that the system time, synced with NTP, can automatically write the current system time every 11 minutes to the hwclock. The default hwclock is /dev/rtc0 which isn't backed up with a battery. Is it possible to change the default hwclock to always be /dev/rtc1? Or will hwclock automatically update both /dev/rtc0 and /dev/rtc1 with the system time?

Thank you for your time.  

William Hermans

unread,
Jan 10, 2016, 1:46:56 PM1/10/16
to beagl...@googlegroups.com
http://man7.org/linux/man-pages/man8/hwclock.8.html

-f, --rtc=filename Override hwclock's default rtc device file name. Otherwise it will use the first one found in this order: /dev/rtc /dev/rtc0 /dev/misc/rtc For IA-64: /dev/efirtc /dev/misc/efirtc

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Hurd

unread,
Jan 10, 2016, 2:24:03 PM1/10/16
to BeagleBoard
HI WIlliam,

Thank you for getting back to my post, really appreciate your time.
However, your solution is the same approach as I mentioned my initial post (hwclock -r -f /dev/rtc1). This doesn't actually set the default rtc source, it only overrides the default for the command. I need an approach that permanently sets hwclock to /dev/rtc1 automatically all of the time, i.e. after reboot etc. Thus executing the command hwclock should always default to /dev/rtc1 and not rtc0.

I think however I may have found the answer to my own questions thanks to a post talking about OpenRC https://wiki.gentoo.org/wiki/System_time
I haven't tested it yet, but it looks promising.

root:# cd /etc/init.d/
root: /etc/init.d# nano hwclock.sh

In the hwclock.sh script is the following line that looks to be setting the default hardware clock to rtc0.

HCTOSYS_DEVICE=rtc0

Thus, I bet if I change it to =rtc1 then I should be away.

I will post back with my results. 

Robert Hurd

unread,
Jan 10, 2016, 2:32:15 PM1/10/16
to BeagleBoard
Actually, on reflection there's another file that should be edited and not the one I posted above.

root:# nano /etc/default/hwclock

William Hermans

unread,
Jan 10, 2016, 6:05:07 PM1/10/16
to beagl...@googlegroups.com
HI WIlliam,

Thank you for getting back to my post, really appreciate your time.
However, your solution is the same approach as I mentioned my initial post (hwclock -r -f /dev/rtc1).

Yeah, I did not realize until after I posted. I figured it would require "hacking" the kernel(otherwise), but looks like you've found something that will work better for you.

On Sun, Jan 10, 2016 at 12:32 PM, Robert Hurd <rob...@roberthurd.com> wrote:
Actually, on reflection there's another file that should be edited and not the one I posted above.

root:# nano /etc/default/hwclock

--

William Hermans

unread,
Jan 10, 2016, 6:07:25 PM1/10/16
to beagl...@googlegroups.com
Additionally, I know there is a package called "fake-hwclock" which simulates an rtc for those systems that do not have. One, so was going to suggest perhaps looking over the code. But seems largely  moot now.

Robert Hurd

unread,
Jan 12, 2016, 6:57:25 PM1/12/16
to BeagleBoard
To get back to this thread, it seems that editing the default HCTOSYS_DEVICE field in /etc/default/hwclock won't work in my situation. I'm assuming because the RTC1 (DS3231) is loaded via a script when Debian boots the hwclock has already loaded and defaulted to RTC0 because RTC1 is yet to be loaded.

This isn't really too much on an issue though. Using Adafruit's guide for creating a script to load the RTC (DS3231) I am able to set the system time and default hwclock RTC0 on bootup. Likewise I have made a similar script that runs when Debain shuts down, reboots and halts to set the DS3231 RTC to the system time. This allows the system to sync with an NTP server if available and update the external RTC.

maxmike

unread,
Oct 9, 2016, 3:39:21 PM10/9/16
to BeagleBoard

Robert, when using rtc0, did you also use .../i2c-adapter/i2c-0... ?

Micka

unread,
Oct 9, 2016, 4:44:47 PM10/9/16
to BeagleBoard

I also had to change the default rtc... I managed it by recompiling the kernel. In the menu config you can specify the default rtc....


Le dim. 9 oct. 2016 21:39, maxmike <maxmi...@gmail.com> a écrit :

Robert, when using rtc0, did you also use .../i2c-adapter/i2c-0... ?

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.

maxmike

unread,
Oct 9, 2016, 6:21:30 PM10/9/16
to BeagleBoard

I don~t think Robert recompiled the kernel. I am using 3.8.13 Debian.

William Hermans

unread,
Oct 9, 2016, 9:54:43 PM10/9/16
to beagl...@googlegroups.com
The best way I found for myself. Was to simply install ntpdate, run it, then update the external real clock from system time. Then, if you *absolutely* need rtc0 updated. You update it from the system time. Or rtc1. No need to recompile the kernel.

Sure, it's a couple of extra steps, but steps that can be done at boot with a simple script / service. Then if you need, or want to update the real time clock. Since time on computer can drift. You run a cron job every X time frame to run a script that pulls in system time from an atomic clock, then re-apply to rtc1.

On Sun, Oct 9, 2016 at 3:21 PM, maxmike <maxmi...@gmail.com> wrote:

I don~t think Robert recompiled the kernel. I am using 3.8.13 Debian.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/4e6fdc99-4137-4c04-8c1d-72fa9de5a6a4%40googlegroups.com.

Micka

unread,
Jan 4, 2017, 7:51:50 AM1/4/17
to beagl...@googlegroups.com
The problem have been discussed there :

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=785445


Le lun. 10 oct. 2016 à 03:54, William Hermans <yyr...@gmail.com> a écrit :
The best way I found for myself. Was to simply install ntpdate, run it, then update the external real clock from system time. Then, if you *absolutely* need rtc0 updated. You update it from the system time. Or rtc1. No need to recompile the kernel.

Sure, it's a couple of extra steps, but steps that can be done at boot with a simple script / service. Then if you need, or want to update the real time clock. Since time on computer can drift. You run a cron job every X time frame to run a script that pulls in system time from an atomic clock, then re-apply to rtc1.
On Sun, Oct 9, 2016 at 3:21 PM, maxmike <maxmi...@gmail.com> wrote:

I don~t think Robert recompiled the kernel. I am using 3.8.13 Debian.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/CALHSORqDsbBWiO%2BJOUPuaeAsG1O%2B4dxiP6G3PqUkOxE1GeVhgA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages