{"record":{"id":"45ef9030d7498928","repo":"rust-embedded/rust-raspberrypi-OS-tutorials","slug":"error-initializing-timer-subsystem","errorCode":null,"errorMessage":"Error initializing timer subsystem: {}","messagePattern":"Error initializing timer subsystem: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"20_timer_callbacks/kernel/src/main.rs","lineNumber":35,"sourceCode":"\nuse libkernel::{bsp, cpu, driver, exception, info, memory, state, time};\n\n/// Early init code.\n///\n/// When this code runs, virtual memory is already enabled.\n///\n/// # Safety\n///\n/// - Only a single core must be active and running this function.\n/// - Printing will not work until the respective driver's MMIO is remapped.\n#[no_mangle]\nunsafe fn kernel_init() -> ! {\n    exception::handling_init();\n    memory::init();\n\n    // Initialize the timer subsystem.\n    if let Err(x) = time::init() {\n        panic!(\"Error initializing timer subsystem: {}\", x);\n    }\n\n    // Initialize the BSP driver subsystem.\n    if let Err(x) = bsp::driver::init() {\n        panic!(\"Error initializing BSP driver subsystem: {}\", x);\n    }\n\n    // Initialize all device drivers.\n    driver::driver_manager().init_drivers_and_irqs();\n\n    bsp::memory::mmu::kernel_add_mapping_records_for_precomputed();\n\n    // Unmask interrupts on the boot CPU core.\n    exception::asynchronous::local_irq_unmask();\n\n    // Announce conclusion of the kernel_init() phase.\n    state::state_manager().transition_to_single_core_main();\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/blob/644474cc09f755249f9c55d99a5d1e07a2562fc7/20_timer_callbacks/kernel/src/main.rs#L17-L53","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the wrapped '{}' cause in the panic message to identify which timer driver failed and fix that root error.","Verify the active BSP implements time::init() with a valid timer driver for the target platform (e.g. QEMU's ARM generic timer).","Check that the timer's MMIO base address/IRQ numbers in the BSP match the machine you are running on.","Run in QEMU with the expected machine type (e.g. -M raspi3 / virt) matching the compiled BSP."],"exampleFix":"// before: wrong BSP timer for platform\n// cargo build for bsp rpi3 but run with -M virt\nqemu-system-aarch64 -M virt -kernel kernel8.elf\n// after: build matching BSP\n// RUST_TARGET_BSP=rpi3 ... then\nqemu-system-aarch64 -M raspi3 -kernel kernel8.elf","handlingStrategy":"fallback","validationCode":"// Pre-flight: confirm the BSP provides a timer driver for this target\n#[cfg(not(feature = \"bsp_rpi3\"))] compile_error!(\"Select a BSP with a timer driver\");","typeGuard":null,"tryCatchPattern":"// In no_std kernels panics are unrecoverable; capture the cause in a debug log before the panic\nif let Err(x) = time::init() {\n    sys_println!(\"timer init failed: {}\", x);\n    panic!(\"Error initializing timer subsystem: {}\", x);\n}","preventionTips":["Match the compiled BSP to the actual machine/QEMU model.","Log the wrapped error before panicking so root cause is visible.","Test timer init early in CI with the same QEMU flags as local runs."],"tags":["kernel","timer","boot","initialization","panic"],"backgroundTag":"module-init-failed","analyzedSha":"644474cc09f755249f9c55d99a5d1e07a2562fc7","analyzedAt":"2026-09-06T09:25:56.584Z","contentChangedAt":"2026-09-06T09:25:56.584Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}