Skip to content

Commit bc40af0

Browse files
committed
added simple fake-hwclock
1 parent 3802049 commit bc40af0

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

general/package/Config.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ source "$BR2_EXTERNAL_GENERAL_PATH/package/divinus/Config.in"
1313
source "$BR2_EXTERNAL_GENERAL_PATH/package/dropbear-openipc/Config.in"
1414
source "$BR2_EXTERNAL_GENERAL_PATH/package/exfat-openipc/Config.in"
1515
source "$BR2_EXTERNAL_GENERAL_PATH/package/f2fs-tools-openipc/Config.in"
16+
source "$BR2_EXTERNAL_GENERAL_PATH/package/fake-hwclock-openipc/Config.in"
1617
source "$BR2_EXTERNAL_GENERAL_PATH/package/fdk-aac-openipc/Config.in"
1718
source "$BR2_EXTERNAL_GENERAL_PATH/package/ffmpeg-openipc/Config.in"
1819
source "$BR2_EXTERNAL_GENERAL_PATH/package/fullhan-osdrv-fh8852v100/Config.in"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
config BR2_PACKAGE_FAKE_HWCLOCK_OPENIPC
2+
bool "fake-hwclock-openipc"
3+
help
4+
Restores system time from a file on boot, saves the current time, or periodically updates a timestamp file to maintain time on systems without a hardware RTC.
5+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
################################################################################
2+
#
3+
# fake-hwclock-openipc
4+
#
5+
################################################################################
6+
7+
define FAKE_HWCLOCK_OPENIPC_INSTALL_TARGET_CMDS
8+
$(INSTALL) -m 755 -d $(TARGET_DIR)/etc/init.d
9+
$(INSTALL) -m 755 -t $(TARGET_DIR)/etc/init.d $(FAKE_HWCLOCK_OPENIPC_PKGDIR)/files/S39fakehwclock
10+
11+
$(INSTALL) -m 755 -d $(TARGET_DIR)/usr/bin
12+
$(INSTALL) -m 755 -t $(TARGET_DIR)/usr/bin $(FAKE_HWCLOCK_OPENIPC_PKGDIR)/files/fake-hwclock
13+
endef
14+
15+
$(eval $(generic-package))
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
3+
DAEMON="fake-hwclock"
4+
PIDFILE="/var/run/$DAEMON.pid"
5+
DAEMON_ARGS="5 /etc/fake-hwclock.data"
6+
7+
case "$1" in
8+
start)
9+
echo -n "Starting $DAEMON: "
10+
fake-hwclock load /etc/fake-hwclock.data
11+
# Save timestamp every 5 seconds
12+
start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "$DAEMON" -- $DAEMON_ARGS
13+
if [ $? -eq 0 ]; then
14+
echo "OK"
15+
else
16+
echo "FAIL"
17+
fi
18+
;;
19+
20+
stop)
21+
echo -n "Stopping $DAEMON: "
22+
start-stop-daemon -K -q -p "$PIDFILE"
23+
if [ $? -eq 0 ]; then
24+
rm -f "$PIDFILE"
25+
fake-hwclock save /etc/fake-hwclock.data
26+
echo "OK"
27+
else
28+
echo "FAIL"
29+
fi
30+
;;
31+
32+
*)
33+
echo "Usage: $0 {start|stop}"
34+
exit 1
35+
;;
36+
esac
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
if [[ $# -lt 2 ]]; then
4+
exit 1
5+
fi
6+
7+
MODE="$1"
8+
TIMESTAMP_FILE="$2"
9+
10+
mkdir -p "$(dirname "$TIMESTAMP_FILE")"
11+
12+
if [[ "$MODE" == "load" ]]; then
13+
if [[ -f "$TIMESTAMP_FILE" ]]; then
14+
LAST_TS=$(cat "$TIMESTAMP_FILE")
15+
if [[ -n "$LAST_TS" ]]; then
16+
echo "fake-hwclock: Setting time to $(date -d @"$LAST_TS")"
17+
fi
18+
fi
19+
elif [[ "$MODE" == "save" ]]; then
20+
date +%s > "$TIMESTAMP_FILE"
21+
elif [[ "$MODE" =~ ^[0-9]+$ ]]; then
22+
INTERVAL="$MODE"
23+
while true; do
24+
date +%s > "$TIMESTAMP_FILE"
25+
sleep "$INTERVAL"
26+
done
27+
fi

0 commit comments

Comments
 (0)