Is there a way to set the date to RTC value when debian is booted?

Is there a way to set the date to RTC value when debian is booted?

On Android, time is maintained, but not on debian.
Should I use fake-hwclock?

file : pm8916.dtsi

&spmi_bus {
pm8916_0: pm8916@0 {
compatible = “qcom,pm8916”, “qcom,spmi-pmic”;
reg = <0x0 SPMI_USID>;
#address-cells = <1>;
#size-cells = <0>;

  rtc@6000 {
  	compatible = "qcom,pm8941-rtc";
  	reg = <0x6000>;
  	reg-names = "rtc", "alarm";
  	interrupts = <0x0 0x61 0x1 IRQ_TYPE_EDGE_RISING>;
  };

file : .config

CONFIG_RTC_DRV_PM8XXX=y
CONFIG_RTC_HCTOSYS=y
CONFIG_RTC_HCTOSYS_DEVICE=“rtc0”
CONFIG_RTC_SYSTOHC=y
CONFIG_RTC_SYSTOHC_DEVICE=“rtc0”

terminal :

root@linaro-alip:~# hwclock
1970-01-01 10:10:10.345815+09:00
root@linaro-alip:~# hwclock -w
hwclock: ioctl(RTC_SET_TIME) to /dev/rtc0 to set the time failed: Permission denied
root@linaro-alip:~#

What are you trying to accomplish? Are you trying to set the system time? The system time and the RTC time are not the same thing. The RTC is typically used to store the time during an “off” interval, however it requires a battery or other power supply to keep it ticking. Those config parameters you found: SYSTOHC: saves the system time to the RTC when the device is going to turn off. HCTOSYS: loads the RTC time to the system when the kernel boots up. Those won’t do you any good, however, since the clock will reset to 1970 the moment the power goes off.

fake-hwclock is helpful in that it makes sure that time at least keeps flowing forward. However, it obviously will stop advancing when the power is turned off. In other words, if you turn the board off for 6 hours and start it up again, then your clock will be 6 hours behind.

In Android, the system time is obtained via NTP upon boot. You probably don’t notice it because it happens the moment the network connects. The RTC doesn’t need to be involved at all. Debian can be configured to do the same thing, but seems that you are going to have to configure it yourself. Its been a while since I’ve set up a linux ntp client, but if I recall correctly, the default settings may not work if the time jump is too large, but there was a parameter that allows it to ignore that.

If NTP is used, it operates at normal time.

However, when you reboot offline, the time is delayed by the time it was off.

RTC has a coin battery,
It is in 1970, but it progresses normally.

I want to use normal time when rebooting using RTC.

Ok, well if its progressing normally, then you just have to do a little math;

System clock (seconds since epoch) = RTC (seconds since epoch) + offset.

Don’t use the kernel config parameter to read or set the RTC, do it manually in your rc.local

As far as I understand, there may not be any way to actually set the RTC.