diff --git a/Cargo.lock b/Cargo.lock index a68b25b1..3bff2fee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -646,8 +646,8 @@ dependencies = [ [[package]] name = "embedded-cfu-protocol" -version = "0.1.0" -source = "git+https://github.com/OpenDevicePartnership/embedded-cfu#ffb9041a2ec9ca7a411f3439f45eec3bc01b975b" +version = "0.2.0" +source = "git+https://github.com/OpenDevicePartnership/embedded-cfu#a4cc8707842b878048447abbf2af4efa79fed368" dependencies = [ "defmt 0.3.100", "embedded-io-async", diff --git a/Cargo.toml b/Cargo.toml index bd073d7a..b291921e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ embassy-sync = { git = "https://github.com/embassy-rs/embassy" } embassy-time = { git = "https://github.com/embassy-rs/embassy" } embassy-time-driver = { git = "https://github.com/embassy-rs/embassy" } embedded-batteries-async = "0.1.0" -embedded-cfu-protocol = { git = "https://github.com/OpenDevicePartnership/embedded-cfu", version = "0.1.0" } +embedded-cfu-protocol = { git = "https://github.com/OpenDevicePartnership/embedded-cfu", version = "0.2.0" } embedded-hal = "1.0" embedded-hal-async = "1.0" embedded-hal-nb = "1.0" diff --git a/cfu-service/src/host.rs b/cfu-service/src/host.rs index de9b1564..c86e215e 100644 --- a/cfu-service/src/host.rs +++ b/cfu-service/src/host.rs @@ -3,30 +3,31 @@ use core::future::Future; use embedded_cfu_protocol::components::CfuComponentTraits; use embedded_cfu_protocol::host::{CfuHostStates, CfuUpdater}; use embedded_cfu_protocol::protocol_definitions::*; -use embedded_cfu_protocol::{CfuImage, CfuWriter, CfuWriterDefault, CfuWriterError}; +use embedded_cfu_protocol::{ + CfuImage, + writer::{CfuWriterAsync, CfuWriterError, CfuWriterNop}, +}; use heapless::Vec; use crate::CfuError; /// All host side Cfu traits, in some cases this will originate from a OS driver for CFU -pub trait CfuHost: CfuHostStates { +pub trait CfuHost: CfuHostStates { /// Get all images fn get_cfu_images(&self) -> impl Future, CfuError>>; /// Gets the firmware version of all components - fn get_all_fw_versions( + fn get_all_fw_versions( self, - writer: &mut T, + writer: &mut W, primary_cmpt: ComponentId, ) -> impl Future>; /// Goes through the offer list and returns a slice of offer responses - fn process_cfu_offers<'a, T: CfuWriter>( + fn process_cfu_offers<'a>( offer_commands: &'a [FwUpdateOffer], - writer: &mut T, + writer: &mut W, ) -> impl Future>; /// For a specific component, update its content - fn update_cfu_content( - writer: &mut T, - ) -> impl Future>; + fn update_cfu_content(writer: &mut W) -> impl Future>; /// For a specific image that was updated, validate its content fn is_cfu_image_valid(image: I) -> impl Future>; } @@ -34,7 +35,7 @@ pub trait CfuHost: CfuHostStates { pub struct CfuHostInstance { pub updater: CfuUpdater, pub images: heapless::Vec, - pub writer: CfuWriterDefault, + pub writer: CfuWriterNop, pub primary_cmpt: C, pub host_token: HostToken, } @@ -45,15 +46,15 @@ impl CfuHostInstance { Self { updater: CfuUpdater {}, images: Vec::new(), - writer: CfuWriterDefault::default(), + writer: CfuWriterNop, primary_cmpt, host_token: HostToken::Driver, } } } -impl CfuHostStates for CfuHostInstance { - async fn start_transaction(self, _writer: &mut T) -> Result { +impl CfuHostStates for CfuHostInstance { + async fn start_transaction(self, _writer: &mut W) -> Result { let _mock_cmd = FwUpdateOfferInformation::new(OfferInformationComponentInfo::new( HostToken::Driver, SpecialComponentIds::Info, @@ -62,10 +63,7 @@ impl CfuHostStates for CfuHostInstance let mockresponse = FwUpdateOfferResponse::default(); Ok(mockresponse) } - async fn notify_start_offer_list( - self, - writer: &mut T, - ) -> Result { + async fn notify_start_offer_list(self, writer: &mut W) -> Result { // Serialize FwUpdateOfferInformation to bytes let mock_cmd = FwUpdateOfferInformation::new(OfferInformationComponentInfo::new( HostToken::Driver, @@ -89,10 +87,7 @@ impl CfuHostStates for CfuHostInstance } } - async fn notify_end_offer_list( - self, - writer: &mut T, - ) -> Result { + async fn notify_end_offer_list(self, writer: &mut W) -> Result { let mock_cmd = FwUpdateOfferInformation::new(OfferInformationComponentInfo::new( HostToken::Driver, SpecialComponentIds::Info, @@ -128,14 +123,14 @@ impl CfuHostStates for CfuHostInstance } } -impl CfuHost for CfuHostInstance { +impl CfuHost for CfuHostInstance { async fn get_cfu_images(&self) -> Result, CfuError> { Err(CfuError::BadImage) } - async fn get_all_fw_versions( + async fn get_all_fw_versions( self, - _writer: &mut T, + _writer: &mut W, primary_cmpt: ComponentId, ) -> Result { let mut component_count: u8 = 0; @@ -172,15 +167,15 @@ impl CfuHost for CfuHostInstance { } } - async fn process_cfu_offers<'a, T: CfuWriter>( + async fn process_cfu_offers<'a>( _offer_commands: &'a [FwUpdateOffer], - _writer: &mut T, + _writer: &mut W, ) -> Result<&'a [FwUpdateOfferResponse], CfuError> { // TODO Err(CfuError::BadImage) } - async fn update_cfu_content(_writer: &mut T) -> Result { + async fn update_cfu_content(_writer: &mut W) -> Result { Err(CfuError::ProtocolError(CfuProtocolError::WriterError( CfuWriterError::Other, ))) diff --git a/cfu-service/src/lib.rs b/cfu-service/src/lib.rs index f3995bd5..21f69362 100644 --- a/cfu-service/src/lib.rs +++ b/cfu-service/src/lib.rs @@ -1,10 +1,12 @@ #![no_std] + use embassy_sync::once_lock::OnceLock; use embedded_cfu_protocol::client::CfuReceiveContent; +use embedded_cfu_protocol::components::CfuComponentTraits; use embedded_cfu_protocol::protocol_definitions::*; use embedded_services::cfu::component::*; use embedded_services::cfu::{CfuError, ContextToken}; -use embedded_services::{comms, error, info}; +use embedded_services::{comms, error, info, trace}; pub mod buffer; pub mod host; @@ -17,8 +19,21 @@ pub struct CfuClient { tp: comms::Endpoint, } -/// use default "do-nothing" implementations -impl CfuReceiveContent for CfuClient {} +impl CfuReceiveContent for CfuClient { + async fn process_command(&self, _args: Option, _cmd: C) -> Result<(), ()> { + trace!("CfuClient CfuReceiveContent::process_command do nothing implementation."); + Ok(()) + } + + async fn prepare_components( + &self, + _args: Option, + _primary_component: impl CfuComponentTraits, + ) -> Result<(), ()> { + trace!("CfuClient CfuReceiveContent::prepare_components do nothing implementation."); + Ok(()) + } +} impl CfuClient { /// Create a new Cfu Client diff --git a/embedded-service/src/cfu/component.rs b/embedded-service/src/cfu/component.rs index 0b5e3ff2..e7633a27 100644 --- a/embedded-service/src/cfu/component.rs +++ b/embedded-service/src/cfu/component.rs @@ -5,7 +5,7 @@ use embassy_sync::channel::Channel; use embassy_sync::mutex::Mutex; use embedded_cfu_protocol::components::{CfuComponentInfo, CfuComponentStorage, CfuComponentTraits}; use embedded_cfu_protocol::protocol_definitions::*; -use embedded_cfu_protocol::{CfuWriter, CfuWriterError}; +use embedded_cfu_protocol::writer::{CfuWriterAsync, CfuWriterError}; use heapless::Vec; use super::CfuError; @@ -173,7 +173,7 @@ impl CfuDevice { } /// Example for CFU Component -pub struct CfuComponentDefault { +pub struct CfuComponentDefault { device: CfuDevice, is_dual_bank: bool, is_primary: bool, @@ -182,19 +182,19 @@ pub struct CfuComponentDefault { writer: Mutex, } -impl Default for CfuComponentDefault { +impl Default for CfuComponentDefault { fn default() -> Self { Self::new(1, false, [None; MAX_SUBCMPT_COUNT], W::default()) } } -impl CfuDeviceContainer for CfuComponentDefault { +impl CfuDeviceContainer for CfuComponentDefault { fn get_cfu_component_device(&self) -> &CfuDevice { &self.device } } -impl CfuComponentDefault { +impl CfuComponentDefault { /// Constructor pub fn new( id: ComponentId, @@ -283,7 +283,7 @@ impl CfuComponentDefault { } } -impl CfuComponentInfo for CfuComponentDefault { +impl CfuComponentInfo for CfuComponentDefault { fn get_component_id(&self) -> ComponentId { self.device.component_id() } @@ -304,12 +304,12 @@ impl CfuComponentInfo for CfuComponentDefault { } } -impl CfuWriter for CfuComponentDefault { - async fn cfu_write(&self, mem_offset: Option, data: &[u8]) -> Result<(), CfuWriterError> { +impl CfuWriterAsync for CfuComponentDefault { + async fn cfu_write(&mut self, mem_offset: Option, data: &[u8]) -> Result<(), CfuWriterError> { self.writer.lock().await.cfu_write(mem_offset, data).await } async fn cfu_write_read( - &self, + &mut self, mem_offset: Option, data: &[u8], read: &mut [u8], @@ -317,12 +317,16 @@ impl CfuWriter for CfuComponentDefault { self.writer.lock().await.cfu_write_read(mem_offset, data, read).await } - async fn cfu_read(&self, mem_offset: Option, read: &mut [u8]) -> Result<(), CfuWriterError> { + async fn cfu_read(&mut self, mem_offset: Option, read: &mut [u8]) -> Result<(), CfuWriterError> { self.writer.lock().await.cfu_read(mem_offset, read).await } + + async fn cfu_storage(&mut self, mem_offset: usize, read: &[u8]) -> Result<(), CfuWriterError> { + self.writer.lock().await.cfu_storage(mem_offset, read).await + } } -impl CfuComponentStorage for CfuComponentDefault { +impl CfuComponentStorage for CfuComponentDefault { fn get_storage_offset(&self) -> usize { self.storage_offset } @@ -344,7 +348,7 @@ async fn default_get_fw_version() -> Result { Ok(FwVersion::default()) } -impl CfuComponentTraits for CfuComponentDefault {} +impl CfuComponentTraits for CfuComponentDefault {} /// Example Wrapper for CFU Component /// Takes type which implements `CFUComponentTraits` and `CfuDeviceContainer` diff --git a/examples/rt685s-evk/Cargo.toml b/examples/rt685s-evk/Cargo.toml index 2eca9c32..1a85f96a 100644 --- a/examples/rt685s-evk/Cargo.toml +++ b/examples/rt685s-evk/Cargo.toml @@ -47,7 +47,7 @@ futures = { version = "0.3.30", default-features = false, features = [ mimxrt600-fcb = "0.1.0" mimxrt685s-pac = { version = "*", features = ["rt", "critical-section"] } -embedded-cfu-protocol = { git = "https://github.com/OpenDevicePartnership/embedded-cfu" } +embedded-cfu-protocol = { git = "https://github.com/OpenDevicePartnership/embedded-cfu", version = "0.2.0"} embedded-services = { path = "../../embedded-service", features = ["defmt"] } power-button-service = { path = "../../power-button-service", features = [ "defmt", diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index 86fe1b9e..f1d2afd6 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml @@ -28,7 +28,7 @@ power-policy-service = { path = "../../power-policy-service", features = [ "log", ] } cfu-service = { path = "../../cfu-service", features = ["log"] } -embedded-cfu-protocol = { git = "https://github.com/OpenDevicePartnership/embedded-cfu" } +embedded-cfu-protocol = { git = "https://github.com/OpenDevicePartnership/embedded-cfu", version = "0.2.0" } embedded-batteries-async = "0.1.0" battery-service = { path = "../../battery-service", features = ["log"] }