-
Notifications
You must be signed in to change notification settings - Fork 26
orchestrator: Add the platform-driver skeleton behind the Platform seam #418
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
Open
chrysh
wants to merge
4
commits into
OpenPRoT:main
Choose a base branch
from
9elements:add-shell-skeleton
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+733
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
198fc9f
orchestrator: Add the shell's board seams
chrysh 4556f0f
orchestrator: Add the shell skeleton with firmware verification
chrysh 9c874bb
orchestrator: Rename the shell to platform driver
chrysh 33cead9
orchestrator: Rename read_firmware to stage_firmware
chrysh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Licensed under the Apache-2.0 license | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") | ||
|
|
||
| rust_library( | ||
| name = "orchestrator_driver", | ||
| srcs = [ | ||
| "src/board.rs", | ||
| "src/driver.rs", | ||
| "src/lib.rs", | ||
| "src/tests.rs", | ||
| ], | ||
| crate_name = "openprot_orchestrator_driver", | ||
| edition = "2024", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//services/orchestrator/sm:orchestrator_sm", | ||
| "@rust_crates//:heapless", | ||
| ], | ||
| ) | ||
|
|
||
| # Host tests: build on the host platform, no kernel/QEMU. | ||
| rust_test( | ||
| name = "orchestrator_driver_test", | ||
| crate = ":orchestrator_driver", | ||
| edition = "2024", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <!-- Licensed under the Apache-2.0 license --> | ||
| <!-- SPDX-License-Identifier: Apache-2.0 --> | ||
|
|
||
| # orchestrator platform driver (`openprot_orchestrator_driver`) | ||
|
|
||
| The effect-executing layer around the orchestrator state machine. `PlatformDriver` | ||
| implements the SM's `Platform` seam: one method per `Effect`, each | ||
| documenting its obligation from the platform-boundary contract | ||
| ([orchestrator-model.md §6](../../../docs/src/design/orchestrator/orchestrator-model.md)). Unimplemented executors return | ||
| `DriverError::NotImplemented`; the SM fail-closes on them. | ||
|
|
||
| Everything device-specific arrives through the seams in `board.rs` | ||
| (`ImageSource`, `Verifier`, bundled in `Board`); executor-produced events | ||
| return to the SM via `PlatformDriver::take_event`. The event loop dispatches an | ||
| outside event, then keeps dispatching what the executors produced until | ||
| `take_event` returns `None`: | ||
|
|
||
| ```rust | ||
| orch.dispatch(&mut driver, event); | ||
| while let Some(ev) = driver.take_event() { | ||
| orch.dispatch(&mut driver, ev); | ||
| } | ||
| ``` | ||
|
|
||
| Implemented executors: `read_firmware`, `verify_firmware`. Everything else | ||
| returns `NotImplemented` until its pillar lands (boot walk, recovery, | ||
| update path, attestation, reporting). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Licensed under the Apache-2.0 license | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! What the board supplies to the driver: traits and wiring data only. | ||
| //! Boards (or test mocks) implement these. | ||
|
|
||
| use openprot_orchestrator_sm::ComponentId; | ||
|
|
||
| /// Access to one component's active firmware image, however it is reached — | ||
| /// interposed flash, a PLDM/MCTP transfer, a RAM copy in tests. | ||
| pub trait ImageSource { | ||
| /// The error type reported by this source. | ||
| type Error: core::error::Error; | ||
|
|
||
| /// Makes the image readable (claim the flash, open the transfer). | ||
| /// Idempotent; a later `open` re-stages the image. | ||
| fn open(&mut self) -> Result<(), Self::Error>; | ||
|
|
||
| /// Image length in bytes. | ||
| fn size(&mut self) -> Result<usize, Self::Error>; | ||
|
|
||
| /// Reads `buf.len()` bytes starting at byte `offset` of the image. | ||
| fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Result<(), Self::Error>; | ||
| } | ||
|
|
||
| impl<S: ImageSource> ImageSource for &mut S { | ||
| type Error = S::Error; | ||
|
|
||
| #[inline(always)] | ||
| fn open(&mut self) -> Result<(), Self::Error> { | ||
| (**self).open() | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| fn size(&mut self) -> Result<usize, Self::Error> { | ||
| (**self).size() | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| fn read_at(&mut self, offset: usize, buf: &mut [u8]) -> Result<(), Self::Error> { | ||
| (**self).read_at(offset, buf) | ||
| } | ||
| } | ||
|
|
||
| /// Judges a component's firmware image; board wiring decides what | ||
| /// "authentic" means. | ||
| pub trait Verifier { | ||
| /// The error type reported by this verifier. | ||
| type Error: core::error::Error; | ||
|
|
||
| /// Judges `id`'s image, reading it from `image`. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Only when the check could not be performed (crypto fault, missing | ||
| /// key, unreadable source). A checked-and-bad image is | ||
| /// `Ok(Verdict::Rejected)` — an actuation fault must not forge a | ||
| /// verdict. | ||
| fn verify( | ||
| &mut self, | ||
| id: ComponentId, | ||
| image: &mut impl ImageSource, | ||
| ) -> Result<Verdict, Self::Error>; | ||
| } | ||
|
|
||
| impl<V: Verifier> Verifier for &mut V { | ||
| type Error = V::Error; | ||
|
|
||
| #[inline(always)] | ||
| fn verify( | ||
| &mut self, | ||
| id: ComponentId, | ||
| image: &mut impl ImageSource, | ||
| ) -> Result<Verdict, Self::Error> { | ||
| (**self).verify(id, image) | ||
| } | ||
| } | ||
|
|
||
| /// A [`Verifier`]'s judgment of one image. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum Verdict { | ||
| /// Reported as `Event::VerificationPassed`. | ||
| Authentic, | ||
| /// Reported as `Event::VerificationFailed`. | ||
| Rejected, | ||
| } | ||
|
|
||
| /// One board's type choices, named by a marker type. A new seam adds an | ||
| /// associated type here and a field on [`Board`] — never another parameter. | ||
| pub trait BoardTypes { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pease rename |
||
| /// Image access for the managed components. | ||
| type Image: ImageSource; | ||
| /// Judges images for every component. | ||
| type Verifier: Verifier; | ||
| // Later seams: Reset (release/assert_reset), Evidence (checkpoint | ||
| // walk), Recovery, Staging. | ||
| } | ||
|
|
||
| /// Everything the board supplies, built once at bring-up and handed to | ||
| /// `PlatformDriver::new`. Fields are public: executors may need two parts at once | ||
| /// (disjoint borrows). | ||
| /// | ||
| /// ```ignore | ||
| /// struct Ast1060Board; | ||
| /// impl BoardTypes for Ast1060Board { | ||
| /// type Image = SpiFlashImage; // interposed flash, offsets from the slot layout | ||
| /// type Verifier = ManifestVerifier; // signature + SVN via the crypto engine | ||
| /// } | ||
| /// let board = Board::<Ast1060Board, 2> { | ||
| /// images: [bmc_image, cpld_image], | ||
| /// verifier, | ||
| /// }; | ||
| /// ``` | ||
| pub struct Board<B: BoardTypes, const N: usize> { | ||
| /// `images[i]` belongs to `ComponentId(i)` — device index = chain | ||
| /// position = table declaration order. | ||
| pub images: [B::Image; N], | ||
| /// Judges images for every component. | ||
| pub verifier: B::Verifier, | ||
| // Later seams add fields, e.g. resets: [B::Reset; N]. | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if we cryptographically authenticated an image, I would name it
Authenticated, since this is common naming in cryptographic contexts.