Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Raspberry Pi Boot2Qt - Real Time Clock (RTC) syncing on bootup
Dean_Wittmann last edited by
Per several internet articles, the following line in the config.txt file in the Boot2Qt boot partition should synchronize the hardware based DS3231 RTC to the Boot2Qt Yocto OS software based clock:
The examples on the internet focus specifically on the Raspbian OS and indicate that the fake-hwclock should be removed and disabled in order for this to work. However, the Boot2Qt Yocto OS does not contain the apt-get package manager to go through the steps provided in those internet examples.
Is there another way to remove and disable the fake-hwclock without rebuilding a Boot2Qt Yocto OS image?
In other words, what are the steps to either install apt-get (in order to follow the examples), or remove the fake-hwclock without installing apt-get. I'd like to do this with an existing and running Boot2Qt image for the Rasberry Pi provided by Qt, without having to build my own Boot2Qt image.
Dean_Wittmann last edited by
I've found the solution on my own:
The dtoverlay=i2c-rtc,ds3231 entry in the Boot2Qt boot partition enables a device tree overlay for the i2c interface real-time clock driver to have the abilities of the DS3231 RTC. This had nothing to do with synchronizing the RTC to the system clock or vice-versa.
Synchronization happens with the hwclock-set.sh script that is present in the Raspbian OS images but not the Qt built Boot2Qt Yocto OS images (installable with any particular Qt version).
To enable the synchronization, I've copied the hwclock-set.sh script from a Raspbian image into /etc/init.d/hwclock-set.sh in the Yocto running OS via WinSCP and changed its attributes to be executable. But, there are a couple of additional items to do:
Comment out the following lines:
#if [ -d /run/udev ] || [ -d /dev/.udev ]; then #return 0 #fi
because /run/udev will exist as a directory and therefore since the script exits with the return 0, your synchronization will not execute.
Don't forget to run this command to add hwclock-set.sh as a script to run at startup / shutdown, etc.:
update-rc.d hwclock-set.sh defaults
The hwclock-set.sh file makes use of the /lib/lsb/init-functions helper scripts, which also do not exist in the Boot2Qt Yocto image. So, do the same thing, copy from the Raspbian image:
No modifications are necessary for these files. Just make sure they have the execution attribute.
There are several files referenced within hwclock-set.sh which do not exists and they are useful to have for auto-adjustments of RTC time drift and selection between UTC / LOCAL time represented by the hardware clock. The filenames to copy or create are:
Here is the content of the /etc/default/hwclock file:
# Defaults for the hwclock init script. See hwclock(5) and hwclock(8). # This is used to specify that the hardware clock incapable of storing # years outside the range of 1994-1999. Set to yes if the hardware is # broken or no if working correctly. #BADYEAR=no # Set this to yes if it is possible to access the hardware clock, # or no if it is not. #HWCLOCKACCESS=yes # Set this to any options you might need to give to hwclock, such # as machine hardware clock type for Alphas. #HWCLOCKPARS= # Set this to the hardware clock device you want to use, it should # probably match the CONFIG_RTC_HCTOSYS_DEVICE kernel config option. #HCTOSYS_DEVICE=rtc0
As you can see, I didn't have to update anything in this file because all of these variables are already set correctly in the hwclock-set.sh file, and this file is just used to override those variables (if I want to in the future).
Here's another referenced file within the hwclock-set.sh script:
Here is the content that I put into this file:
You can read more about the purpose and content of this file here:
And the last referenced file within hwclock-set.sh is:
If you don't have this file, the hwclock-set.sh script will create it for you with the default content:
0.0 0 0.0 0 UTC
This file is used to adjust the hardware clock time drift automatically over time. You can read more about this file and its content here:
And this information on the hwclock utility is particularly useful in understanding that you really want to keep your hardware clock set with UTC time and not local time:
Look for the section labeled: LOCAL vs UTC
and read up on why.
I've set UTC=yes in the /etc/default/rcS file and UTC in the /etc/adjtime file. This allows me to keep the hardware clock in UTC time so it isn't affected by time changes due to a timezone. Your system clock can use the TZ environment variable and/or the usual symbolic link of one of the files in /usr/share/zoneinfo as /etc/localtime.
A Linux OS will automatically update the system time when time changes within a timezone, but will leave the hardware clock in UTC time without any time changes. When the hwclock-set.sh script is executed during shutdown or restart, the hardware clock will be updated with the system clock date/time. The hwclock utility automatically uses the UTC setting in the /etc/adjtime file to know how to translate the system time into UTC time when reading from and writing to the hardware clock.