From 6b9817fbd0791a410895887e8d936269be9b39ca Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Fri, 5 Apr 2024 11:14:20 -0400 Subject: [PATCH] Move sp_update and rot_update to MgsCommon --- task/control-plane-agent/src/mgs_common.rs | 17 ++++++++++--- task/control-plane-agent/src/mgs_gimlet.rs | 24 +++++++++--------- task/control-plane-agent/src/mgs_psc.rs | 23 ++++++++++-------- task/control-plane-agent/src/mgs_sidecar.rs | 27 ++++++++++----------- 4 files changed, 51 insertions(+), 40 deletions(-) diff --git a/task/control-plane-agent/src/mgs_common.rs b/task/control-plane-agent/src/mgs_common.rs index e6c136a3c..bb45ab4da 100644 --- a/task/control-plane-agent/src/mgs_common.rs +++ b/task/control-plane-agent/src/mgs_common.rs @@ -2,7 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::{inventory::Inventory, Log, MgsMessage}; +use crate::{ + inventory::Inventory, update::rot::RotUpdate, update::sp::SpUpdate, Log, + MgsMessage, +}; use drv_caboose::{CabooseError, CabooseReader}; use drv_sprot_api::{ CabooseOrSprotError, RotState as SprotRotState, SpRot, SprotError, @@ -30,24 +33,30 @@ task_slot!(pub UPDATE_SERVER, update_server); /// Provider of MGS handler logic common to all targets (gimlet, sidecar, psc). pub(crate) struct MgsCommon { + pub sp_update: SpUpdate, + pub rot_update: RotUpdate, + reset_component_requested: Option, inventory: Inventory, base_mac_address: MacAddress, packrat: Packrat, sprot: SpRot, - sp_update: Update, + update_sp: Update, sensor: Sensor, } impl MgsCommon { pub(crate) fn claim_static_resources(base_mac_address: MacAddress) -> Self { Self { + sp_update: SpUpdate::new(), + rot_update: RotUpdate::new(), + reset_component_requested: None, inventory: Inventory::new(), base_mac_address, packrat: Packrat::from(PACKRAT.get_task_id()), sprot: SpRot::from(SPROT.get_task_id()), - sp_update: Update::from(UPDATE_SERVER.get_task_id()), + update_sp: Update::from(UPDATE_SERVER.get_task_id()), sensor: Sensor::from(SENSOR.get_task_id()), } } @@ -162,7 +171,7 @@ impl MgsCommon { } 1 => { let len = self - .sp_update + .update_sp .read_caboose_value(key, buf) .map_err(caboose_to_sp_error)?; Ok(len as usize) diff --git a/task/control-plane-agent/src/mgs_gimlet.rs b/task/control-plane-agent/src/mgs_gimlet.rs index ae03c797a..ffeca002f 100644 --- a/task/control-plane-agent/src/mgs_gimlet.rs +++ b/task/control-plane-agent/src/mgs_gimlet.rs @@ -121,8 +121,6 @@ impl AttachedSerialConsoleMgs { pub(crate) struct MgsHandler { common: MgsCommon, sequencer: Sequencer, - sp_update: SpUpdate, - rot_update: RotUpdate, host_flash_update: HostFlashUpdate, host_phase2: HostPhase2Requester, usart: UsartHandler, @@ -143,8 +141,6 @@ impl MgsHandler { common: MgsCommon::claim_static_resources(base_mac_address), host_flash_update: HostFlashUpdate::new(), host_phase2: HostPhase2Requester::claim_static_resources(), - sp_update: SpUpdate::new(), - rot_update: RotUpdate::new(), sequencer: Sequencer::from(GIMLET_SEQ.get_task_id()), user_leds: UserLeds::from(USER_LEDS.get_task_id()), usart, @@ -173,7 +169,7 @@ impl MgsHandler { // set our timer for 1 tick from now to give a window for other // interrupts/notifications to arrive. if self.host_flash_update.is_preparing() - || self.sp_update.is_preparing() + || self.common.sp_update.is_preparing() { Some(sys_get_timer().now + 1) } else { @@ -194,7 +190,7 @@ impl MgsHandler { // active at a time. For any inactive update, `step_preparation()` is a // no-op. self.host_flash_update.step_preparation(); - self.sp_update.step_preparation(); + self.common.sp_update.step_preparation(); // Even though `timer_deadline()` can return a timer related to usart // flushing or host phase2 data handling, we don't need to do anything // here; `NetHandler` in main.rs will call @@ -555,7 +551,7 @@ impl SpHandler for MgsHandler { slot: 0, })); - self.sp_update.prepare(&UPDATE_MEMORY, update) + self.common.sp_update.prepare(&UPDATE_MEMORY, update) } fn component_update_prepare( @@ -576,7 +572,7 @@ impl SpHandler for MgsHandler { self.host_flash_update.prepare(&UPDATE_MEMORY, update) } SpComponent::ROT | SpComponent::STAGE0 => { - self.rot_update.prepare(&UPDATE_MEMORY, update) + self.common.rot_update.prepare(&UPDATE_MEMORY, update) } _ => Err(SpError::RequestUnsupportedForComponent), } @@ -619,12 +615,14 @@ impl SpHandler for MgsHandler { match chunk.component { SpComponent::SP_ITSELF | SpComponent::SP_AUX_FLASH => self + .common .sp_update .ingest_chunk(&chunk.component, &chunk.id, chunk.offset, data), SpComponent::HOST_CPU_BOOT_FLASH => self .host_flash_update .ingest_chunk(&(), &chunk.id, chunk.offset, data), SpComponent::ROT | SpComponent::STAGE0 => self + .common .rot_update .ingest_chunk(&(), &chunk.id, chunk.offset, data), _ => Err(SpError::RequestUnsupportedForComponent), @@ -649,9 +647,11 @@ impl SpHandler for MgsHandler { // includes an aux flash image, which they don't need to know). // Similarly, they will only ask for the status of an `SP_ITSELF` // update, not an `SP_AUX_FLASH` update (which isn't a thing). - SpComponent::SP_ITSELF => self.sp_update.status(), + SpComponent::SP_ITSELF => self.common.sp_update.status(), SpComponent::HOST_CPU_BOOT_FLASH => self.host_flash_update.status(), - SpComponent::ROT | SpComponent::STAGE0 => self.rot_update.status(), + SpComponent::ROT | SpComponent::STAGE0 => { + self.common.rot_update.status() + } _ => return Err(SpError::RequestUnsupportedForComponent), }; @@ -677,12 +677,12 @@ impl SpHandler for MgsHandler { // includes an aux flash image, which they don't need to know). // Similarly, they will only attempt to abort an `SP_ITSELF` // update, not an `SP_AUX_FLASH` update (which isn't a thing). - SpComponent::SP_ITSELF => self.sp_update.abort(&id), + SpComponent::SP_ITSELF => self.common.sp_update.abort(&id), SpComponent::HOST_CPU_BOOT_FLASH => { self.host_flash_update.abort(&id) } SpComponent::ROT | SpComponent::STAGE0 => { - self.rot_update.abort(&id) + self.common.rot_update.abort(&id) } _ => Err(SpError::RequestUnsupportedForComponent), } diff --git a/task/control-plane-agent/src/mgs_psc.rs b/task/control-plane-agent/src/mgs_psc.rs index ffb50bcf2..579986064 100644 --- a/task/control-plane-agent/src/mgs_psc.rs +++ b/task/control-plane-agent/src/mgs_psc.rs @@ -4,7 +4,7 @@ use crate::{ mgs_common::MgsCommon, update::rot::RotUpdate, update::sp::SpUpdate, - update::ComponentUpdater, CriticalEvent, Log, MgsMessage, + update::ComponentUpdater, usize_max, CriticalEvent, Log, MgsMessage, }; use drv_user_leds_api::UserLeds; use gateway_messages::sp_impl::{ @@ -26,7 +26,8 @@ use userlib::sys_get_timer; // How big does our shared update buffer need to be? Has to be able to handle SP // update blocks for now, no other updateable components. -const UPDATE_BUFFER_SIZE: usize = SpUpdate::BLOCK_SIZE; +const UPDATE_BUFFER_SIZE: usize = + usize_max(SpUpdate::BLOCK_SIZE, RotUpdate::BLOCK_SIZE); userlib::task_slot!(USER_LEDS, user_leds); @@ -70,7 +71,7 @@ impl MgsHandler { /// `main()` is responsible for calling this method and actually setting the /// timer. pub(crate) fn timer_deadline(&self) -> Option { - if self.sp_update.is_preparing() { + if self.common.sp_update.is_preparing() { Some(sys_get_timer().now + 1) } else { None @@ -79,7 +80,7 @@ impl MgsHandler { pub(crate) fn handle_timer_fired(&mut self) { // This is a no-op if we're not preparing for an SP update. - self.sp_update.step_preparation(); + self.common.sp_update.step_preparation(); } pub(crate) fn drive_usart(&mut self) {} @@ -250,7 +251,7 @@ impl SpHandler for MgsHandler { slot: 0, })); - self.sp_update.prepare(&UPDATE_MEMORY, update) + self.common.sp_update.prepare(&UPDATE_MEMORY, update) } fn component_update_prepare( @@ -268,7 +269,7 @@ impl SpHandler for MgsHandler { match update.component { SpComponent::ROT | SpComponent::STAGE0 => { - self.rot_update.prepare(&UPDATE_MEMORY, update) + self.common.rot_update.prepare(&UPDATE_MEMORY, update) } _ => Err(SpError::RequestUnsupportedForComponent), } @@ -308,9 +309,9 @@ impl SpHandler for MgsHandler { })); match component { - SpComponent::SP_ITSELF => Ok(self.sp_update.status()), + SpComponent::SP_ITSELF => Ok(self.common.sp_update.status()), SpComponent::ROT | SpComponent::STAGE0 => { - Ok(self.rot_update.status()) + Ok(self.common.rot_update.status()) } _ => Err(SpError::RequestUnsupportedForComponent), } @@ -330,9 +331,11 @@ impl SpHandler for MgsHandler { match chunk.component { SpComponent::SP_ITSELF | SpComponent::SP_AUX_FLASH => self + .common .sp_update .ingest_chunk(&chunk.component, &chunk.id, chunk.offset, data), SpComponent::ROT | SpComponent::STAGE0 => self + .common .rot_update .ingest_chunk(&(), &chunk.id, chunk.offset, data), _ => Err(SpError::RequestUnsupportedForComponent), @@ -351,9 +354,9 @@ impl SpHandler for MgsHandler { })); match component { - SpComponent::SP_ITSELF => self.sp_update.abort(&id), + SpComponent::SP_ITSELF => self.common.sp_update.abort(&id), SpComponent::ROT | SpComponent::STAGE0 => { - self.rot_update.abort(&id) + self.common.rot_update.abort(&id) } _ => Err(SpError::RequestUnsupportedForComponent), } diff --git a/task/control-plane-agent/src/mgs_sidecar.rs b/task/control-plane-agent/src/mgs_sidecar.rs index edbdbdfd9..d9465be78 100644 --- a/task/control-plane-agent/src/mgs_sidecar.rs +++ b/task/control-plane-agent/src/mgs_sidecar.rs @@ -4,7 +4,7 @@ use crate::{ mgs_common::MgsCommon, update::rot::RotUpdate, update::sp::SpUpdate, - update::ComponentUpdater, CriticalEvent, Log, MgsMessage, + update::ComponentUpdater, usize_max, CriticalEvent, Log, MgsMessage, }; use drv_ignition_api::IgnitionError; use drv_monorail_api::{Monorail, MonorailError}; @@ -42,7 +42,8 @@ userlib::task_slot!(TRANSCEIVERS, transceivers); // How big does our shared update buffer need to be? Has to be able to handle SP // update blocks for now, no other updateable components. -const UPDATE_BUFFER_SIZE: usize = SpUpdate::BLOCK_SIZE; +const UPDATE_BUFFER_SIZE: usize = + usize_max(SpUpdate::BLOCK_SIZE, RotUpdate::BLOCK_SIZE); // Create type aliases that include our `UpdateBuffer` size (i.e., the size of // the largest update chunk of all the components we update). @@ -62,8 +63,6 @@ pub(crate) struct MgsHandler { sequencer: Sequencer, monorail: Monorail, transceivers: Transceivers, - sp_update: SpUpdate, - rot_update: RotUpdate, ignition: IgnitionController, } @@ -76,8 +75,6 @@ impl MgsHandler { sequencer: Sequencer::from(SIDECAR_SEQ.get_task_id()), monorail: Monorail::from(MONORAIL.get_task_id()), transceivers: Transceivers::from(TRANSCEIVERS.get_task_id()), - sp_update: SpUpdate::new(), - rot_update: RotUpdate::new(), ignition: IgnitionController::new(), } } @@ -90,7 +87,7 @@ impl MgsHandler { /// `main()` is responsible for calling this method and actually setting the /// timer. pub(crate) fn timer_deadline(&self) -> Option { - if self.sp_update.is_preparing() { + if self.common.sp_update.is_preparing() { Some(sys_get_timer().now + 1) } else { None @@ -99,7 +96,7 @@ impl MgsHandler { pub(crate) fn handle_timer_fired(&mut self) { // This is a no-op if we're not preparing for an SP update. - self.sp_update.step_preparation(); + self.common.sp_update.step_preparation(); } pub(crate) fn drive_usart(&mut self) {} @@ -299,7 +296,7 @@ impl SpHandler for MgsHandler { slot: 0, })); - self.sp_update.prepare(&UPDATE_MEMORY, update) + self.common.sp_update.prepare(&UPDATE_MEMORY, update) } fn component_update_prepare( @@ -317,7 +314,7 @@ impl SpHandler for MgsHandler { match update.component { SpComponent::ROT | SpComponent::STAGE0 => { - self.rot_update.prepare(&UPDATE_MEMORY, update) + self.common.rot_update.prepare(&UPDATE_MEMORY, update) } _ => Err(SpError::RequestUnsupportedForComponent), } @@ -361,9 +358,9 @@ impl SpHandler for MgsHandler { })); match component { - SpComponent::SP_ITSELF => Ok(self.sp_update.status()), + SpComponent::SP_ITSELF => Ok(self.common.sp_update.status()), SpComponent::ROT | SpComponent::STAGE0 => { - Ok(self.rot_update.status()) + Ok(self.common.rot_update.status()) } _ => Err(SpError::RequestUnsupportedForComponent), } @@ -383,9 +380,11 @@ impl SpHandler for MgsHandler { match chunk.component { SpComponent::SP_ITSELF | SpComponent::SP_AUX_FLASH => self + .common .sp_update .ingest_chunk(&chunk.component, &chunk.id, chunk.offset, data), SpComponent::ROT | SpComponent::STAGE0 => self + .common .rot_update .ingest_chunk(&(), &chunk.id, chunk.offset, data), _ => Err(SpError::RequestUnsupportedForComponent), @@ -404,9 +403,9 @@ impl SpHandler for MgsHandler { })); match component { - SpComponent::SP_ITSELF => self.sp_update.abort(&id), + SpComponent::SP_ITSELF => self.common.sp_update.abort(&id), SpComponent::ROT | SpComponent::STAGE0 => { - self.rot_update.abort(&id) + self.common.rot_update.abort(&id) } _ => Err(SpError::RequestUnsupportedForComponent), }