Skip to content

Formalize the trial-boot / commit / rollback capabilities as traits #377

Description

@rusty1968

fwmanager's BootControl doc already sketches this flow (set_trial → release → await_boot → commit),

pub enum BootProgress { Booted, Failed, Timeout }

pub trait BootMonitor {
    type Error: core::error::Error;
    fn await_boot(&mut self, window: core::time::Duration)
        -> Result<BootProgress, Self::Error>;
}

pub trait SlotControl {
    type Error: core::error::Error;
    fn set_trial(&mut self, slot: Slot) -> Result<(), Self::Error>;
    fn commit(&mut self, slot: Slot)    -> Result<(), Self::Error>;
    fn rollback(&mut self)              -> Result<(), Self::Error>;
}


fn trial_boot<D, M, S>(dev: &mut D, monitor: &mut M, store: &mut S, new_slot: Slot)
    -> Result<(), Error>
where
    D: BootControl,
    M: BootMonitor,
    S: SlotStore,
{
    dev.hold_in_reset()?;
    store.set_trial(new_slot)?;                 // tentative — not yet committed
    dev.release()?;                             // boot the trial image

    match monitor.await_boot(window)? {         // Ok(progress); Err only = couldn't watch
        BootProgress::Booted  => store.commit(new_slot)?,   // observed good => active
        BootProgress::Failed  => store.rollback()?,         // bad image => previous slot
        BootProgress::Timeout => store.rollback()?,         // went quiet => previous slot
    }
    Ok(())
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions