From 69fd8a0064321b5e950dbd7a4719cbf40a96b275 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Sat, 26 Sep 2026 20:08:58 -0700 Subject: [PATCH] fix(timer): don't panic when the timer frequency is zero PlatformTimer::start panicked if the timer frequency was zero. On aarch64 the frequency comes from CNTFRQ_EL0, which some firmware leaves unprogrammed, and on x86_64 a Stall that returns immediately measures zero. The timer is only used for bootloader interface timestamps, so log a warning and report zero durations instead. --- crates/eficore/src/platform/timer.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/eficore/src/platform/timer.rs b/crates/eficore/src/platform/timer.rs index 55eb28a..7d8fffc 100644 --- a/crates/eficore/src/platform/timer.rs +++ b/crates/eficore/src/platform/timer.rs @@ -2,6 +2,7 @@ // Architecturally modified to support UEFI and remove x86 (32-bit) support. use core::time::Duration; +use log::warn; /// Support for aarch64 timers. #[cfg(target_arch = "aarch64")] @@ -35,7 +36,11 @@ impl TickFrequency { } /// Produce a duration from the provided elapsed `ticks` value. + /// If the frequency is unknown, the duration is zero. fn duration(&self, ticks: u64) -> Duration { + if self.ticks() == 0 { + return Duration::ZERO; + } let accuracy = self.nanos(); let nanos = ticks as f64 * accuracy; Duration::from_nanos(nanos as u64) @@ -56,9 +61,10 @@ fn arch_frequency() -> TickFrequency { let frequency = aarch64::frequency(); #[cfg(target_arch = "x86_64")] let frequency = x86_64::frequency(); - // If the frequency is 0, then something went very wrong and we should panic. + // Some firmware does not program the timer frequency. The timer is only used to report + // timestamps to the bootloader interface, so this should not prevent booting. if frequency.ticks() == 0 { - panic!("timer frequency is zero"); + warn!("timer frequency is zero, timestamps will not be reported"); } frequency }