rust-embedded/rust-raspberrypi-OS-tutorials · critical

Error initializing timer subsystem: {}

Error message

Error initializing timer subsystem: {}

What it means

kernel_init() aborts boot when time::init() returns Err, panicking with "Error initializing timer subsystem: {}" and the underlying error. This guards the invariant that the kernel cannot run without a functioning timer subsystem. The panic message wraps the real cause (e.g. driver init failure) returned from the timer layer.

Source

Thrown at 20_timer_callbacks/kernel/src/main.rs:35

use libkernel::{bsp, cpu, driver, exception, info, memory, state, time};

/// Early init code.
///
/// When this code runs, virtual memory is already enabled.
///
/// # Safety
///
/// - Only a single core must be active and running this function.
/// - Printing will not work until the respective driver's MMIO is remapped.
#[no_mangle]
unsafe fn kernel_init() -> ! {
    exception::handling_init();
    memory::init();

    // Initialize the timer subsystem.
    if let Err(x) = time::init() {
        panic!("Error initializing timer subsystem: {}", x);
    }

    // Initialize the BSP driver subsystem.
    if let Err(x) = bsp::driver::init() {
        panic!("Error initializing BSP driver subsystem: {}", x);
    }

    // Initialize all device drivers.
    driver::driver_manager().init_drivers_and_irqs();

    bsp::memory::mmu::kernel_add_mapping_records_for_precomputed();

    // Unmask interrupts on the boot CPU core.
    exception::asynchronous::local_irq_unmask();

    // Announce conclusion of the kernel_init() phase.
    state::state_manager().transition_to_single_core_main();

View on GitHub (pinned to 644474cc09)

Solutions

  1. Read the wrapped '{}' cause in the panic message to identify which timer driver failed and fix that root error.
  2. Verify the active BSP implements time::init() with a valid timer driver for the target platform (e.g. QEMU's ARM generic timer).
  3. Check that the timer's MMIO base address/IRQ numbers in the BSP match the machine you are running on.
  4. Run in QEMU with the expected machine type (e.g. -M raspi3 / virt) matching the compiled BSP.

Example fix

// before: wrong BSP timer for platform
// cargo build for bsp rpi3 but run with -M virt
qemu-system-aarch64 -M virt -kernel kernel8.elf
// after: build matching BSP
// RUST_TARGET_BSP=rpi3 ... then
qemu-system-aarch64 -M raspi3 -kernel kernel8.elf
Defensive patterns

Strategy: fallback

Validate before calling

// Pre-flight: confirm the BSP provides a timer driver for this target
#[cfg(not(feature = "bsp_rpi3"))] compile_error!("Select a BSP with a timer driver");

Try / catch

// In no_std kernels panics are unrecoverable; capture the cause in a debug log before the panic
if let Err(x) = time::init() {
    sys_println!("timer init failed: {}", x);
    panic!("Error initializing timer subsystem: {}", x);
}

Prevention

When it happens

Trigger: time::init() returns Err, typically because the BSP timer driver's init (e.g. QEMU/generic timer bring-up) failed, returned an error string, or a required device was missing.

Common situations: Running on hardware/QEMU where the expected system timer is absent or misconfigured; a BSP driver_init for the timer returning Err; changes to the BSP that removed or renamed the timer driver.

Related errors


AI-assisted analysis of rust-embedded/rust-raspberrypi-OS-tutorials@644474cc09 (2026-09-06). Data as JSON: /api/errors/45ef9030d7498928. Report an issue: GitHub.