From bc01fd6728f3b1efef2eb12adcce5acff558f6bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 17 Sep 2026 16:32:08 +0200 Subject: [PATCH 1/2] Add `ResetSignal` --- core/CHANGELOG.md | 4 +- core/src/lib.rs | 1 + core/src/reset_signal.rs | 107 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 core/src/reset_signal.rs diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index d44686628af..1961ae59e4d 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -2,7 +2,9 @@ ## Unreleased -- +### Added + +- Add `ResetSignal` ## [v0.2.2](https://github.com/trussed-dev/trussed/releases/tag/core-v0.2.2) (2026-05-30) diff --git a/core/src/lib.rs b/core/src/lib.rs index f439ca5569b..56cdad7317a 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -15,6 +15,7 @@ pub mod api; pub mod config; #[cfg(feature = "crypto-client")] pub mod mechanisms; +pub mod reset_signal; #[cfg(feature = "serde-extensions")] pub mod serde_extensions; pub mod types; diff --git a/core/src/reset_signal.rs b/core/src/reset_signal.rs new file mode 100644 index 00000000000..feb374a7304 --- /dev/null +++ b/core/src/reset_signal.rs @@ -0,0 +1,107 @@ +use core::sync::atomic::{AtomicU8, Ordering}; + +/// Structure meant to be stored in a `static` to signal applications that they have been factory-resetted by a runner +/// +/// It is expected to have one such structure for each application supporting factory-reset +#[derive(Debug)] +pub struct ResetSignalAllocation(AtomicU8); + +impl Default for ResetSignalAllocation { + fn default() -> Self { + Self::new() + } +} + +impl ResetSignalAllocation { + pub const fn new() -> Self { + Self(AtomicU8::new(ResetSignal::None as u8)) + } + + pub fn load(&self) -> ResetSignal { + let v = self.0.load(Ordering::Relaxed); + ResetSignal::from_repr(v).expect("A reset signal value") + } + + pub fn set_factory_reset(&self) -> bool { + self.0 + .compare_exchange( + ResetSignal::None as u8, + ResetSignal::FactoryReset as u8, + Ordering::Relaxed, + Ordering::Relaxed, + ) + .is_ok() + } + + pub fn set_config_changed(&self) { + self.0 + .store(ResetSignal::ConfigChanged as u8, Ordering::Relaxed) + } + + /// Factory reset can be acknowledged so that the application can restart working + /// + /// A configuration change cannot be acknowledged as it requires a power cycle to be taken into account. + pub fn ack_factory_reset(&self) -> bool { + self.0 + .compare_exchange( + ResetSignal::FactoryReset as u8, + ResetSignal::None as u8, + Ordering::Relaxed, + Ordering::Relaxed, + ) + .is_ok() + } +} + +macro_rules! enum_u8 { + ( + $(#[$outer:meta])* + $vis:vis enum $name:ident { + $($(#[$attr:meta])* $var:ident),+ + $(,)* + } + ) => { + $(#[$outer])* + #[repr(u8)] + $vis enum $name { + $( + $(#[$attr])* + $var, + )* + } + + impl $name { + fn from_repr(val: u8) -> Option<$name> { + mod constants { + $( + #[allow(non_upper_case_globals)] + pub const $var: u8 = super::$name::$var as u8; + )* + } + match val { + $( + constants::$var => Some($name::$var), + )* + _ => None, + } + } + } + } +} + +enum_u8!( + #[derive(Debug, Default)] + pub enum ResetSignal { + #[default] + /// The App can continue operating + None, + /// The app has had it state factory reseted by the admin app + /// + /// It should delete any runtime state it is currently holding, then [`acknowledge`](ResetSignalAllocation::ack_factory_reset) the reset and continue working. + FactoryReset, + /// A configuration relevant to the application has been changed. + /// + /// The application must reject all incoming request and store no persistent state until a power cycle. + ConfigChanged, + } +); From 7fadd07908805b62e0769776d81d2e02197e7c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 17 Sep 2026 17:44:46 +0200 Subject: [PATCH 2/2] Prepare release trussed-core 0.2.2 --- Cargo.toml | 2 +- core/CHANGELOG.md | 2 ++ core/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e635150a792..690d1b1b332 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ license.workspace = true repository.workspace = true [dependencies] -trussed-core = "0.2.2" +trussed-core = "0.2.3" # general bitflags = { version = "2.1" } diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 1961ae59e4d..ba9628d79a0 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +## [v0.2.3](https://github.com/trussed-dev/trussed/releases/tag/core-v0.2.3) (2026-09-17) + ### Added - Add `ResetSignal` diff --git a/core/Cargo.toml b/core/Cargo.toml index 679df5c3a9f..b5a417fb01b 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trussed-core" -version = "0.2.2" +version = "0.2.3" description = "Core types for the trussed crate" authors.workspace = true