From 2e2b7bb6442bda08e02e7e8a57a30f23a60533a1 Mon Sep 17 00:00:00 2001 From: Sven Rademakers Date: Fri, 3 Nov 2023 07:57:10 +0000 Subject: [PATCH 1/2] bmc_application: restore power and usb settings This commit contains 2 improvements: * Internal operations are not triggering persistency updates anymore. Minimizing flash wear. * After a flash command the power and USB settings are restored to their previous values --- src/app/bmc_application.rs | 25 ++++++++++++++++++------- src/app/firmware_runner.rs | 15 ++++----------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/app/bmc_application.rs b/src/app/bmc_application.rs index efd217a..d06455c 100644 --- a/src/app/bmc_application.rs +++ b/src/app/bmc_application.rs @@ -115,7 +115,7 @@ impl BmcApplication { self.initialize_power().await } - async fn initialize_power(&self) -> anyhow::Result<()> { + pub async fn initialize_power(&self) -> anyhow::Result<()> { if self.app_db.get::(ACTIVATED_NODES_KEY).await != 0 { self.power_on().await?; } @@ -187,7 +187,19 @@ impl BmcApplication { self.power_controller.set_power_node(0b0000, 0b1111).await } + pub async fn power_off_node(&self, node: NodeId) -> anyhow::Result<()> { + self.power_controller + .set_power_node(node.to_bitfield(), node.to_bitfield()) + .await + } + pub async fn configure_usb(&self, config: UsbConfig) -> anyhow::Result<()> { + self.configure_usb_internal(config).await?; + self.app_db.set(USB_CONFIG, config).await; + Ok(()) + } + + async fn configure_usb_internal(&self, config: UsbConfig) -> anyhow::Result<()> { log::debug!("changing usb config to {:?}", config); let (mode, dest, route) = match config { UsbConfig::UsbA(device) => (UsbMode::Device, device, UsbRoute::UsbA), @@ -197,7 +209,6 @@ impl BmcApplication { self.pin_controller.set_usb_route(route).await?; self.pin_controller.select_usb(dest, mode)?; - self.app_db.set(USB_CONFIG, config).await; Ok(()) } @@ -220,8 +231,6 @@ impl BmcApplication { } pub async fn set_node_in_msd(&self, node: NodeId, router: UsbRoute) -> anyhow::Result<()> { - // The SUPPORTED_MSD_DEVICES list contains vid_pids of USB drivers we know will load the - // storage of a node as a MSD device. self.configure_node_for_fwupgrade(node, router, SUPPORTED_DEVICES.keys()) .await .map(|_| ()) @@ -237,7 +246,8 @@ impl BmcApplication { I: IntoIterator, { log::info!("Powering off node {:?}...", node); - self.activate_slot(!node.to_bitfield(), node.to_bitfield()) + self.power_controller + .set_power_node(!node.to_bitfield(), node.to_bitfield()) .await?; self.pin_controller .set_usb_boot(!node.to_bitfield(), node.to_bitfield())?; @@ -249,10 +259,11 @@ impl BmcApplication { UsbRoute::UsbA => UsbConfig::UsbA(node), }; self.usb_boot(node, true).await?; - self.configure_usb(config).await?; + self.configure_usb_internal(config).await?; log::info!("Prerequisite settings toggled, powering on..."); - self.activate_slot(node.to_bitfield(), node.to_bitfield()) + self.power_controller + .set_power_node(node.to_bitfield(), node.to_bitfield()) .await?; tokio::time::sleep(Duration::from_secs(1)).await; diff --git a/src/app/firmware_runner.rs b/src/app/firmware_runner.rs index 7cf2d77..91ec581 100644 --- a/src/app/firmware_runner.rs +++ b/src/app/firmware_runner.rs @@ -11,7 +11,6 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -use super::bmc_application::UsbConfig; use crate::app::bmc_application::BmcApplication; use crate::firmware_update::FwUpdateError; use crate::utils::{reader_with_crc64, WriteWatcher}; @@ -100,17 +99,11 @@ impl FirmwareRunner { bail!(FwUpdateError::ChecksumMismatch) } - log::info!("Flashing {node} successful, restarting device..."); - bmc.activate_slot(!node.to_bitfield(), node.to_bitfield()) - .await?; - - //TODO: we probably want to restore the state prior flashing + log::info!("Flashing {node} successful, restoring USB & power settings..."); + bmc.power_off_node(node).await?; bmc.usb_boot(node, false).await?; - bmc.configure_usb(UsbConfig::UsbA(node)).await?; - bmc.activate_slot(node.to_bitfield(), node.to_bitfield()) - .await?; - - Ok(()) + bmc.configure_usb(bmc.get_usb_mode().await).await?; + bmc.initialize_power().await } pub async fn os_update(self) -> anyhow::Result<()> { From f5d681ec20e698197b4ad5bc345c6062c77e26cd Mon Sep 17 00:00:00 2001 From: Sven Rademakers Date: Fri, 3 Nov 2023 08:42:41 +0000 Subject: [PATCH 2/2] fix power init --- src/api/streaming_data_service.rs | 2 +- src/app/bmc_application.rs | 5 +++-- src/main.rs | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/streaming_data_service.rs b/src/api/streaming_data_service.rs index e4357a6..f3ea483 100644 --- a/src/api/streaming_data_service.rs +++ b/src/api/streaming_data_service.rs @@ -59,7 +59,7 @@ impl StreamingDataService { let (written_sender, written_receiver) = watch::channel(0u64); let cancel = CancellationToken::new(); let (sender, worker) = action - .into_data_processor(64, written_sender, cancel.child_token()) + .into_data_processor(256, written_sender, cancel.child_token()) .await?; let context = TransferContext::new(id, process_name, size, written_receiver, sender, cancel); diff --git a/src/app/bmc_application.rs b/src/app/bmc_application.rs index d06455c..e51cf15 100644 --- a/src/app/bmc_application.rs +++ b/src/app/bmc_application.rs @@ -117,9 +117,10 @@ impl BmcApplication { pub async fn initialize_power(&self) -> anyhow::Result<()> { if self.app_db.get::(ACTIVATED_NODES_KEY).await != 0 { - self.power_on().await?; + self.power_on().await + } else { + self.power_off().await } - Ok(()) } async fn initialize_usb_mode(&self) -> anyhow::Result<()> { diff --git a/src/main.rs b/src/main.rs index b21875b..6d7a506 100644 --- a/src/main.rs +++ b/src/main.rs @@ -118,7 +118,6 @@ fn init_logger() { simple_logger::SimpleLogger::new() .with_level(level) - .with_module_level("bmcd", LevelFilter::Info) .with_module_level("actix_http", LevelFilter::Info) .with_module_level("h2", LevelFilter::Info) .with_colors(true)