[PATCH v4 07/11] rtc: sandbox-rtc: fix set method
Heiko Schocher
hs at denx.de
Thu Jul 9 10:37:55 CEST 2020
Hello Rasmus,
Am 06.07.2020 um 22:01 schrieb Rasmus Villemoes:
> The current set method is broken; a simple test case is to first set
> the date to something in April, then change the date to 31st May:
>
> => date 040412122020.34
> Date: 2020-04-04 (Saturday) Time: 12:12:34
> => date 053112122020.34
> Date: 2020-05-01 (Friday) Time: 12:12:34
>
> or via the amending of the existing rtc_set_get test case similarly:
>
> $ ./u-boot -T -v
> => ut dm rtc_set_get
> Test: dm_test_rtc_set_get: rtc.c
> expected: 31/08/2004 18:18:00
> actual: 01/08/2004 18:18:00
>
> The problem is that after each register write,
> sandbox_i2c_rtc_complete_write() gets called and sets the internal
> time from the current set of registers. However, when we get to
> writing 31 to mday, the registers are in an inconsistent state (mon is
> still 4), so the mktime machinery ends up translating April 31st to
> May 1st. Upon the next register write, the registers are populated by
> sandbox_i2c_rtc_prepare_read(), so the 31 we just wrote to mday gets
> overwritten by a 1.
>
> Fix it by writing all registers at once, and for consistency, update
> the get method to retrieve them all with one "i2c transfer".
>
> Reviewed-by: Simon Glass <sjg at chromium.org>
> Reviewed-by: Heiko Schocher <hs at denx.de>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
> ---
> drivers/rtc/sandbox_rtc.c | 65 +++++++++++++++------------------------
> test/dm/rtc.c | 15 ++++++++-
> 2 files changed, 38 insertions(+), 42 deletions(-)
Applied to u-boot-i2c.git master
Thanks!
bye,
Heiko
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
More information about the U-Boot
mailing list