现在的位置: 首页 > 综合 > 正文

fs2410 linux-2.6.35内核移植中的RTC问题–drivers/rtc/hctosys.c: unable to open rtc device (rtc0)

2013年07月29日 ⁄ 综合 ⁄ 共 5861字 ⁄ 字号 评论关闭

linux-2.6.35在fs2410开发板启动后,通过nfs挂载文件系统,但是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.20.253, mask=255.255.255.0, gw=192.168.20.1,
     host=thomas_fs2410, domain=, nis-domain=(none),
     bootserver=192.168.20.192, rootserver=192.168.20.192, rootpath=
Looking up port of RPC 100003/2 on 192.168.20.192
Looking up port of RPC 100005/1 on 192.168.20.192
VFS: Mounted root (nfs filesystem).
Mounted devfs on /dev
Freeing init memory: 184K




解决方案:

1.   内核配置选项


 --- Real Time Clock                                                                                        
                    [*]   Set system time from RTC on startup and resume                                                   
                     (rtc0)  RTC used to set the system time                                                        
                    [ ]   RTC debug support                                                                                   
                      *** RTC interfaces ***                                                                             
                    [*]   /sys/class/rtc/rtcN (sysfs)                                                                  
                    [*]   /dev/rtcN (character devices)                                                                
                    [ ]     RTC UIE emulation on dev interface      
      *** on-CPU RTC drivers ***                                                               
                    <*>   Samsung S3C series SoC RTC  



2.  linux kernel 中 已经支持S3C2410的RTC,但是并没有添加到平台设备初始化数组中,所以系统启动时并不会初始化这一部分,需要修改文件mach-smdk.c

static struct platform_device *smdk2410_devices[] __initdata = {
    &s3c_device_ohci,
    &s3c_device_lcd,
    &s3c_device_wdt,
    &s3c_device_i2c0,
    &s3c_device_iis,
    &s3c_device_rtc,   //新增代码
};



3.  创建设备节点,在文件系统/dev目录下执行:

sudo   mknod rtc c 10 135



4.  重新编译内核,查看启动信息

S3C24XX RTC, (c) 2004,2006 Simtec Electronics                                                                                      
s3c-rtc s3c2410-rtc: rtc disabled, re-enabling                                                                                     
s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0       

这里说明rtc驱动起来可以正常工作了                                                                       
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics                                                                                
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled                                                            
No device for DAI UDA134X                                                                                                          
No device for DAI s3c24xx-i2s                                                                                                      
ALSA device list:                                                                                                                  
  No soundcards found.                                                                                                             
TCP cubic registered                                                                                                               
NET: Registered protocol family 17                                                                                                 
s3c-rtc s3c2410-rtc: hctosys: invalid date/time    

 
以上信息说明当前
RTC
时间invalid  ,
RTC
初始时间为
Wed Dec 31 23:59:59 1969
;



从内核函数
int rtc_valid_tm(struct rtc_time *tm)
,可以看出,当
year
小于
1970
时,认为是时间
invalid
,函数返回
-EINVAL
;

drivers/rtc/rtc-lib.c

/*
 * Does the rtc_time represent a valid date/time?
 */
int rtc_valid_tm(struct rtc_time *tm)
{
    if (tm->tm_year < 70
        || ((unsigned)tm->tm_mon) >= 12
        || tm->tm_mday < 1
        || tm->tm_mday > rtc_month_days(tm->tm_mon, tm->tm_year + 1900)
        || ((unsigned)tm->tm_hour) >= 24
        || ((unsigned)tm->tm_min) >= 60
        || ((unsigned)tm->tm_sec) >= 60)
        return -EINVAL;

    return 0;
}
EXPORT_SYMBOL(rtc_valid_tm);

下面来验证一下这个想法



# hwclock

Wed Dec 31 23:59:59 1969  0.000000 seconds

# date

Thu Jan  1 00:06:58 UTC 1970

             

系统时间是通过
date
来设置的,
RTC
时间是通过
hwclock
来设置的。开机时系统时间首先通过
RTC
来获得,RTC没有设置时,系统时间也会使用Wed Dec 31 23:59:59 1969。


 

# 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)

 

# hwclock -s

hwclock: settimeofday() failed: Invalid argument

# hwclock -w

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

hwclock: RTC_SET_TIME: Invalid argument

 

以上错误信息都是因为
year
设置不当引起的。没有设置
RTC

RTC
也不会启动计时。

 

下面首先设置正确的系统时间,然后将系统时间传递给
RTC


 

# date 040612282008.20

Sun Apr  6 12:28:20 UTC 2008

# hwclock -w

# hwclock

Sun Apr  6 12:29:01 2008  0.000000 seconds

# hwclock

Sun Apr  6 12:30:15 2008  0.000000 seconds

 

Ok

RTC
开始工作了!

 

为了使系统时间和
RTC
时间同步,可以在初始化文件中添加命令

Hwclock –s

使每次开机时读取
RTC
时间,并同步给系统时间。

 


etc/init.d/rcS
中添加

/bin/hwclock -s



时间设置的相关命令(转载)

    1.
在虚拟终端中使用date
命令来查看和设置系统时间
   

查看系统时钟的操作:

    # date


   
设置系统时钟的操作:
    # date 091713272003.30


   
通用的设置格式:
    # date

月日时分年.


    2.
使用hwclock
clock
命令查看和设置硬件时钟
   

查看硬件时钟的操作:

    # hwclock --show



    # clock --show
    2003

09

17

星期三 13
24
11
-0.482735 seconds

   
设置硬件时钟的操作:
    # hwclock --set --date="09/17/2003 13:26:00"


   
或者
    # clock --set --date="09/17/2003 13:26:00"


   
通用的设置格式:hwclock/clock --set --date=“
/
/
年时:分:秒

    3.
同步系统时钟和硬件时钟

    Linux
系统(
笔者使用的是Red Hat 8.0
,其它系统没有做过实验)
默认重启后,硬件时钟和系统时钟同步。如果不大方便重新启动的话(
服务器通常很少重启)
,使用clock
hwclock
命令来同步系统时钟和硬件时钟。

   
硬件时钟与系统时钟同步:
    # hwclock --hctosys


   
或者
    # clock --hctosys


   
上面命令中,--hctosys
表示Hardware Clock to SYStem clock

   
系统时钟和硬件时钟同步:
    # hwclock --systohc


   
或者
    # clock --systohc


   
使用图形化系统设置工具设置时间



参考:http://blogold.chinaunix.net/u2/63560/showart_518707.html













抱歉!评论已关闭.