[PATCH v2] time: Fix get_ticks being non-monotonic

Sean Anderson
2021-03-01T23:02:13Z

On 3/1/21 11:40 AM, Michael Opdenacker wrote:
> Hi Simon,
>
> I'm back working on this old issue. Thanks for your help with this!
>
> So, SPL support for Atmel/Microchip SAMA5D3 is still broken in the
> latest mainline, at least for the Xplained board with the MMC configuration.
>
> My comments and further questions below...
>
> On 11/22/20 12:07 AM, Simon Glass wrote:
>> Hi Michael,
>>
>> On Thu, 19 Nov 2020 at 04:23, Michael Opdenacker
>> <michael.opdenacker@bootlin.com> wrote:
>>> Hi,
>>>
>>> Sorry, no messaging quoting, I was not subscribed to the list at that time.
>>>
>>> Merging this change into master actually broke the SPL on
>>> Atmel/Microchip SAMA5D3, at least booting from MMC:
>>>
>>> RomBOOT
>>>
>>> <debug_uart>
>>> Could not initialize timer (err -11)
>>>
>>> Could not initialize timer (err -11)
>>>
>>> Could not initialize timer (err -11)
>>> ...
>>>
>>> I'll look for a fix, but suggestions are welcome!
>
>
> Now, it's:
>
> Could not initialize timer (err -19)
> (-19 is -ENODEV /* No such device */)
>
>> The board might need CONFIG_TIMER_EARLY, but otherwise I think it is a
>> case of figuring out why the timer is used before it is available.
>
>
> I tried to enable CONFIG_TIMER_EARLY but it fails at link time:
>
> LD u-boot
> arm-linux-ld.bfd: lib/built-in.o: in function `get_tbclk':
> /home/mike/work/git/git.denx.de/u-boot/lib/time.c:70: undefined
> reference to `timer_early_get_rate'
> arm-linux-ld.bfd: lib/built-in.o: in function `get_ticks':
> /home/mike/work/git/git.denx.de/u-boot/lib/time.c:90: undefined
> reference to `timer_early_get_count'
> make: *** [Makefile:1765: u-boot] Error 1
>
>
> This is not a surprise, as according to
> https://elixir.bootlin.com/u-boot/latest/C/ident/timer_early_get_rate,
> timer_early_get_rate() is not implemented on ARM, only on sandbox
> (drivers/timer/sandbox_timer.c) and on x86 (drivers/timer/tsc_timer.c).

It is also available on most RISC-V boards, not that it helps :)

>
> So, I'm moving to your second suggestion...
>
>
>>
>> You can use dm_dump_all() to print out available devices and whether
>> they are probed.
>
>
> Done, I added dm_dump_all to lib/time.c right before the panic() message:
>
> Class Index Probed Driver Name
> -----------------------------------------------------------
> root 0 [ + ] root_driver root_driver
> simple_bus 0 [ ] simple_bus `-- ahb
> simple_bus 1 [ ] simple_bus `-- apb
> mmc 0 [ ] atmel-mci |-- mmc at f0000000
> blk 0 [ ] mmc_blk | `-- mmc at f0000000.blk
> mmc 1 [ ] atmel-mci |-- mmc at f8000000
> blk 1 [ ] mmc_blk | `-- mmc at f8000000.blk
> serial 0 [ ] serial_atmel |-- serial at ffffee00
> pinctrl 0 [ ] atmel_sama5d3_pinctrl |-- pinctrl at fffff200
> pinconfig 0 [ ] pinconfig | |-- dbgu
> pinconfig 1 [ ] pinconfig | | `-- dbgu-0
> pinconfig 2 [ ] pinconfig | |-- mmc0
> pinconfig 3 [ ] pinconfig | | |-- mmc0_clk_cmd_dat0
> pinconfig 4 [ ] pinconfig | | |-- mmc0_dat1_3
> pinconfig 5 [ ] pinconfig | | `-- mmc0_dat4_7
> pinconfig 6 [ ] pinconfig | |-- mmc1
> pinconfig 7 [ ] pinconfig | | |-- mmc1_clk_cmd_dat0
> pinconfig 8 [ ] pinconfig | | `-- mmc1_dat1_3
> pinconfig 9 [ ] pinconfig | |-- spi0
> pinconfig 10 [ ] pinconfig | | `-- spi0-0
> pinconfig 11 [ ] pinconfig | |-- spi1
> pinconfig 12 [ ] pinconfig | | `-- spi1-0
> pinconfig 13 [ ] pinconfig | `-- board
> pinconfig 14 [ ] pinconfig | |-- mmc0_cd
> pinconfig 15 [ ] pinconfig | `-- mmc1_cd
> gpio 0 [ ] atmel_at91rm9200_gpio |-- gpio at fffff200
> gpio 1 [ ] atmel_at91rm9200_gpio |-- gpio at fffff400
> gpio 2 [ ] atmel_at91rm9200_gpio |-- gpio at fffff600
> gpio 3 [ ] atmel_at91rm9200_gpio |-- gpio at fffff800
> gpio 4 [ ] atmel_at91rm9200_gpio |-- gpio at fffffa00
> simple_bus 2 [ ] at91-pmc `-- pmc at fffffc00
> clk 0 [ ] at91sam9x5-utmi-clk |-- utmick
> clk 1 [ ] at91-master-clk |-- masterck
> misc 0 [ ] sam9x5-periph-clk `-- periphck
> clk 2 [ ] periph-clk |-- dbgu_clk at 2
> clk 3 [ ] periph-clk |-- pioA_clk at 6
> clk 4 [ ] periph-clk |-- pioB_clk at 7
> clk 5 [ ] periph-clk |-- pioC_clk at 8
> clk 6 [ ] periph-clk |-- pioD_clk at 9
> clk 7 [ ] periph-clk |-- pioE_clk at 10
> clk 8 [ ] periph-clk |-- mci0_clk at 21
> clk 9 [ ] periph-clk |-- mci1_clk at 22
> clk 10 [ ] periph-clk |-- spi0_clk at 24
> clk 11 [ ] periph-clk `-- spi1_clk at 25
> Could not initialize timer (err -19)

So nothing here is probed, but additionally nothing has UCLASS_TIMER.
What do you expect the timer device to be?

--Sean

>
> I'm not familiar enough with U-Boot yet (and with SAMA5D3 support
> either) to see why the timer device is missing here, but I hope our
> Microchip friends can give us further clues...
>
> Thanks again,
>
> Cheers,
>
> Michael.
>