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

Error initializing driver: {}: {}

Error message

Error initializing driver: {}: {}

What it means

During init_drivers_and_irqs, the driver manager iterates its registered driver descriptors and calls init() on each device driver. If any driver's init() returns Err, the manager panics with the driver's compatible name and the driver's own error string. Because init runs early in the kernel bring-up with system-wide impact, failures are treated as unrecoverable.

Source

Thrown at 20_timer_callbacks/kernel/src/driver.rs:132

    }

    /// Register a device driver with the kernel.
    pub fn register_driver(&self, descriptor: DeviceDriverDescriptor<T>) {
        self.descriptors
            .write(|descriptors| descriptors.push(descriptor));
    }

    /// Fully initialize all drivers and their interrupts handlers.
    ///
    /// # Safety
    ///
    /// - During init, drivers might do stuff with system-wide impact.
    pub unsafe fn init_drivers_and_irqs(&self) {
        self.descriptors.read(|descriptors| {
            for descriptor in descriptors {
                // 1. Initialize driver.
                if let Err(x) = descriptor.device_driver.init() {
                    panic!(
                        "Error initializing driver: {}: {}",
                        descriptor.device_driver.compatible(),
                        x
                    );
                }

                // 2. Call corresponding post init callback.
                if let Some(callback) = &descriptor.post_init_callback {
                    if let Err(x) = callback() {
                        panic!(
                            "Error during driver post-init callback: {}: {}",
                            descriptor.device_driver.compatible(),
                            x
                        );
                    }
                }
            }

View on GitHub (pinned to 644474cc09)

Solutions

  1. Read the compatible name and error string in the panic message to identify which driver failed and why.
  2. Fix the driver's init() implementation so it succeeds on the target hardware (correct base address, clock, sequence).
  3. If the failing driver should not be present, remove its registration from the driver manager instead of letting init fail.
  4. Consider degrading to a warning for optional drivers whose init failure should not halt boot.

Example fix

// before
fn init(&self) -> Result<(), &'static str> {
    let base = 0x0; // wrong MMIO base
    self.probe(base)
}

// after
fn init(&self) -> Result<(), &'static str> {
    let base = self.mmio_base(); // correct per-board base
    self.probe(base)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Rust panics abort the kernel, so guard before calling:
// run driver self-checks before registering:
assert!(driver.is_probed(), "driver {} not probed before init", driver.compatible());

Try / catch

// panic! cannot be caught in kernel; instead make init() fallible and log:
if let Err(x) = descriptor.device_driver.init() {
    log_warn("driver init failed: {}: {}", descriptor.device_driver.compatible(), x);
    continue; // skip optional driver instead of panicking
}

Prevention

When it happens

Trigger: A registered driver's DeviceDriver::init() implementation returns Err(&str) while init_drivers_and_irqs() walks the descriptor list.

Common situations: Hardware probing fails at boot (missing device, wrong MMIO base address in config); an init routine detects an incompatible peripheral version; a driver tries to access a resource (clock, power domain, register) that is not yet available.

Related errors


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