Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

control-plane-agent: finish ComponentUpdater #1727

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions task/control-plane-agent/src/mgs_gimlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,10 @@ impl SpHandler for MgsHandler {
.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.rot_update.ingest_chunk(&chunk.id, chunk.offset, data)
}
.ingest_chunk(&(), &chunk.id, chunk.offset, data),
SpComponent::ROT | SpComponent::STAGE0 => self
.rot_update
.ingest_chunk(&(), &chunk.id, chunk.offset, data),
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand Down
6 changes: 3 additions & 3 deletions task/control-plane-agent/src/mgs_psc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ impl SpHandler for MgsHandler {
SpComponent::SP_ITSELF | SpComponent::SP_AUX_FLASH => self
.sp_update
.ingest_chunk(&chunk.component, &chunk.id, chunk.offset, data),
SpComponent::ROT | SpComponent::STAGE0 => {
self.rot_update.ingest_chunk(&chunk.id, chunk.offset, data)
}
SpComponent::ROT | SpComponent::STAGE0 => self
.rot_update
.ingest_chunk(&(), &chunk.id, chunk.offset, data),
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand Down
6 changes: 3 additions & 3 deletions task/control-plane-agent/src/mgs_sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ impl SpHandler for MgsHandler {
SpComponent::SP_ITSELF | SpComponent::SP_AUX_FLASH => self
.sp_update
.ingest_chunk(&chunk.component, &chunk.id, chunk.offset, data),
SpComponent::ROT | SpComponent::STAGE0 => {
self.rot_update.ingest_chunk(&chunk.id, chunk.offset, data)
}
SpComponent::ROT | SpComponent::STAGE0 => self
.rot_update
.ingest_chunk(&(), &chunk.id, chunk.offset, data),
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand Down
4 changes: 4 additions & 0 deletions task/control-plane-agent/src/update/host_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ static_assertions::const_assert!(
impl ComponentUpdater for HostFlashUpdate {
const BLOCK_SIZE: usize = PAGE_SIZE_BYTES;

type UpdatePrepare = ComponentUpdatePrepare;
type SubComponent = ();

fn prepare(
&mut self,
buffer: &'static UpdateBuffer,
Expand Down Expand Up @@ -243,6 +246,7 @@ impl ComponentUpdater for HostFlashUpdate {

fn ingest_chunk(
&mut self,
_sub: &(),
id: &UpdateId,
offset: u32,
mut data: &[u8],
Expand Down
16 changes: 12 additions & 4 deletions task/control-plane-agent/src/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::mgs_handler::UpdateBuffer;
use gateway_messages::{
ComponentUpdatePrepare, SpError, UpdateId, UpdateStatus,
};
use gateway_messages::{SpError, UpdateId, UpdateStatus};

#[cfg(feature = "gimlet")]
pub(crate) mod host_flash;
Expand All @@ -30,6 +28,15 @@ pub(crate) trait ComponentUpdater {
/// mechanism wants as a single chunk.
const BLOCK_SIZE: usize;

/// Record provided to the `prepare` operation. Generally
/// `ComponentUpdatePrepare`, and would default to that if associated type
/// defaults were stable at the time of this writing (2024-04), which they
/// are not.
type UpdatePrepare;

/// Type used to specify sub-components within a component.
type SubComponent;

/// Attempt to start preparing for an update, using `buffer` as the backing
/// store for incoming data.
///
Expand All @@ -38,7 +45,7 @@ pub(crate) trait ComponentUpdater {
fn prepare(
&mut self,
buffer: &'static UpdateBuffer,
update: ComponentUpdatePrepare,
update: Self::UpdatePrepare,
) -> Result<(), SpError>;

/// Returns true if this task needs `step_preparation()` called.
Expand All @@ -53,6 +60,7 @@ pub(crate) trait ComponentUpdater {
/// Attempt to ingest a single update chunk from MGS.
fn ingest_chunk(
&mut self,
sub: &Self::SubComponent,
id: &UpdateId,
offset: u32,
data: &[u8],
Expand Down
4 changes: 4 additions & 0 deletions task/control-plane-agent/src/update/rot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ enum State {
impl ComponentUpdater for RotUpdate {
const BLOCK_SIZE: usize = BLOCK_SIZE_BYTES;

type UpdatePrepare = ComponentUpdatePrepare;
type SubComponent = ();

fn prepare(
&mut self,
buffer: &'static UpdateBuffer,
Expand Down Expand Up @@ -131,6 +134,7 @@ impl ComponentUpdater for RotUpdate {

fn ingest_chunk(
&mut self,
_sub: &(),
id: &UpdateId,
offset: u32,
mut data: &[u8],
Expand Down
32 changes: 19 additions & 13 deletions task/control-plane-agent/src/update/sp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

use crate::mgs_common::UPDATE_SERVER;
use crate::mgs_handler::{BorrowedUpdateBuffer, UpdateBuffer};
use crate::update::ComponentUpdater;
use cfg_if::cfg_if;
use core::ops::{Deref, DerefMut};
use drv_caboose::CabooseReader;
Expand Down Expand Up @@ -98,24 +99,29 @@ pub(crate) struct SpUpdate {
}

impl SpUpdate {
#[cfg(feature = "auxflash")]
pub(crate) const BLOCK_SIZE: usize =
crate::usize_max(BLOCK_SIZE_BYTES, drv_auxflash_api::PAGE_SIZE_BYTES);
#[cfg(not(feature = "auxflash"))]
pub(crate) const BLOCK_SIZE: usize = BLOCK_SIZE_BYTES;

pub(crate) fn new() -> Self {
Self {
sp_task: Update::from(UPDATE_SERVER.get_task_id()),
auxflash_task: AuxFlash::from(AUX_FLASH_SERVER.get_task_id()),
current: None,
}
}
}

pub(crate) fn prepare(
impl ComponentUpdater for SpUpdate {
#[cfg(feature = "auxflash")]
const BLOCK_SIZE: usize =
crate::usize_max(BLOCK_SIZE_BYTES, drv_auxflash_api::PAGE_SIZE_BYTES);
#[cfg(not(feature = "auxflash"))]
const BLOCK_SIZE: usize = BLOCK_SIZE_BYTES;

type UpdatePrepare = SpUpdatePrepare;
type SubComponent = SpComponent;

fn prepare(
&mut self,
buffer: &'static UpdateBuffer,
update: SpUpdatePrepare,
update: Self::UpdatePrepare,
) -> Result<(), SpError> {
// Do we have an update already in progress?
match self.current.as_ref().map(|c| c.state()) {
Expand Down Expand Up @@ -178,14 +184,14 @@ impl SpUpdate {
Ok(())
}

pub(crate) fn is_preparing(&self) -> bool {
fn is_preparing(&self) -> bool {
match self.current.as_ref().map(|c| c.state()) {
Some(State::AuxFlash(s)) => s.is_preparing(),
_ => false,
}
}

pub(crate) fn step_preparation(&mut self) {
fn step_preparation(&mut self) {
// Do we have an update?
let current = match self.current.as_mut() {
Some(current) => current,
Expand Down Expand Up @@ -231,7 +237,7 @@ impl SpUpdate {
});
}

pub(crate) fn status(&self) -> UpdateStatus {
fn status(&self) -> UpdateStatus {
let current = match self.current.as_ref() {
Some(current) => current,
None => return UpdateStatus::None,
Expand Down Expand Up @@ -264,7 +270,7 @@ impl SpUpdate {
}
}

pub(crate) fn ingest_chunk(
fn ingest_chunk(
&mut self,
component: &SpComponent,
id: &UpdateId,
Expand Down Expand Up @@ -377,7 +383,7 @@ impl SpUpdate {
})
}

pub(crate) fn abort(&mut self, id: &UpdateId) -> Result<(), SpError> {
fn abort(&mut self, id: &UpdateId) -> Result<(), SpError> {
// Do we have an update in progress? If not, nothing to do.
let current = match self.current.as_mut() {
Some(current) => current,
Expand Down
Loading