hwclock: settimeofday() failed: Invalid argument

 

移植linux2.6.35到s3c2416遇到drivers/rtc/hctosys.c: unable to open rtc device (rtc0) 錯誤提示。
2010年07月09日 星期五 14:26


移植linux2.6.35到s3c2416遇到drivers/rtc/hctosys.c: unable to open rtc device (rtc0) 錯誤提示。

網上搜索找到了解決辦法,如下:

解決辦法:

從啓動信息可以看出沒有加載成功 RTC 驅動!

TCP cubic registered

NET: Registered protocol family 1

RPC: Registered udp transport module.

RPC: Registered tcp transport module.

drivers/rtc/hctosys.c: unable to open rtc device (rtc0)

IP-Config: Complete:

      device=eth0, addr=192.168.1.230, mask=255.255.255.0, gw=192.168.1.1,

     host=www, domain=, nis-domain=kevin.com,

     bootserver=192.168.1.90, rootserver=192.168.1.90, rootpath=

Looking up port of RPC 100003/2 on 192.168.1.90
s3c2416 的 RTC 已經在 2.6.35 kernel 中,但是沒有加入 smdk2416  targetboard ,

所以我們只需要將 RTC 加入初始化的設備列表中。


1.       menu config 中 RTC 部分使用默認設置。


2.       修改文件 mach-smdk2416 .c ( /linux2.6.35.6/arch/arm/mach-s3c2416/mach-smdk2416 .c ),在數組 smdk2416 _devices[] 中添加 &s3c_device_rtc.


3.       在 /dev 目錄下創建 rtc 設備文件 rtc.

            mknod rtc c 10 135


4.       重新編譯內核。看看啓動信息。

            ……

            S3C24XX RTC, (c) 2004,2006 Simtec Electronics

            s3c2410-rtc s3c2410-rtc: rtc disabled, re-enabling

            s3c2410-rtc s3c2410-rtc: rtc core: registered s3c as rtc0

            ……

            以上信息說明 RTC 設備已經加入內核了。

             完事。

錯誤提示:hwclock: settimeofday() failed: Invalid argument

以上信息說明可能還沒有設置 RTC 時間, RTC 初始時間爲 Wed Dec 31 23:59:59 1969 。從內核函數 int rtc_valid_tm(struct rtc_time *tm) ,可以看出,當 year 小於 1970 時,認爲是時間 invalid ,函數返回 -EINVAL下面來驗證一下這個想法 J


[username@smdk2416]#
[username@smdk2416]# hwclock
Wed Dec 31 23:59:59 1969 0.000000 seconds
[username@smdk2416]# date
Wed Jul 30 20:34:09 UTC 1975


系統時間是通過 date 來設置的, RTC 時間是通過 hwclock 來設置的。開機時系統時間首先通過 RTC 來獲得,RTC沒有設置時,系統時間也會使用Wed Dec 31 23:59:59 1969。


[root@ltls /]# hwclock --help

BusyBox v1.9.2 (2008-04-01 21:32:34 CST) multi-call binary


Usage: hwclock [-r|--show] [-s|--hctosys] [-w|--systohc] [-l|--localtime] [-u|--utc] [-f FILE]


Query and set a hardware clock (RTC)


Options:

            -r       Read hardware clock and print result

            -s      Set the system time from the hardware clock

            -w      Set the hardware clock to the system time

            -u      The hardware clock is kept in coordinated universal time

            -l       The hardware clock is kept in local time

            -f FILE      Use the specified clock (e.g. /dev/rtc2)


[root@ltls /]# hwclock -s

hwclock: settimeofday() failed: Invalid argument

[root@ltls /]# hwclock -w

s3c2410-rtc s3c2410-rtc: rtc only supports 100 years

hwclock: RTC_SET_TIME: Invalid argument


以上錯誤信息都是因爲 year 設置不當引起的。沒有設置 RTC , RTC 也不會啓動計時。


下面首先設置正確的系統時間,然後將系統時間傳遞給 RTC 。


[root@ltls /]# date 040612282008.20

Sun Apr 6 12:28:20 UTC 2008

[root@ltls /]# hwclock -w

[root@ltls /]# hwclock

Sun Apr 6 12:29:01 2008 0.000000 seconds

[root@ltls /]# hwclock

Sun Apr 6 12:30:15 2008 0.000000 seconds


Ok , RTC 開始工作了!


爲了使系統時間和 RTC 時間同步,可以在初始化文件中添加命令
Hwclock –s

使每次開機時讀取 RTC 時間,並同步給系統時間。


在 etc/init.d/rcS 中添加
#+kevin080305

/bin/hwclock -s

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章