diff --git a/package/Config.in b/package/Config.in index ffaed13c74..579b5ffc87 100644 --- a/package/Config.in +++ b/package/Config.in @@ -2866,6 +2866,7 @@ menu "System tools" source "package/getent/Config.in" source "package/gkrellm/Config.in" source "package/htop/Config.in" + source "package/hwclock-initscript/Config.in" source "package/ibm-sw-tpm2/Config.in" source "package/initscripts/Config.in" source "package/iotop/Config.in" diff --git a/package/hwclock-initscript/Config.in b/package/hwclock-initscript/Config.in new file mode 100644 index 0000000000..a660a26eaa --- /dev/null +++ b/package/hwclock-initscript/Config.in @@ -0,0 +1,10 @@ +config BR2_PACKAGE_HWCLOCK_INITSCRIPT + bool "hwclock-initscript" + depends on !BR2_PACKAGE_SYSTEMD + depends on BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_UTIL_LINUX_HWCLOCK + help + Initscript to save the date and time to the hardware clock on + shutdown. + + Note that the kernel already loads the time from the hwclock + at boot time, no init script is needed for that. diff --git a/package/hwclock-initscript/S20hwclock b/package/hwclock-initscript/S20hwclock new file mode 100644 index 0000000000..c9f55cff1c --- /dev/null +++ b/package/hwclock-initscript/S20hwclock @@ -0,0 +1,39 @@ +#! /bin/sh +# +# hwclock This writes the system time to the RTC on shutdown +# + +RTC_DEVICE=rtc0 +DAEMON=hwclock + +# shellcheck source=/dev/null +[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON" + +# Quietly do nothing if /dev/rtc0 does not exist +[ -c /dev/$RTC_DEVICE ] || exit 0 + +start(){ + : # Nothing to do on startup +} + +stop(){ + printf "Saving the system clock to /dev/%s\n" "${RTC_DEVICE}" + /sbin/$DAEMON -f "/dev/${RTC_DEVICE}" -w +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart|reload) + stop + start + ;; + *) + echo "Usage: $0 {start|stop|restart|reload}" + exit 1 + ;; +esac diff --git a/package/hwclock-initscript/hwclock-initscript.mk b/package/hwclock-initscript/hwclock-initscript.mk new file mode 100644 index 0000000000..a5d42ef55f --- /dev/null +++ b/package/hwclock-initscript/hwclock-initscript.mk @@ -0,0 +1,12 @@ +################################################################################ +# +# hwclock-initscript +# +################################################################################ + +define HWCLOCK_INITSCRIPT_INSTALL_INIT_SYSV + $(INSTALL) -D -m 0755 $(HWCLOCK_INITSCRIPT_PKGDIR)/S20hwclock \ + $(TARGET_DIR)/etc/init.d/S20hwclock +endef + +$(eval $(generic-package))