diff mbox series

[RESEND,2/2] package/buildroot-initscripts: add hwclock initscript

Message ID 20230313081549.493823-3-michael@walle.cc
State Accepted
Headers show
Series new package buildroot-initscripts | expand

Commit Message

Michael Walle March 13, 2023, 8:15 a.m. UTC
Add a new initscript to save the date and time to the hardware clock
on shutdown.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 package/buildroot-initscripts/Config.in       |  6 ++++++
 package/buildroot-initscripts/S20hwclock      | 21 +++++++++++++++++++
 .../buildroot-initscripts.mk                  |  1 +
 3 files changed, 28 insertions(+)
 create mode 100644 package/buildroot-initscripts/S20hwclock

Comments

Arnout Vandecappelle May 18, 2025, 8:47 p.m. UTC | #1
On 13/03/2023 09:15, Michael Walle via buildroot wrote:
> Add a new initscript to save the date and time to the hardware clock
> on shutdown.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>

  We decided to put this instead into a package hwclock-initscript in the System 
Tools menu.

  I've made a few further changes and applied to master, thanks.
- mention in help text that it isn't needed at boot;
  rewrite initscript according to our usual pattern;
  fix shellcheck errors.


  Regards,
  Arnout

> ---
>   package/buildroot-initscripts/Config.in       |  6 ++++++
>   package/buildroot-initscripts/S20hwclock      | 21 +++++++++++++++++++
>   .../buildroot-initscripts.mk                  |  1 +
>   3 files changed, 28 insertions(+)
>   create mode 100644 package/buildroot-initscripts/S20hwclock
> 
> diff --git a/package/buildroot-initscripts/Config.in b/package/buildroot-initscripts/Config.in
> index 8e84e975fa..b30c91b646 100644
> --- a/package/buildroot-initscripts/Config.in
> +++ b/package/buildroot-initscripts/Config.in
> @@ -7,6 +7,12 @@ config BR2_PACKAGE_BUILDROOT_INITSCRIPTS
>   
>   if BR2_PACKAGE_BUILDROOT_INITSCRIPTS
>   
> +config BR2_PACKAGE_BUILDROOT_INITSCRIPTS_HWCLOCK
> +	bool "hwclock"
> +	help
> +	  Initscript to save the date and time to the hardware clock on
> +	  shutdown.
> +
>   config BR2_PACKAGE_BUILDROOT_INITSCRIPTS_URANDOM
>   	bool "urandom"
>   	default y if BR2_PACKAGE_INITSCRIPTS
> diff --git a/package/buildroot-initscripts/S20hwclock b/package/buildroot-initscripts/S20hwclock
> new file mode 100644
> index 0000000000..3e6ea98fe8
> --- /dev/null
> +++ b/package/buildroot-initscripts/S20hwclock
> @@ -0,0 +1,21 @@
> +#! /bin/sh
> +
> +RTC_DEVICE=rtc0
> +
> +[ -r "/etc/default/hwclock" ] && . "/etc/default/hwclock"
> +
> +# Quietly do nothing if /dev/rtc0 does not exist
> +[ -c /dev/$RTC_DEVICE ] || exit 0
> +
> +case "$1" in
> +	start)
> +		exit 0
> +		;;
> +	stop)
> +		echo "Saving the system clock to /dev/$RTC_DEVICE.."
> +		/sbin/hwclock -f /dev/$RTC_DEVICE -w
> +		;;
> +	*)
> +		echo "Usage: $0 {start|stop}"
> +		exit 1
> +esac
> diff --git a/package/buildroot-initscripts/buildroot-initscripts.mk b/package/buildroot-initscripts/buildroot-initscripts.mk
> index 098113bcbd..980a5fe1e4 100644
> --- a/package/buildroot-initscripts/buildroot-initscripts.mk
> +++ b/package/buildroot-initscripts/buildroot-initscripts.mk
> @@ -4,6 +4,7 @@
>   #
>   ################################################################################
>   
> +BUILDROOT_INITSCRIPTS_SCRIPTS_$(BR2_PACKAGE_BUILDROOT_INITSCRIPTS_HWCLOCK) += S20hwclock
>   BUILDROOT_INITSCRIPTS_SCRIPTS_$(BR2_PACKAGE_BUILDROOT_INITSCRIPTS_URANDOM) += S20seedrng
>   
>   define BUILDROOT_INITSCRIPTS_INSTALL_INIT_SYSV
diff mbox series

Patch

diff --git a/package/buildroot-initscripts/Config.in b/package/buildroot-initscripts/Config.in
index 8e84e975fa..b30c91b646 100644
--- a/package/buildroot-initscripts/Config.in
+++ b/package/buildroot-initscripts/Config.in
@@ -7,6 +7,12 @@  config BR2_PACKAGE_BUILDROOT_INITSCRIPTS
 
 if BR2_PACKAGE_BUILDROOT_INITSCRIPTS
 
+config BR2_PACKAGE_BUILDROOT_INITSCRIPTS_HWCLOCK
+	bool "hwclock"
+	help
+	  Initscript to save the date and time to the hardware clock on
+	  shutdown.
+
 config BR2_PACKAGE_BUILDROOT_INITSCRIPTS_URANDOM
 	bool "urandom"
 	default y if BR2_PACKAGE_INITSCRIPTS
diff --git a/package/buildroot-initscripts/S20hwclock b/package/buildroot-initscripts/S20hwclock
new file mode 100644
index 0000000000..3e6ea98fe8
--- /dev/null
+++ b/package/buildroot-initscripts/S20hwclock
@@ -0,0 +1,21 @@ 
+#! /bin/sh
+
+RTC_DEVICE=rtc0
+
+[ -r "/etc/default/hwclock" ] && . "/etc/default/hwclock"
+
+# Quietly do nothing if /dev/rtc0 does not exist
+[ -c /dev/$RTC_DEVICE ] || exit 0
+
+case "$1" in
+	start)
+		exit 0
+		;;
+	stop)
+		echo "Saving the system clock to /dev/$RTC_DEVICE.."
+		/sbin/hwclock -f /dev/$RTC_DEVICE -w
+		;;
+	*)
+		echo "Usage: $0 {start|stop}"
+		exit 1
+esac
diff --git a/package/buildroot-initscripts/buildroot-initscripts.mk b/package/buildroot-initscripts/buildroot-initscripts.mk
index 098113bcbd..980a5fe1e4 100644
--- a/package/buildroot-initscripts/buildroot-initscripts.mk
+++ b/package/buildroot-initscripts/buildroot-initscripts.mk
@@ -4,6 +4,7 @@ 
 #
 ################################################################################
 
+BUILDROOT_INITSCRIPTS_SCRIPTS_$(BR2_PACKAGE_BUILDROOT_INITSCRIPTS_HWCLOCK) += S20hwclock
 BUILDROOT_INITSCRIPTS_SCRIPTS_$(BR2_PACKAGE_BUILDROOT_INITSCRIPTS_URANDOM) += S20seedrng
 
 define BUILDROOT_INITSCRIPTS_INSTALL_INIT_SYSV