Skip to content

Commit

Permalink
Merge branch 'master' into eliza/sp3-to-sp-alert
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw authored Apr 8, 2024
2 parents 27015a7 + d72a833 commit 8e09350
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 48 deletions.
4 changes: 2 additions & 2 deletions app/psc/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ notifications = ["exti-wildcard-irq"]
"exti.exti15_10" = "exti-wildcard-irq"

[tasks.sys.config.gpio-irqs.rot_irq]
port = "D"
pin = 0
port = "E"
pin = 3
owner = {name = "sprot", notification = "rot_irq"}

[tasks.i2c_driver]
Expand Down
12 changes: 6 additions & 6 deletions drv/stm32h7-sprot-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,13 @@ impl<S: SpiServer> Io<S> {
// determined based on `max_sleep`.
fn wait_rot_irq(&mut self, desired: bool, max_sleep: u32) -> bool {
use notifications::{sprot::TIMER_MASK, ROT_IRQ_MASK};
// Determine our edge sensitivity for the interrupt. If we want to wait
// for the line to be asserted, we want to wait for a rising edge. If
// the line is currently asserted, and we're waiting for it to be
// *deasserted*, we want to wait for a falling edge.
// Determine our edge sensitivity for the interrupt. The ROT_IRQ line is
// active low, so if we want to wait for it to be asserted, wait for the
// falling edge. If the line is currently asserted, and we're waiting
// for it to be *deasserted*, we want to wait for a rising edge.
let sensitivity = match desired {
true => sys_api::Edge::Rising,
false => sys_api::Edge::Falling,
false => sys_api::Edge::Rising,
true => sys_api::Edge::Falling,
};
self.sys.gpio_irq_configure(ROT_IRQ_MASK, sensitivity);

Expand Down
17 changes: 13 additions & 4 deletions task/control-plane-agent/src/mgs_common.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::{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,
Expand Down Expand Up @@ -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<SpComponent>,
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()),
}
}
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions task/control-plane-agent/src/mgs_gimlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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),
}
Expand Down Expand Up @@ -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),
Expand All @@ -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),
};

Expand All @@ -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),
}
Expand Down
23 changes: 13 additions & 10 deletions task/control-plane-agent/src/mgs_psc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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);

Expand Down Expand Up @@ -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<u64> {
if self.sp_update.is_preparing() {
if self.common.sp_update.is_preparing() {
Some(sys_get_timer().now + 1)
} else {
None
Expand All @@ -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) {}
Expand Down Expand Up @@ -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(
Expand All @@ -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),
}
Expand Down Expand Up @@ -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),
}
Expand All @@ -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),
Expand All @@ -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),
}
Expand Down
27 changes: 13 additions & 14 deletions task/control-plane-agent/src/mgs_sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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).
Expand All @@ -62,8 +63,6 @@ pub(crate) struct MgsHandler {
sequencer: Sequencer,
monorail: Monorail,
transceivers: Transceivers,
sp_update: SpUpdate,
rot_update: RotUpdate,
ignition: IgnitionController,
}

Expand All @@ -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(),
}
}
Expand All @@ -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<u64> {
if self.sp_update.is_preparing() {
if self.common.sp_update.is_preparing() {
Some(sys_get_timer().now + 1)
} else {
None
Expand All @@ -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) {}
Expand Down Expand Up @@ -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(
Expand All @@ -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),
}
Expand Down Expand Up @@ -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),
}
Expand All @@ -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),
Expand All @@ -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),
}
Expand Down

0 comments on commit 8e09350

Please sign in to comment.