refactor(core): move telemetry to sec layers
What changed, and why it matters
This commit is a code reorganization: it moves the small telemetry module that records battery temperature from one internal directory to another. The actual logic for reading, writing, and validating the temperature data is unchanged. There is no indication this fixes a security bug or introduces a new vulnerability.
No security action required. Treat as routine refactoring. If reviewing the broader telemetry feature, verify that backup RAM access controls for `BACKUP_RAM_KEY_TELEMETRY` remain appropriate in the new `sec/` layer.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change relocates the telemetry implementation from core/embed/util/telemetry/ to core/embed/sec/telemetry/ and updates all include paths from <util/telemetry.h> to <sec/telemetry.h>. The build model for trezor_t3w1_revC.py is updated to reference the new source/path. The only functional difference is that the implementation now includes <sec/backup_ram.h> instead of <sys/backup_ram.h>, which is consistent with the new security-layer placement. The data structure, versioning, read/write logic, and SMC verifier/stub wrappers remain identical.
Changed components
Trezor Core firmware telemetry moduleSTM32U5 power monitoringsecure-monitor call (SMC) telemetry stubs/verifiersT3W1 revision C build configurationInspect captured patch +154 / −155
diff --git a/core/embed/io/power_manager/stm32u5/power_monitoring.c b/core/embed/io/power_manager/stm32u5/power_monitoring.c
index 6f25960da..61621712b 100644
--- a/core/embed/io/power_manager/stm32u5/power_monitoring.c
+++ b/core/embed/io/power_manager/stm32u5/power_monitoring.c
@@ -26,7 +26,7 @@
#include <trezor_rtl.h>
#ifdef USE_TELEMETRY
-#include <util/telemetry.h>
+#include <sec/telemetry.h>
#endif
#include "../fuel_gauge/battery_model.h"
diff --git a/core/embed/sec/telemetry/inc/sec/telemetry.h b/core/embed/sec/telemetry/inc/sec/telemetry.h
new file mode 100644
index 000000000..aec62fb98
--- /dev/null
+++ b/core/embed/sec/telemetry/inc/sec/telemetry.h
@@ -0,0 +1,52 @@
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <trezor_types.h>
+
+/**
+ * @brief Telemetry data structure.
+ */
+typedef struct {
+ float min_temp_c; /**< Minimum recorded battery temperature in Celsius. */
+ float max_temp_c; /**< Maximum recorded battery temperature in Celsius. */
+} telemetry_data_t;
+
+/**
+ * @brief Record current battery temperature (in Celsius) into telemetry
+ * storage.
+ *
+ * Updates persisted min/max values:
+ * - minimum can only decrease
+ * - maximum can only increase
+ *
+ * @param temp_c Current battery temperature in Celsius.
+ */
+void telemetry_update_battery_temp(float temp_c);
+
+/**
+ * @brief Retrieve stored min/max battery temperature (in Celsius).
+ *
+ * @param[out] out Pointer to where the telemetry data will be stored (may be
+ * NULL).
+ *
+ * @return true if values are available (initialized), false otherwise.
+ */
+bool telemetry_get(telemetry_data_t* out);
diff --git a/core/embed/sec/telemetry/telemetry.c b/core/embed/sec/telemetry/telemetry.c
new file mode 100644
index 000000000..a327f42b4
--- /dev/null
+++ b/core/embed/sec/telemetry/telemetry.c
@@ -0,0 +1,96 @@
+/*
+ * This file is part of the Trezor project, https://trezor.io/
+ *
+ * Copyright (c) SatoshiLabs
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef SECURE_MODE
+
+#include <trezor_types.h>
+
+#include <sec/backup_ram.h>
+#include <sec/telemetry.h>
+
+// Versioning for persisted telemetry structure
+#define TELEMETRY_DATA_VERSION 0x0001
+
+typedef struct {
+ uint16_t version;
+ uint8_t initialized; // 0 = not set, 1 = valid data present
+ uint8_t reserved; // alignment/padding
+ telemetry_data_t data;
+} telemetry_t;
+
+static bool telemetry_read(telemetry_t* out) {
+ size_t size = 0;
+ if (!backup_ram_read(BACKUP_RAM_KEY_TELEMETRY, out, sizeof(*out), &size)) {
+ return false;
+ }
+ if (size != sizeof(*out)) {
+ return false;
+ }
+ if (out->version != TELEMETRY_DATA_VERSION) {
+ return false;
+ }
+ return true;
+}
+
+static bool telemetry_write(const telemetry_t* data) {
+ return backup_ram_write(BACKUP_RAM_KEY_TELEMETRY, BACKUP_RAM_ITEM_PUBLIC,
+ data, sizeof(*data));
+}
+
+void telemetry_update_battery_temp(float temp_c) {
+ telemetry_t telemetry;
+ bool have = telemetry_read(&telemetry) && telemetry.initialized == 1;
+
+ if (!have) {
+ telemetry.version = TELEMETRY_DATA_VERSION;
+ telemetry.initialized = 1;
+ telemetry.reserved = 0;
+ telemetry.data.min_temp_c = temp_c;
+ telemetry.data.max_temp_c = temp_c;
+ telemetry_write(&telemetry);
+ return;
+ }
+
+ bool changed = false;
+ if (temp_c < telemetry.data.min_temp_c) {
+ telemetry.data.min_temp_c = temp_c; // min can only decrease
+ changed = true;
+ }
+ if (temp_c > telemetry.data.max_temp_c) {
+ telemetry.data.max_temp_c = temp_c; // max can only increase
+ changed = true;
+ }
+
+ if (changed) {
+ telemetry_write(&telemetry);
+ }
+}
+
+bool telemetry_get(telemetry_data_t* out) {
+ telemetry_t telemetry;
+ if (!telemetry_read(&telemetry) || telemetry.initialized != 1) {
+ return false;
+ }
+ if (out != NULL) {
+ *out = telemetry.data;
+ }
+ return true;
+}
+
+#endif
diff --git a/core/embed/sys/smcall/stm32/smcall_stubs.c b/core/embed/sys/smcall/stm32/smcall_stubs.c
index f0593c92c..be1fd81e3 100644
--- a/core/embed/sys/smcall/stm32/smcall_stubs.c
+++ b/core/embed/sys/smcall/stm32/smcall_stubs.c
@@ -413,7 +413,7 @@ secbool secret_validate_nrf_pairing(const uint8_t *message, size_t msg_len,
// telemetry.h
// =============================================================================
-#include <util/telemetry.h>
+#include <sec/telemetry.h>
void telemetry_update_battery_temp(float temp_c) {
union {
diff --git a/core/embed/sys/smcall/stm32/smcall_verifiers.c b/core/embed/sys/smcall/stm32/smcall_verifiers.c
index ea5cf0628..b981d2405 100644
--- a/core/embed/sys/smcall/stm32/smcall_verifiers.c
+++ b/core/embed/sys/smcall/stm32/smcall_verifiers.c
@@ -575,7 +575,7 @@ access_violation:
#endif
#ifdef USE_TELEMETRY
-#include <util/telemetry.h>
+#include <sec/telemetry.h>
// Telemetry verifiers
void telemetry_update_battery_temp__verified(float temp_c) {
diff --git a/core/embed/sys/smcall/stm32/smcall_verifiers.h b/core/embed/sys/smcall/stm32/smcall_verifiers.h
index 1224aa0a3..4c5fb653f 100644
--- a/core/embed/sys/smcall/stm32/smcall_verifiers.h
+++ b/core/embed/sys/smcall/stm32/smcall_verifiers.h
@@ -169,7 +169,7 @@ secbool secret_validate_nrf_pairing__verified(const uint8_t *message,
// Telemetry
// ---------------------------------------------------------------------
-#include <util/telemetry.h>
+#include <sec/telemetry.h>
void telemetry_update_battery_temp__verified(float temp_c);
diff --git a/core/embed/util/telemetry/inc/util/telemetry.h b/core/embed/util/telemetry/inc/util/telemetry.h
deleted file mode 100644
index aec62fb98..000000000
--- a/core/embed/util/telemetry/inc/util/telemetry.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * This file is part of the Trezor project, https://trezor.io/
- *
- * Copyright (c) SatoshiLabs
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#pragma once
-
-#include <trezor_types.h>
-
-/**
- * @brief Telemetry data structure.
- */
-typedef struct {
- float min_temp_c; /**< Minimum recorded battery temperature in Celsius. */
- float max_temp_c; /**< Maximum recorded battery temperature in Celsius. */
-} telemetry_data_t;
-
-/**
- * @brief Record current battery temperature (in Celsius) into telemetry
- * storage.
- *
- * Updates persisted min/max values:
- * - minimum can only decrease
- * - maximum can only increase
- *
- * @param temp_c Current battery temperature in Celsius.
- */
-void telemetry_update_battery_temp(float temp_c);
-
-/**
- * @brief Retrieve stored min/max battery temperature (in Celsius).
- *
- * @param[out] out Pointer to where the telemetry data will be stored (may be
- * NULL).
- *
- * @return true if values are available (initialized), false otherwise.
- */
-bool telemetry_get(telemetry_data_t* out);
diff --git a/core/embed/util/telemetry/telemetry.c b/core/embed/util/telemetry/telemetry.c
deleted file mode 100644
index 842a9a600..000000000
--- a/core/embed/util/telemetry/telemetry.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * This file is part of the Trezor project, https://trezor.io/
- *
- * Copyright (c) SatoshiLabs
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifdef SECURE_MODE
-
-#include <trezor_types.h>
-
-#include <sys/backup_ram.h>
-
-#include <util/telemetry.h>
-
-// Versioning for persisted telemetry structure
-#define TELEMETRY_DATA_VERSION 0x0001
-
-typedef struct {
- uint16_t version;
- uint8_t initialized; // 0 = not set, 1 = valid data present
- uint8_t reserved; // alignment/padding
- telemetry_data_t data;
-} telemetry_t;
-
-static bool telemetry_read(telemetry_t* out) {
- size_t size = 0;
- if (!backup_ram_read(BACKUP_RAM_KEY_TELEMETRY, out, sizeof(*out), &size)) {
- return false;
- }
- if (size != sizeof(*out)) {
- return false;
- }
- if (out->version != TELEMETRY_DATA_VERSION) {
- return false;
- }
- return true;
-}
-
-static bool telemetry_write(const telemetry_t* data) {
- return backup_ram_write(BACKUP_RAM_KEY_TELEMETRY, BACKUP_RAM_ITEM_PUBLIC,
- data, sizeof(*data));
-}
-
-void telemetry_update_battery_temp(float temp_c) {
- telemetry_t telemetry;
- bool have = telemetry_read(&telemetry) && telemetry.initialized == 1;
-
- if (!have) {
- telemetry.version = TELEMETRY_DATA_VERSION;
- telemetry.initialized = 1;
- telemetry.reserved = 0;
- telemetry.data.min_temp_c = temp_c;
- telemetry.data.max_temp_c = temp_c;
- telemetry_write(&telemetry);
- return;
- }
-
- bool changed = false;
- if (temp_c < telemetry.data.min_temp_c) {
- telemetry.data.min_temp_c = temp_c; // min can only decrease
- changed = true;
- }
- if (temp_c > telemetry.data.max_temp_c) {
- telemetry.data.max_temp_c = temp_c; // max can only increase
- changed = true;
- }
-
- if (changed) {
- telemetry_write(&telemetry);
- }
-}
-
-bool telemetry_get(telemetry_data_t* out) {
- telemetry_t telemetry;
- if (!telemetry_read(&telemetry) || telemetry.initialized != 1) {
- return false;
- }
- if (out != NULL) {
- *out = telemetry.data;
- }
- return true;
-}
-
-#endif
diff --git a/core/site_scons/models/T3W1/trezor_t3w1_revC.py b/core/site_scons/models/T3W1/trezor_t3w1_revC.py
index 178fdf9d2..fc47cdade 100644
--- a/core/site_scons/models/T3W1/trezor_t3w1_revC.py
+++ b/core/site_scons/models/T3W1/trezor_t3w1_revC.py
@@ -238,8 +238,8 @@ def configure(
sources += ["embed/sec/hw_revision/stm32/hw_revision.c"]
if "telemetry" in features_wanted:
- sources += ["embed/util/telemetry/telemetry.c"]
- paths += ["embed/util/telemetry/inc"]
+ sources += ["embed/sec/telemetry/telemetry.c"]
+ paths += ["embed/sec/telemetry/inc"]
defines += [("USE_TELEMETRY", "1")]
defines += [
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.