First, there are two types of time under Linux, system time and hardware time (RTC chip):
1. System time is the time that can be directly seen by the running system;
2. Hardware time is the time in the RTC chip, which is still powered by battery even when power is off;
When the Linux system is turned on, it will read the current time from the RTC as the system time, and the system time will tick independently from then on. This means that if you use the date command to modify the system time, the hardware time will not be affected. If you shut down the system at this time, the next system time will still be wrong. To save the system time to the hardware time, you can use the hwclock or clock command, where hwclock means hardware clock.
Because my development board does not support the clock command, I will only explain the hwclock command:
BusyBox v1.20.2 (2014-07-26 20:22:32 CST) multi-call binary.
Usage: hwclock [-r|--show] [-s|--hctosys] [ -w|--systohc] [-t|--systz] [-l|--localtime] [-u|--utc] [-f|--rtc FILE]
Query and set hardware clock (RTC)
-r Show hardware clock time
-s Set system time from hardware clock
-w Set hardware clock from system time
-t Set in-kernel timezone, correct system time
if hardware clock is in local time
-u Assume hardware clock is kept in UTC
-l Assume hardware clock is kept in local time
-f FILE Use specified device (eg /dev/rtc2)
hwclock –r show, displays the hardware clock, equivalent to hwclock without parameters.
hwclock –s hctosys, hardware clock to system, writes the time of the "hardware clock" RTC to the Linux "system" clock.
hwclock –w systohc, system to hardware clock, writes the "system" clock to the "hardware clock" RTC
Second, add support for RTC in the kernel (kernel linux-3.8)
1. RTC is already well supported in the kernel. You only need to add kernel compilation and register it:
Modify arch/arm/mach-s3c24xx/mach-smdk2440.c and add (just add the RTC device, in red):
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_ohci,
&s3c_device_lcd
, &s3c_device_wdt
, &s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_dm9000,
&s3c_device_adc,
&s3c_device_ts,
&s3c_device_rtc,
};
In arch/arm/plat-samsung/devs.c there is s3c_device_rtc definition:
#ifdef CONFIG_PLAT_S3C24XX
static struct resource s3c_rtc_resource[] = {
[0] = DEFINE_RES_MEM(S3C24XX_PA_RTC, SZ_256),
[1] = DEFINE_RES_IRQ(IRQ_RTC),
[2] = DEFINE_RES_IRQ(IRQ_TICK),
};
struct platform_device s3c_device _rtc = {
.name = "s3c2410-rtc",
.id = -1,
.num_resources = ARRAY_SIZE(s3c_rtc_resource),
.resource = s3c_rtc_resource,
};
#endif /* CONFIG_PLAT_S3C24XX */
2. Make menuconfig to add configuration options:
DeviceDrivers --->
[*] Real Time Clock --->
--- Real Time Clock
[*] Set system time from RTC on startup and resume
(rtc0) RTC used to set the system time
[*] /sys/class/rtc/rtcN (sysfs)
[*] /proc/driver/rtc (procfs for rtcN)
[*] /dev/rtcN(character devices)
After the Linux RTC driver is implemented, it is usually a normal character device, a misc device, or a platform device by default. If the driver is insmoded or compiled directly into the kernel, the corresponding device file is usually /dev/rtc or /dev/rtc0 or /dev/misc/rtc. In the linux-3.8 kernel, the root file system tool busybox-1.20.2 includes the hwclock command definition:
In busybox-1.20.2's libbb/rtc.c there is:
int FAST_FUNCrtc_xopen(const char **default_rtc, int flags)
{
int rtc;
if(!*default_rtc) {
*default_rtc = "/dev/rtc";
rtc =open(*default_rtc, flags);
if (rtc>= 0)
return rtc;
*default_rtc ="/dev/rtc0";
rtc = open(*default_rtc, flags);
if (rtc >= 0)
return rtc;
*default_rtc = "/dev/misc/rtc";
}
returnxopen(*default_rtc, flags);
}
3. Compile, download and start: red font means RTC is added ok
[s3c2440@zhou]# boot
NAND read: device 0 offset 0x100000, size 0x800000
8388608 bytesread: OK
## Booting kernel from Legacy Image at 30008000 ...
ImageName: Linux Kernel
Created: 2014-08-13 7:55:08 UTC
ImageType: ARM Linux Kernel Image(uncompressed)
DataSize: 3115480 Bytes = 3 MiB
Load Address:30008000
EntryPoint: 30008040
VerifyingChecksum ... OK
XIP KernelImage ... OK
OK
OS entry point: 30008040
Image entry point=30008040
Starting kernel ...
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda(Samsung NAND 256MiB 3,3V 8-bit), 256MiB, page size: 2048, OOB size: 64
Scanning device for bad blocks
Bad eraseblock 236 at 0x000001d80000
Bad eraseblock 704 at 0x000005800000
Bad eraseblock 705 at 0x000005820000
Bad eraseblock 717 at 0x0000059a0000
Bad eraseblock 1251 at 0x000009c60000
Bad eraseblock 1631 at 0x00000cbe0000
Bad eraseblock 1771 at 0x00000dd60000
Bad eraseblock 1947 at 0x00000f360000
Creating 9 MTD partitions on "NAND":
0x000000000000-0x000000100000 : "mtdblock0_u-Boot1MB "
0x000000100000-0x000001000000 : "mtdbolck1_kernel15MB"
0x000001000000-0x000002400000 :"mtdbolck2_ramdisk 20MB"
0x000002400000-0x000003800000 : "mtdblock3_cramfs20MB"
0x000003800000-0x000006000000 : "mtdblock4_jffs240MB"
0x000006000000-0x000008800000 : "mtdblock5_yaffs240MB"
0x000008800000-0x00000b000000 : "mtdblock6_ubifs40MB"
0x00000b000000-0x00000d800000 : "mtdblock7_apps40MB"
0x00000d800000-0x000010000000 : "mtdblock8_data40MB"
. . . . .
usbserial: USB Serial support registered for pl2303
mousedev: PS/2 mouse device common for all mice
s3c-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
. . . . .
UBI: background thread "ubi_bgt0d" started,PID 472
s3c-rtc s3c2410-rtc: setting system clock to 2024-04-2611:18:22 UTC (1714130302)
ALSA device list:
. . . . .
Freeing init memory: 156K
usb 1-1: New USB device found, idVendor=05e3,idProduct=0606
usb 1-1: New USB device strings: Mfr=1, Product=2,SerialNumber=0
usb 1-1: Product: USB Hub 2.0
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
dm9000 dm9000 eth0: link down dm9000 dm9000 eth0: linkup, 100Mbps, full-duplex, lpa 0xCDE1
Copyright (C) 2014zhouguangfeng
root for passwd: 12345
root login: root
Password:
apps data etc init linuxrc my2440 root sys usr
bin dev info lib mnt proc sbin tmp var
Wed Jan 1 01:04:08 MST 2014
to Wed Aug 13 17:51:10 MDT 2014
Wed Jan 1 01:05:08 2014 0.000000 seconds
Wed Jan 1 01:05:26 MST 2014
Wed Aug 13 17:51:10 MDT 2014
Wed Jan 1 01:05:59 2014 0.000000 seconds
Wed Aug 13 17:51:25 2014 0.000000 seconds
crw-rw---- 1 root root 254, 0 Dec 31 1969 /dev/rtc0
Previous article:Kernel transplantation and file system creation (3) Ramdisk introduction and common problems
Next article:Module cannot be rmmod after insmod
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Another technical solution for power-type plug-in hybrid: A brief discussion on Volvo T8 plug-in hybrid technology
- STM32F767 Bluetooth module communication problem
- C28x series DSP (28069) (28377D) CAN communication
- List the functions of TI msp430 microcontroller clock
- Pure dry goods! Overview of radio frequency power amplifier (RF PA)
- UMTS Turbo MAP Decoder for DSP Processor
- The company is recruiting weekend part-time electronic control system design and simulation lecturers
- Current sensing: What is the difference between using high-side sensing and low-side sensing?
- Hardware Circuit Design - "DFX"
- ESP32 Learning Notes 3 -- WS2812 16*16 dot matrix point, line and surface painting
- Discussion on Optimization Ideas for 5G Massive MIMO