Bosse_B
Posts: 966
Joined: Thu Jan 30, 2014 9:53 am

RTC DS3231 on line, what do I do with fake-hwclock?

Thu Jan 30, 2020 10:30 pm

I have added a board to my RPi4B running Raspbian Buster, which contains an RTC circuit (DS3231 + battery).
I have added the following line to the end of /boot/config.txt:

Code: Select all

dtoverlay=i2c-rtc,ds3231
Then rebooted the RPi4.
Using this command I found that linux uses my RTC chip:

Code: Select all

pi@rpi4-gui:~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
... removed ...
60: 60 -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
On this page you are advised to remove fake-hwclock:

Code: Select all

sudo apt-get -y remove fake-hwclock
sudo update-rc.d -f fake-hwclock remove
Then also:

Code: Select all

sudo nano /lib/udev/hwclock-set
# Comment out these lines:
if [ -e /run/systemd/system ] ; then
  exit 0
fi
But I am hesitant to do this because if I remove the add-on board and start my RPi4 I will not have any time at all until the network comes on-line, right?
I would rather have fake-hwclock available as a fall-back.
Is that possible?
What happens if I do not remove fake-hwclock?
Bo Berglund
Sweden

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

Re: RTC DS3231 on line, what do I do with fake-hwclock?

Thu Jan 30, 2020 10:53 pm

fake-hwclock in incompatible with an RTC. fake-hwclock will try to set the clock during boot up to the value stored at shutdown. If you have an RTC it should be the only thing that sets the clock until the system is connected to the internet (and timesyncd can get a value).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Bosse_B
Posts: 966
Joined: Thu Jan 30, 2014 9:53 am

Re: RTC DS3231 on line, what do I do with fake-hwclock?

Fri Jan 31, 2020 9:50 am

So that means I should uninstall fake-hwclock then?
Does this not pose a problem if the RTC (which is sitting on an add-on board on the GPIO pin header) is later removed...
Is there not a way to make fake-hwclock execution on startup depend on a failed detection of the hardware RTC?
Something like (pseudocode):

Code: Select all

if not detect_RTC then "fake-hwclock -w";
I guess that somewhere hidden in amongst the start scripts is a place where fake-hwclock is called to set the time?
Maybe /lib/udev/hwclock-set even though I do not see how that works (not very fluent in shellscripting).

If it is also regularly called to save the current time into a file used on startup, this does not really matter as long as it won't interfere with the time setting on startup...
Seems like removing fake-hwclock is asking for trouble down the line.
Bo Berglund
Sweden

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

Re: RTC DS3231 on line, what do I do with fake-hwclock?

Fri Jan 31, 2020 12:08 pm

Just blow fake-hwclock off the face of the planet. Reboot then keep calm and carry on.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Bosse_B
Posts: 966
Joined: Thu Jan 30, 2014 9:53 am

Re: RTC DS3231 on line, what do I do with fake-hwclock?

Fri Jan 31, 2020 12:55 pm

OK!
Just a final question:
How can I make the date command in terminal display a sensible ISO formatted string?
Right now I am getting this junk:

Code: Select all

$ date
Fri 31 Jan 2020 01:49:45 PM CET
I would very much prefer the ISO standard display like:
2020-01-31 13:49:45

I have tried a lot of things and the only way seems to be to use this complex command:

Code: Select all

$ date "+%F %T"
2020-01-31 13:53:03
Seems like the system only allows totally unreadable date and time displays...
Can I set the default for date to use the specifiers I managed to dig up?
Bo Berglund
Sweden

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

Re: RTC DS3231 on line, what do I do with fake-hwclock?

Fri Jan 31, 2020 1:09 pm

Code: Select all

pi@discovery:~ $ date
Fri 31 Jan 13:07:45 GMT 2020
pi@discovery:~ $ date -I
2020-01-31
pi@discovery:~ $ date -R
Fri, 31 Jan 2020 13:08:11 +0000
You can set an alias to change the defaults for the plain date command.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Bosse_B
Posts: 966
Joined: Thu Jan 30, 2014 9:53 am

Re: RTC DS3231 on line, what do I do with fake-hwclock?

Fri Jan 31, 2020 3:10 pm

DougieLawson wrote:
Fri Jan 31, 2020 1:09 pm
You can set an alias to change the defaults for the plain date command.
Thanks, that solved it for me! :)
Bo Berglund
Sweden

Return to “Raspberry Pi OS”