pub enum SingleBootCommandDescription {
    Erase {
        start: u32,
        end: u32,
    },
    Load {
        file: String,
        src: u32,
        dst: u32,
        len: Option<u32>,
    },
    CheckNonsecureFirmwareVersion {
        version: u32,
    },
    CheckSecureFirmwareVersion {
        version: u32,
    },
}
Expand description

Commands used to define SB2.1 files

Currently, we only need to erase and load (partial) files.

Example

Since there does not seem to exit a command to enter the bootloader, but a corrupt / missing firmware makes the MCU enter the bootloader, one way to do so is the following specification, which erases the first flash page.

[[commands]]
cmd = "Erase"
start = 0
end = 512

Example

To securely flash firmware, it is advised to write the first page last, so that if flashing goes wrong or is interrupted, the MCU stays in the bootloader on next boot.

[[commands]]
cmd = "Erase"
start = 0
end = 0x8_9800

[[commands]]
# write firmware, skipping first flash page
cmd = "Load"
file = "example.sb2"
src = 512
dst = 512

[[commands]]
# write first flash page of firmware
cmd = "Load"
file = "example.sb2"
len = 512

Variants

Erase

Fields

start: u32
end: u32

Maps to BootCommand::EraseRegion, but start and end are given in bytes.

Load

Fields

file: String
src: u32

source offset in bytes (default 0)

dst: u32

destination offset in bytes (default 0)

len: Option<u32>

number of bytes to copy

Load (part) of the data reference in source to flash.

The syntax is such that if source data and destination flash were slices src: &[u8] and dst: &mut [u8], this command would do:

let src_len = src.len() - cmd.src;
let len = cmd.len.unwrap_or(src_len);
dst[cmd.dst..][..len].copy_from_slice(&src[cmd.src..][..len]);

CheckNonsecureFirmwareVersion

Fields

version: u32

CheckSecureFirmwareVersion

Fields

version: u32

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.