Skip to content

Commit

Permalink
Add RoT update support to the control-plane-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Jan 19, 2023
1 parent d5114dc commit 8cd6b06
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions drv/update-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,18 @@ pub mod stm32h7 {
pub const BLOCK_SIZE_BYTES: usize = FLASH_WORD_BYTES * 32;
}

pub mod lpc55 {
// This value is currently set to `lpc55_romapi::FLASH_PAGE_SIZE`
//
// We hardcode it for simplicity, and because we cannot,and should not,
// directly include the `lpc55_romapi` crate. While we could transfer
// arbitrary amounts of data over spi and have the update server on
// the RoT split it up, this makes the code more complicated than
// necessary and is only an optimization. For now, especially since we
// only have 1 RoT and we must currently define a constant for use the
// `control_plane_agent::ComponentUpdater` trait, we do the simple thing
// and hardcode according to hardware requirements.
pub const BLOCK_SIZE_BYTES: usize = 512;
}

include!(concat!(env!("OUT_DIR"), "/client_stub.rs"));
18 changes: 14 additions & 4 deletions task/control-plane-agent/src/mgs_gimlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use crate::{
mgs_common::MgsCommon, update::host_flash::HostFlashUpdate,
update::sp::SpUpdate, update::ComponentUpdater, usize_max,
vlan_id_from_sp_port, Log, MgsMessage, SYS, USART_IRQ,
update::rot::RotUpdate, update::sp::SpUpdate, update::ComponentUpdater,
usize_max, vlan_id_from_sp_port, Log, MgsMessage, SYS, USART_IRQ,
};
use core::convert::Infallible;
use core::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -39,8 +39,10 @@ use host_phase2::HostPhase2Requester;

