xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-core/busybox/files/hwclock.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/sh
2### BEGIN INIT INFO
3# Provides:          hwclock
4# Required-Start:
5# Required-Stop:     $local_fs
6# Default-Start:     S
7# Default-Stop:      0 6
8# Short-Description: Set system clock
9# Description:       Set system clock to hardware clock, according to the UTC
10#                    setting in /etc/default/rcS (see also rcS(5)).
11### END INIT INFO
12#
13# WARNING:      If your hardware clock is not in UTC/GMT, this script
14#               must know the local time zone. This information is
15#               stored in /etc/localtime. This might be a problem if
16#               your /etc/localtime is a symlink to something in
17#               /usr/share/zoneinfo AND /usr isn't in the root
18#               partition! The workaround is to define TZ either
19#               in /etc/default/rcS, or in the proper place below.
20
21[ ! -x /sbin/hwclock ] && exit 0
22
23[ -f /etc/default/rcS ] && . /etc/default/rcS
24
25[ "$UTC" = "yes" ] && tz="--utc" || tz="--localtime"
26case "$1" in
27        start)
28                if [ "$VERBOSE" != no ]
29                then
30                        echo "System time was `date`."
31                        echo "Setting the System Clock using the Hardware Clock as reference..."
32                fi
33
34		if [ "$HWCLOCKACCESS" != no ]
35		then
36			if [ -z "$TZ" ]
37			then
38	                   hwclock $tz --hctosys
39			else
40			   TZ="$TZ" hwclock $tz --hctosys
41			fi
42		fi
43
44                if [ "$VERBOSE" != no ]
45                then
46                        echo "System Clock set. System local time is now `date`."
47                fi
48                ;;
49        stop|restart|reload|force-reload)
50		#
51		# Updates the Hardware Clock with the System Clock time.
52		# This will *override* any changes made to the Hardware Clock.
53		#
54		# WARNING: If you disable this, any changes to the system
55		#          clock will not be carried across reboots.
56		#
57		if [ "$VERBOSE" != no ]
58		then
59			echo "Saving the System Clock time to the Hardware Clock..."
60		fi
61		if [ "$HWCLOCKACCESS" != no ]
62		then
63			hwclock $tz --systohc
64		fi
65		if [ "$VERBOSE" != no ]
66		then
67			echo "Hardware Clock updated to `date`."
68		fi
69                exit 0
70                ;;
71	show)
72		if [ "$HWCLOCKACCESS" != no ]
73		then
74			hwclock $tz --show
75		fi
76		;;
77        *)
78                echo "Usage: hwclock.sh {start|stop|show|reload|restart}" >&2
79		echo "       start sets kernel (system) clock from hardware (RTC) clock" >&2
80		echo "       stop and reload set hardware (RTC) clock from kernel (system) clock" >&2
81                exit 1
82                ;;
83esac
84