mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 04:13:31 +00:00
base-files: sysfixtime: Fix time on the fake RTC
On some devices the chip has RTC but no battery save time. This leads back to getting the wrong time and skipping the check of the last file modification date. This commit ensures that the file time is checked even if the RTC exists. which would ordinarily return an approbiate system time used for e.g. certificate generation. Tested-on: NanoPi R2S Signed-off-by: Yuan Tao <ty@wevs.org>
This commit is contained in:
parent
d519e5fd0d
commit
ccb04d670d
@ -8,23 +8,33 @@ RTC_DEV=/dev/rtc0
|
|||||||
HWCLOCK=/sbin/hwclock
|
HWCLOCK=/sbin/hwclock
|
||||||
|
|
||||||
boot() {
|
boot() {
|
||||||
start && exit 0
|
hwclock_load
|
||||||
|
local maxtime="$(find_max_time)"
|
||||||
local maxtime="$(maxtime)"
|
|
||||||
local curtime="$(date +%s)"
|
local curtime="$(date +%s)"
|
||||||
[ $curtime -lt $maxtime ] && date -s @$maxtime
|
if [ $curtime -lt $maxtime ]; then
|
||||||
|
date -s @$maxtime
|
||||||
|
hwclock_save
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -u -f $RTC_DEV
|
hwclock_load
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
hwclock_save
|
||||||
|
}
|
||||||
|
|
||||||
|
hwclock_load() {
|
||||||
|
[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -u -f $RTC_DEV
|
||||||
|
}
|
||||||
|
|
||||||
|
hwclock_save(){
|
||||||
[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -u -f $RTC_DEV && \
|
[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -u -f $RTC_DEV && \
|
||||||
logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
|
logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
|
||||||
}
|
}
|
||||||
|
|
||||||
maxtime() {
|
find_max_time() {
|
||||||
local file newest
|
local file newest
|
||||||
|
|
||||||
for file in $( find /etc -type f ) ; do
|
for file in $( find /etc -type f ) ; do
|
||||||
|
Loading…
Reference in New Issue
Block a user