/* /etc/init.d/hwclock.sh */
DAEMON1=/sbin/hwclock
start() {
local RET ERROR=
[ ! -f /etc/adjtime ] && echo "0.0 0 0.0" > /etc/adjtime
log_status_msg "Setting the System Clock using the Hardware Clock as reference..." -n
# Copies Hardware Clock time to System Clock using the correct
# timezone for hardware clocks in local time, and sets kernel
# timezone. DO NOT REMOVE.
[ "$HWCLOCKACCESS" != no ] && $DAEMON1 --hctosys $GMT $BADYEAR
#
# Now that /usr/share/zoneinfo should be available,
# announce the local time.
#
log_status_msg "System Clock set. Local time: `date`"
log_status_msg ""
return 0
}
hwclock最先读取的设备文件是 /dev/rtc ,busybox里面的hwclock是这样实现的:
static int xopen_rtc(int flags)
{
int rtc;
if (!rtcname) {
rtc = open("/dev/rtc", flags);
if (rtc >= 0)
return rtc;
rtc = open("/dev/rtc0", flags);
if (rtc >= 0)
return rtc;
rtcname = "/dev/misc/rtc";
}
return xopen(rtcname, flags);
}