linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Jean-Francois Dagenais <jeff.dagenais@gmail.com>
Cc: "Michal Simek" <michal.simek@xilinx.com>,
	a.zummo@towertech.it, "Srinivas Goud" <sgoud@xilinx.com>,
	git@xilinx.com, linux-rtc@vger.kernel.org,
	champagne.guillaume.c@gmail.com,
	"Maxime Roussin-Bélanger" <maxime.roussinbelanger@gmail.com>,
	"Mathieu Gallichand" <Mathieu.Gallichand@sonatest.com>
Subject: Re: [PATCH 2/2] rtc: zynqmp: fix invalid read_time before 1 second
Date: Thu, 28 Nov 2019 18:29:57 +0100	[thread overview]
Message-ID: <20191128172957.GS299836@piout.net> (raw)
In-Reply-To: <CD70064B-5087-4A0F-9197-1F4A3DAA8B50@gmail.com>

On 28/11/2019 11:04:19-0500, Jean-Francois Dagenais wrote:
> Hi Michal, all,
> 
> > On Nov 28, 2019, at 03:19, Michal Simek <michal.simek@xilinx.com> wrote:
> > 
> >> in CURRENT_TIME and proceeds to use SET_TIME_READ (RTC_SET_TM_RD in the
> >> code). This register contains garbage at this moment and this is
> >> returned as the current time.
> > 
> > How did you test this?
> 
> Remember the linux trampoline code... jumping from FSBL to the kernel without
> u-boot? Well, got it working and it speeds our boot substantially. This means we
> now reach rtc-zynqmp.c's probe within one second of power on. When we boot the
> board without a psbatt, and no internet connection (which means
> systemd-timesyncd cannot fix the bunkers date), we were ending up with a date in
> the very distant future (>50 years into the future). Aside from the date in our
> UI, all our SSL connections were failing because of certificate dates. This got
> our attention.
> 
> We drilled down quite a lot to find the real root cause. We used JTAG with xsct
> with our board simply powered on but not booted (bootselect SD without an SD
> card). This means no FSBL/psu_init code has run.
> 
> Exhibit A:
> 
> xsct% rrd rtc
>      set_time_write                  set_time_read: 00000000
>         calib_write                     calib_read: 00000000
>        current_time: 00000000                alarm: 00000000
>      rtc_int_status:       00         rtc_int_mask:       03
>          rtc_int_en                    rtc_int_dis
>          addr_error:       00  addr_error_int_mask:       01
>   addr_error_int_en             addr_error_int_dis
>             control: 01000000           safety_chk: 00000000
> 
> 
> Then we enable the RTC:
> 
> xsct% rwr rtc control 0x81000000
> 

Doesn't that enable battery switchover instead of simply enabling the
rtc, I though you didn't have a battery.

Or does that mean that your previous read of control returning bit 24
set is also bogus?

I ask because the simpler solution would simply to return -EINVAL in
xlnx_rtc_read_time when you detect a power on condition.

> The counter now counts, set_time_read and calib_read are garbage:
> xsct% rrd rtc
>      set_time_write                  set_time_read: fffe6bff
>         calib_write                     calib_read: 000f7fff
>        current_time: 00000002                alarm: 00000000
>      rtc_int_status:       01         rtc_int_mask:       03
>          rtc_int_en                    rtc_int_dis
>          addr_error:       00  addr_error_int_mask:       01
>   addr_error_int_en             addr_error_int_dis
>             control: 81000000           safety_chk: 00000000
> xsct% rrd rtc
>      set_time_write                  set_time_read: fffe6bff
>         calib_write                     calib_read: 000f7fff
>        current_time: 00000005                alarm: 00000000
>      rtc_int_status:       01         rtc_int_mask:       03
>          rtc_int_en                    rtc_int_dis
>          addr_error:       00  addr_error_int_mask:       01
>   addr_error_int_en             addr_error_int_dis
>             control: 81000000           safety_chk: 00000000
> xsct% rrd rtc
>      set_time_write                  set_time_read: fffe6bff
>         calib_write                     calib_read: 000f7fff
>        current_time: 00000008                alarm: 00000000
>      rtc_int_status:       01         rtc_int_mask:       03
>          rtc_int_en                    rtc_int_dis
>          addr_error:       00  addr_error_int_mask:       01
>   addr_error_int_en             addr_error_int_dis
>             control: 81000000           safety_chk: 00000000
> 
> We tested further, inserted a psbatt, enabled the RTC, but never touched
> set_time_write. Powered our board on and off. The observations is that that
> set_time_read and calib_read registers are not initialized to 0x0 upon power on.
> Once set though, they keep their values as long as the system is powered on or
> psbatt keeps the RTC alive. This is a contradiction of the register POR values
> specification.
> 
> So for rtc-zynqmp.c, it means that using the set_time_read register is a bad
> idea unless the code can definitely say that the set_time_write has been written
> to. And this is exactly what our patch does, by use of the seconds interrupt
> being enabled which signals the read_time() function that there is a pending
> write, and therefore the set_time_read can reliably be read.
> 
> Hope this helps!
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2019-11-28 17:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-28  1:56 [PATCH 1/2] rtc: zynqmp: re-use rtc_time64_to_tm operation Jean-Francois Dagenais
2019-11-28  1:56 ` [PATCH 2/2] rtc: zynqmp: fix invalid read_time before 1 second Jean-Francois Dagenais
2019-11-28  8:19   ` Michal Simek
2019-11-28 16:04     ` Jean-Francois Dagenais
2019-11-28 17:29       ` Alexandre Belloni [this message]
2019-11-29 14:45         ` Jean-Francois Dagenais
2019-11-29 15:14           ` Alexandre Belloni
2019-11-29 15:48             ` Jean-Francois Dagenais
2019-11-28  8:16 ` [PATCH 1/2] rtc: zynqmp: re-use rtc_time64_to_tm operation Michal Simek
2019-12-10 15:50 ` Alexandre Belloni

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=20191128172957.GS299836@piout.net \
    --to=alexandre.belloni@bootlin.com \
    --cc=Mathieu.Gallichand@sonatest.com \
    --cc=a.zummo@towertech.it \
    --cc=champagne.guillaume.c@gmail.com \
    --cc=git@xilinx.com \
    --cc=jeff.dagenais@gmail.com \
    --cc=linux-rtc@vger.kernel.org \
    --cc=maxime.roussinbelanger@gmail.com \
    --cc=michal.simek@xilinx.com \
    --cc=sgoud@xilinx.com \
    /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;
as well as URLs for NNTP newsgroup(s).