From: Oliver Graute <oliver.graute@gmail.com>
To: u-boot@lists.denx.de, michael@walle.cc
Cc: hs@denx.de, philipp.tomsich@theobroma-systems.com,
sjg@chromium.org, u-boot@lists.denx.de,
oliver.graute@kococonnector.com
Subject: possible off-by-one error on month counting in rtc rv8803 driver
Date: Mon, 25 Apr 2022 14:55:39 +0200 [thread overview]
Message-ID: <20220425125539.GA16510@optiplex> (raw)
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
next reply other threads:[~2022-04-25 12:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-25 12:55 Oliver Graute [this message]
2022-04-25 13:50 ` possible off-by-one error on month counting in rtc rv8803 driver Michael Walle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220425125539.GA16510@optiplex \
--to=oliver.graute@gmail.com \
--cc=hs@denx.de \
--cc=michael@walle.cc \
--cc=oliver.graute@kococonnector.com \
--cc=philipp.tomsich@theobroma-systems.com \
--cc=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox