Skip to content
Snippets Groups Projects

Add firmware version consistency check in Rust API

Merged Samuel Tardieu requested to merge rust-firmware-consistency into main
Files
5
@@ -9,6 +9,10 @@ use tele0592::{
use crate::elf_loader::Segment;
fn version_from_bytes((major, minor, patch): (u8, u8, u8)) -> Version {
Version::new(u64::from(major), u64::from(minor), u64::from(patch))
}
pub enum ActiveProgram {
Bootloader { version: Version },
Controller { version: Version, bootloader: bool },
@@ -55,11 +59,11 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
pub fn active_program(i2c: &mut I2c) -> Result<ActiveProgram> {
match i2c.who_am_i()? {
WhoAmI::Controller => Ok(ActiveProgram::Controller {
version: i2c.firmware_version()?,
version: version_from_bytes(i2c.firmware_version()?),
bootloader: i2c.firmware_features()?.has_bootloader_support(),
}),
WhoAmI::Bootloader => {
let version = i2c.firmware_version()?;
let version = version_from_bytes(i2c.firmware_version()?);
let fwupd_req = VersionReq::parse(env!("CARGO_PKG_VERSION"))?;
if !fwupd_req.matches(&version) {
log::warn!("Bootloader version {version} does not match requirement for firmware-updater {fwupd_req}");
Loading