// How big does our shared update buffer need to be? Has to be able to handle SP
// update blocks or host flash pages.
const UPDATE_BUFFER_SIZE: usize =
usize_max(SpUpdate::BLOCK_SIZE, HostFlashUpdate::BLOCK_SIZE);
const UPDATE_BUFFER_SIZE: usize = usize_max(
usize_max(SpUpdate::BLOCK_SIZE, HostFlashUpdate::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).
Expand Down Expand Up @@ -86,6 +88,7 @@ pub(crate) struct MgsHandler {
common: MgsCommon,
sequencer: Sequencer,
sp_update: SpUpdate,
rot_update: RotUpdate,
host_flash_update: HostFlashUpdate,
host_phase2: HostPhase2Requester,
usart: UsartHandler,
Expand All @@ -111,6 +114,7 @@ impl MgsHandler {
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()),
usart,
startup_options,
Expand Down Expand Up @@ -522,6 +526,7 @@ impl SpHandler for MgsHandler {
SpComponent::HOST_CPU_BOOT_FLASH => {
self.host_flash_update.prepare(&UPDATE_MEMORY, update)
}
SpComponent::ROT => self.rot_update.prepare(&UPDATE_MEMORY, update),
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand All @@ -545,6 +550,9 @@ impl SpHandler for MgsHandler {
SpComponent::HOST_CPU_BOOT_FLASH => self
.host_flash_update
.ingest_chunk(&chunk.id, chunk.offset, data),
SpComponent::ROT => {
self.rot_update.ingest_chunk(&chunk.id, chunk.offset, data)
}
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand All @@ -567,6 +575,7 @@ impl SpHandler for MgsHandler {
// update, not an `SP_AUX_FLASH` update (which isn't a thing).
SpComponent::SP_ITSELF => self.sp_update.status(),
SpComponent::HOST_CPU_BOOT_FLASH => self.host_flash_update.status(),
SpComponent::ROT => self.rot_update.status(),
_ => return Err(SpError::RequestUnsupportedForComponent),
};

Expand Down Expand Up @@ -594,6 +603,7 @@ impl SpHandler for MgsHandler {
SpComponent::HOST_CPU_BOOT_FLASH => {
self.host_flash_update.abort(&id)
}
SpComponent::ROT => self.rot_update.abort(&id),
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand Down
18 changes: 15 additions & 3 deletions task/control-plane-agent/src/mgs_psc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use core::convert::Infallible;

use crate::{mgs_common::MgsCommon, update::sp::SpUpdate, Log, MgsMessage};
use crate::{
mgs_common::MgsCommon, update::rot::RotUpdate, update::sp::SpUpdate,
update::ComponentUpdater, Log, MgsMessage,
};
use gateway_messages::sp_impl::{
BoundsChecked, DeviceDescription, SocketAddrV6, SpHandler,
};
Expand Down Expand Up @@ -40,6 +43,7 @@ static UPDATE_MEMORY: UpdateBuffer = UpdateBuffer::new();
pub(crate) struct MgsHandler {
common: MgsCommon,
sp_update: SpUpdate,
rot_update: RotUpdate,
}

impl MgsHandler {
Expand All @@ -49,6 +53,7 @@ impl MgsHandler {
Self {
common: MgsCommon::claim_static_resources(base_mac_address),
sp_update: SpUpdate::new(),
rot_update: RotUpdate::new(),
}
}

Expand Down Expand Up @@ -252,8 +257,10 @@ impl SpHandler for MgsHandler {
slot: update.slot,
}));

// We currently don't have any updateable components on psc.
Err(SpError::RequestUnsupportedForComponent)
match update.component {
SpComponent::ROT => self.rot_update.prepare(&UPDATE_MEMORY, update),
_ => Err(SpError::RequestUnsupportedForComponent),
}
}

fn update_status(
Expand All @@ -266,6 +273,7 @@ impl SpHandler for MgsHandler {

match component {
SpComponent::SP_ITSELF => Ok(self.sp_update.status()),
SpComponent::ROT => Ok(self.rot_update.status()),
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand All @@ -286,6 +294,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 => {
self.rot_update.ingest_chunk(&chunk.id, chunk.offset, data)
}
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand All @@ -301,6 +312,7 @@ impl SpHandler for MgsHandler {

match component {
SpComponent::SP_ITSELF => self.sp_update.abort(&id),
SpComponent::ROT => self.rot_update.abort(&id),
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand Down
18 changes: 15 additions & 3 deletions task/control-plane-agent/src/mgs_sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{mgs_common::MgsCommon, update::sp::SpUpdate, Log, MgsMessage};
use crate::{
mgs_common::MgsCommon, update::rot::RotUpdate, update::sp::SpUpdate,
update::ComponentUpdater, Log, MgsMessage,
};
use core::convert::Infallible;
use drv_ignition_api::IgnitionError;
use drv_monorail_api::{Monorail, MonorailError};
Expand Down Expand Up @@ -56,6 +59,7 @@ pub(crate) struct MgsHandler {
sequencer: Sequencer,
monorail: Monorail,
sp_update: SpUpdate,
rot_update: RotUpdate,
ignition: IgnitionController,
}

Expand All @@ -68,6 +72,7 @@ impl MgsHandler {
sequencer: Sequencer::from(SIDECAR_SEQ.get_task_id()),
monorail: Monorail::from(MONORAIL.get_task_id()),
sp_update: SpUpdate::new(),
rot_update: RotUpdate::new(),
ignition: IgnitionController::new(),
}
}
Expand Down Expand Up @@ -301,8 +306,10 @@ impl SpHandler for MgsHandler {
slot: update.slot,
}));

// We currently don't have any updateable components on sidecar.
Err(SpError::RequestUnsupportedForComponent)
match update.component {
SpComponent::ROT => self.rot_update.prepare(&UPDATE_MEMORY, update),
_ => Err(SpError::RequestUnsupportedForComponent),
}
}

fn update_status(
Expand All @@ -315,6 +322,7 @@ impl SpHandler for MgsHandler {

match component {
SpComponent::SP_ITSELF => Ok(self.sp_update.status()),
SpComponent::ROT => Ok(self.rot_update.status()),
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand All @@ -335,6 +343,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 => {
self.rot_update.ingest_chunk(&chunk.id, chunk.offset, data)
}
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand All @@ -350,6 +361,7 @@ impl SpHandler for MgsHandler {

match component {
SpComponent::SP_ITSELF => self.sp_update.abort(&id),
SpComponent::ROT => self.rot_update.abort(&id),
_ => Err(SpError::RequestUnsupportedForComponent),
}
}
Expand Down
1 change: 1 addition & 0 deletions task/control-plane-agent/src/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use gateway_messages::{
pub(crate) mod host_flash;

mod common;
pub(crate) mod rot;
pub(crate) mod sp;

// TODO Currently we only have one implementor of this trait
Expand Down
Loading

0 comments on commit 8cd6b06

Please sign in to comment.