[PATCH v2] armv8: implement workaround for broken CNTFRQ_EL0 value

Tom Rini trini at konsulko.com
Fri Oct 17 22:40:40 CEST 2025


On Fri, Oct 17, 2025 at 08:49:47PM +0530, Kaustabh Chakraborty wrote:

> In devices where the U-Boot is used as a secondary bootloader, we rely
> on the device's primary bootloader to implement CNTFRQ_EL0. However,
> this reliance may lead to a non-functional timer in broken firmware.
> 
> For instance, some versions of Samsung's S-Boot don't implement it. It's
> also not possible to set it in the U-Boot, because it's booted in a lower
> exception level. CNTFRQ_EL0 is reported to be 0.
> 
> Use gd->arch.timer_rate_hz to override the queried value if set. This
> setting needs to be done in the board file, preferrably in timer_init().
> 
> Signed-off-by: Kaustabh Chakraborty <kauschluss at disroot.org>
> ---
> Changes in v2:
> - Switched to using gd->arch.timer_rate_hz instead of a new config
>   option (Ahmad Fatoum)
> - Link to v1: https://lore.kernel.org/r/20251014-armv8-broken-cntfrq-v1-1-b63f9c69ffcb@disroot.org
> ---
>  arch/arm/cpu/armv8/generic_timer.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/arm/cpu/armv8/generic_timer.c b/arch/arm/cpu/armv8/generic_timer.c
> index 1de7ec596fc7cbbc3e78a241f163bc0a4fcad6b6..1bc72ed26ca31af8e8e72008ed7885cbde23b076 100644
> --- a/arch/arm/cpu/armv8/generic_timer.c
> +++ b/arch/arm/cpu/armv8/generic_timer.c
> @@ -19,6 +19,10 @@ DECLARE_GLOBAL_DATA_PTR;
>  unsigned long notrace get_tbclk(void)
>  {
>  	unsigned long cntfrq;
> +
> +	if (gd->arch.timer_rate_hz)
> +		return gd->arch.timer_rate_hz;
> +
>  	asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq));
>  	return cntfrq;
>  }

This would impact coreprimevelte (as it's the only ARM64 platform to set
gd->arch.timer_rate_hz) but as it's also a Samsung platform it's likely
in the same broken situation your platforms are.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20251017/e3bbf10c/attachment.sig>


More information about the U-Boot mailing list