RTC
RTC stands for Real Time Clock — a hardware device dedicated to keeping time. It can usually be integrated inside the SoC or attached externally and communicate via I2C.
So why is an RTC needed? Because the Linux system time (commonly called wall time) is only valid while the system is running; once the system is powered off, the time is lost. An RTC, however, can keep running after the system shuts down by drawing on an external battery or another supply, which is how the time is preserved.
1. Using the RTC
Taking M5-R1 as an example, the board uses an external RTC (hym8563) and has the rk809 RTC function disabled by default.
When using the external RTC, a coin cell battery must be connected.
2. RTC User-Space Interface
date // Modify the system clock; run man for usage details
hwclock -s // Sync the hardware time to the system time
hwclock -w // Sync the system time to the hardware time
date "2023-08-14 08:00:00" // Manually set the time
hwclock -w // Sync system time to the hardware RTC
hwclock -s // Sync the hardware RTC to the system
# After manually setting or network-syncing the time, -w writes the system time into the hardware RTC, and -s writes the RTC time back to the system. This way the RTC time is synced to the system time on every reboot.