I am attempting to run hwclock on an embedded bionic version for an aarch64 Layerscape processor from NXP. The command I am using is:
Calling /sbin/hwclock -D --set --date='2023-07-07 16:34:08'
hwclock from util-linux 2.31.1
System Time: 1688747648.003062
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Last drift adjustment done at 1688747572 seconds after 1969
Last calibration done at 1688747572 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
missed it - 1689093250.060709 is too far past 1688747648.503062 (345601.557647 > 0.001000)
1689093250.503062 is close enough to 1689093250.503062 (0.000000 < 0.002000)
Set RTC to 1689093250 (1688747648 + 345602; refsystime = 1688747648.003062)
Setting Hardware Clock to 16:34:10 = 1689093250 seconds since 1969
ioctl(RTC_SET_TIME) was successful.
Not adjusting drift factor because the --update-drift option was not used.
New /etc/adjtime data:
0.000000 1688747648 0.000000
1688747648
UTC
Hwclock updated.
Note that I am trying to set the hardware clock to a value different than my host system. In this example, I am trying to set the hardware clock July 7, but my system clock is July 11.
Sometimes, this works. But in many instances, the hwclock command seems to choke, and winds up ignoring the passed in date, as in the example above. Notice the line:
System Time: 1688747648.003062
That translates to July 7, showing hwclock did parse the parameter correctly.
However, it is unable to calculate the calibration factor, and so rather than skipping it, which is what I want, it instead sets the hwclock to 1689093250, which translates to July 11 - the current date of the system. This is NOT what I want it to do.
I have tried several variations of parameters, such as --noadjfile, but nothing works. It seems if the hwclock and system clock are too far apart hwclock just fails and it sets the hwclock to the system clock whether I like it or not.
Is there a way to get this command to do what I want it to do? Or is there another utility I should be using instead? It seems very unfriendly to just ignore my request and do whatever it wants. It should at least fail gracefully and tell me in this case.