public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* possible off-by-one error on month counting in rtc rv8803 driver
@ 2022-04-25 12:55 Oliver Graute
  2022-04-25 13:50 ` Michael Walle
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Graute @ 2022-04-25 12:55 UTC (permalink / raw)
  To: u-boot, michael; +Cc: hs, philipp.tomsich, sjg, u-boot, oliver.graute

Hello,

I stumbled across the following possible off-by-one error in counting the
month in RTC driver rv8803.

I'am using struct rtc_time to define a EOL date for my U-Boots. So after
this date U-Boot stops booting by reading the RTC before with rtc_get().
I'am using the same EOL code for two different imx boards with different
RTCs and therefore different RTC drivers. On both boards I have set the
same EOL date.

So the EOL Date is 25.09.2022 23:59:59

The board with rv3029 stopps booting on 26.09.2022 0:00:00
The board with rv8803 stopps booting on 26.08.2022 0:00:00

U-Boot Code:
(drivers/rtc/rv3029.c)

v3029_rtc_set()
...
regs[RV3029_W_MONTHS - RV3029_W_SEC] = bin2bcd(tm->tm_mon + 1);
...

rv3029_rtc_get()
...
tm->tm_mon = bcd2bin(regs[RV3029_W_MONTHS - RV3029_W_SEC]) - 1;
...

(drivers/rtc/rv8803.c)
rv8803_rtc_set()
...
buf[RTC_MON_REG_ADDR] = bin2bcd(tm->tm_mon)
...

rv8803_rtc_get()
...
tm->tm_mon  = bcd2bin(buf[RTC_MON_REG_ADDR] & 0x1F);
...

I assume that the error is here and increase and decrease by one is also
required here like in the Linux driver code for RTC 8803.

Linux Code:

rv3029_set_time()
...
regs[RV3029_W_MONTHS - RV3029_W_SEC] = bin2bcd(tm->tm_mon + 1);
...

rv3029_read_time()
...
tm->tm_mon = bcd2bin(regs[RV3029_W_MONTHS - RV3029_W_SEC]) - 1;
...

rv8803_set_time()
...
date[RV8803_MONTH] = bin2bcd(tm->tm_mon + 1);
...

rv8803_get_time()
...
tm->tm_mon  = bcd2bin(date[RV8803_MONTH] & 0x1f) - 1;
...

Can someone verify and comment on this. Then I would prepare a patch
later on.

Best Regards,

Oliver

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-25 13:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-25 12:55 possible off-by-one error on month counting in rtc rv8803 driver Oliver Graute
2022-04-25 13:50 ` Michael Walle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox