Skip to main content

tinyboot_core/traits/
mod.rs

1/// App-side boot client interface.
2pub mod app;
3/// Boot-side platform traits.
4pub mod boot;
5
6/// Boot target after a system reset.
7#[derive(Debug, Clone, Copy, PartialEq)]
8pub enum BootMode {
9    /// Boot the application.
10    App,
11    /// Enter the bootloader.
12    Bootloader,
13}
14
15/// Current stage in the firmware update lifecycle.
16///
17/// Each state is a contiguous run of 1-bits from bit 0.
18/// Advancing clears the MSB: `next = state & (state >> 1)`.
19///
20/// ```text
21/// 0xFF  Idle        (8 ones)
22/// 0x7F  Updating    (7 ones)
23/// 0x3F  Validating  (6 ones)
24/// ```
25#[derive(Debug, Clone, Copy, PartialEq)]
26#[repr(u8)]
27pub enum BootState {
28    /// No update in progress. Normal app boot. Erased flash default.
29    Idle = 0xFF,
30    /// Firmware transfer in progress.
31    Updating = 0x7F,
32    /// New firmware written, trial booting the app.
33    Validating = 0x3F,
34}
35
36impl BootState {
37    /// Parse a raw byte into a [`BootState`]. Unrecognised values default to [`Idle`](BootState::Idle).
38    pub fn from_u8(v: u8) -> Self {
39        match v {
40            0xFF | 0x7F | 0x3F => unsafe { core::mem::transmute::<u8, BootState>(v) },
41            _ => BootState::Idle,
42        }
43    }
44}