Hello Kaustabh, On 14.10.25 09:22, 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. > > Thus, the only solution is to add a config option which, when enabled, > returns a hard coded value (CONFIG_COUNTER_FREQUENCY) instead of querying > CNTFRQ_EL0.
Why not read it from the clock-frequency property in the device tree? This is what barebox is now doing, incidentally also for Samsung support, see: https://lore.kernel.org/barebox/[email protected]/ Cheers, Ahmad > > Signed-off-by: Kaustabh Chakraborty <[email protected]> > --- > arch/arm/cpu/armv8/Kconfig | 9 +++++++++ > arch/arm/cpu/armv8/generic_timer.c | 4 ++++ > 2 files changed, 13 insertions(+) > > diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig > index > 199335cd6040d30a355a7fd5448a449fa7f550fb..d54d874b7caea200e1c05f522d8affe6d239a102 > 100644 > --- a/arch/arm/cpu/armv8/Kconfig > +++ b/arch/arm/cpu/armv8/Kconfig > @@ -4,6 +4,15 @@ config CMO_BY_VA_ONLY > bool "Force cache maintenance to be exclusively by VA" > depends on !SYS_DISABLE_DCACHE_OPS > > +config ARMV8_CNTFRQ_BROKEN > + bool "Fix broken ARMv8 generic timer" > + depends on COUNTER_FREQUENCY > 0 > + depends on SYS_ARCH_TIMER > + help > + Say Y here if there is no trustable firmware present which sets > + CNTFRQ_EL0 frequency before U-Boot. U-Boot will use the > + CONFIG_COUNTER_FREQUENCY value as the reported frequency. > + > config ARMV8_SPL_EXCEPTION_VECTORS > bool "Install crash dump exception vectors" > depends on SPL > diff --git a/arch/arm/cpu/armv8/generic_timer.c > b/arch/arm/cpu/armv8/generic_timer.c > index > 1de7ec596fc7cbbc3e78a241f163bc0a4fcad6b6..409570cf6fda79527e296b958368b552900524b1 > 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 (IS_ENABLED(CONFIG_ARMV8_CNTFRQ_BROKEN)) > + return CONFIG_COUNTER_FREQUENCY; > + > asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq)); > return cntfrq; > } > > --- > base-commit: a5b3be1a37e19646b9d36c91f11b23f568be4f21 > change-id: 20251014-armv8-broken-cntfrq-f350f68fbf6e > > Best regards, -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

