[LEDE-DEV] [PATCH v2] base-files: sysfixtime: Keep RTC time in UTC by default
Petr Štetiar
ynezz at true.cz
Sun Oct 30 12:56:59 PDT 2016
We need to tell hwclock with -u commandline option, that we would like to keep
our RTC clock in UTC timezone. Linux kernel expects RTC in UTC timezone anyway.
In current state of things, we don't tell hwclock to load/store time from/to
RTC in UTC timezone so it uses the timezone from the system time. If it's set
to different timezone then UTC, sysfixtime is going to screw the time in RTC.
I've following in the setup script:
uci set system. at system[0].timezone='CET-1CEST,M3.5.0,M10.5.0/3'
uci set system. at system[0].zonename='Europe/Prague'
I've this RTC setup (rtc1 is RTC on i.MX6 SoC, rtc0 is battery backed RTC mcp7941x):
rtc-ds1307 3-006f: rtc core: registered mcp7941x as rtc0
snvs_rtc 20cc000.snvs:snvs-rtc-lp: rtc core: registered 20cc000.snvs:snvs-r as rtc1
Then we can experience following (current time is 10:15am):
$ date
Fri Oct 21 10:15:07 CEST 2016
$ hwclock -r -f /dev/rtc0
Fri Oct 21 08:14:46 2016 0.000000 seconds
$ hwclock -u -r -f /dev/rtc0
Fri Oct 21 10:14:46 2016 0.000000 seconds
And after current broken sysfixtime:
$ /etc/init.d/sysfixtime stop
$ date
Fri Oct 21 10:15:25 CEST 2016
$ hwclock -r -f /dev/rtc0
Fri Oct 21 10:15:31 2016 0.000000 seconds
Now we've time in our battery backed RTC in CEST timezone instead of UTC. Then
once again, but with this patch applied to sysfixtime, where hwclock is using
correctly the -u parameter:
$ /etc/init.d/sysfixtime stop
$ date
Fri Oct 21 10:15:53 CEST 2016
$ hwclock -r -f /dev/rtc0
Fri Oct 21 08:15:55 2016 0.000000 seconds
Signed-off-by: Petr Štetiar <ynezz at true.cz>
---
Changes since v1:
* improved commit message
* enable rtc_utc=1 in system uci file by default (RTC is kept in UTC)
package/base-files/files/etc/init.d/sysfixtime | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/package/base-files/files/etc/init.d/sysfixtime b/package/base-files/files/etc/init.d/sysfixtime
index 81d1c52..7dbaa50 100755
--- a/package/base-files/files/etc/init.d/sysfixtime
+++ b/package/base-files/files/etc/init.d/sysfixtime
@@ -6,6 +6,28 @@ STOP=90
RTC_DEV=/dev/rtc0
HWCLOCK=/sbin/hwclock
+IN_UTC=''
+
+. /lib/functions/procd.sh
+
+validate_system_section() {
+ uci_validate_section system system "${1}" \
+ 'rtc_utc:bool:1'
+}
+
+rtc_config() {
+ local rtc_utc
+
+ validate_system_section "${1}" || {
+ echo "validation failed"
+ return 1
+ }
+
+ [ $rtc_utc = 1 ] && IN_UTC='-u'
+}
+
+config_load system
+config_foreach rtc_config system
boot() {
start && exit 0
@@ -16,11 +38,11 @@ boot() {
}
start() {
- [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -f $RTC_DEV
+ [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s $IN_UTC -f $RTC_DEV
}
stop() {
- [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -f $RTC_DEV && \
+ [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w $IN_UTC -f $RTC_DEV && \
logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
}
--
1.9.1
More information about the Lede-dev
mailing list