chore(core): decouple logging functionality from PYOPT=0
What changed, and why it matters
This is a small internal build-system cleanup. It moves the optional debug logging module so it can be compiled into optimized (non-debug) firmware builds when the debug console feature is enabled. There is no user-facing behavior change, no vulnerability fix, and no security-relevant change.
No security action required. Review as normal build cleanup if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit removes the !PYOPT (non-optimized/debug build) guard around the trezorlog Rust module and the logging micropython submodule. Previously, logging was only available when both PYOPT=0 and USE_DBG_CONSOLE were set. After the change, logging is available whenever USE_DBG_CONSOLE is set, including optimized builds. The Type::name() helper is also enabled under dbg_console because the logging code uses it. This is a feature-build configuration change, not a runtime security control change.
Changed components
core/embed/rust/librust.hcore/embed/rust/src/micropython/mod.rscore/embed/rust/src/micropython/typ.rscore/embed/upymod/rustmods.ccore/src/trezor/log.pyInspect captured patch +7 / −7
diff --git a/core/embed/rust/librust.h b/core/embed/rust/librust.h
index 340f18d5..30bf0742 100644
--- a/core/embed/rust/librust.h
+++ b/core/embed/rust/librust.h
@@ -12,12 +12,13 @@ extern mp_obj_module_t mp_module_trezorui_api;
extern mp_obj_module_t mp_module_trezortranslate;
extern mp_obj_module_t mp_module_trezorble;
-#if !PYOPT
-mp_obj_t ui_debug_layout_type();
#ifdef USE_DBG_CONSOLE
extern mp_obj_module_t mp_module_trezorlog;
#endif
+#if !PYOPT
+mp_obj_t ui_debug_layout_type();
+
#ifdef TREZOR_EMULATOR
extern mp_obj_module_t mp_module_coveragedata;
#endif
diff --git a/core/embed/rust/src/micropython/mod.rs b/core/embed/rust/src/micropython/mod.rs
index b6ec68c6..49887713 100644
--- a/core/embed/rust/src/micropython/mod.rs
+++ b/core/embed/rust/src/micropython/mod.rs
@@ -19,7 +19,7 @@ pub mod simple_type;
pub mod typ;
pub mod util;
-#[cfg(all(feature = "debug", feature = "dbg_console"))]
+#[cfg(feature = "dbg_console")]
pub mod logging;
#[cfg(test)]
diff --git a/core/embed/rust/src/micropython/typ.rs b/core/embed/rust/src/micropython/typ.rs
index 007c03e8..1a277deb 100644
--- a/core/embed/rust/src/micropython/typ.rs
+++ b/core/embed/rust/src/micropython/typ.rs
@@ -25,7 +25,7 @@ impl Type {
unsafe { Obj::from_ptr(self as *const _ as *mut _) }
}
- #[cfg(feature = "debug")]
+ #[cfg(any(feature = "debug", feature = "dbg_console"))]
pub fn name(&self) -> &'static str {
use super::qstr::Qstr;
diff --git a/core/embed/upymod/rustmods.c b/core/embed/upymod/rustmods.c
index 111fd5c0..20bb769e 100644
--- a/core/embed/upymod/rustmods.c
+++ b/core/embed/upymod/rustmods.c
@@ -40,6 +40,6 @@ MP_REGISTER_MODULE(MP_QSTR_trezorble, mp_module_trezorble);
MP_REGISTER_MODULE(MP_QSTR_coveragedata, mp_module_coveragedata);
#endif
-#if !PYOPT && defined(USE_DBG_CONSOLE)
+#if defined(USE_DBG_CONSOLE)
MP_REGISTER_MODULE(MP_QSTR_trezorlog, mp_module_trezorlog);
#endif
diff --git a/core/src/trezor/log.py b/core/src/trezor/log.py
index 461e9316..4b385b13 100644
--- a/core/src/trezor/log.py
+++ b/core/src/trezor/log.py
@@ -12,7 +12,7 @@ def _no_op(name: str, msg: str, *args: Any, iface: WireInterface | None = None)
return None
-if __debug__ and utils.USE_DBG_CONSOLE:
+if utils.USE_DBG_CONSOLE:
from trezorlog import debug, error, info, init, warning # noqa: F401
_levels = [debug, info, warning, error]
@@ -20,7 +20,6 @@ if __debug__ and utils.USE_DBG_CONSOLE:
debug, info, warning, error = [_no_op] * _min_level + _levels[_min_level:]
init(_min_level) # initialize rust logging connector
else:
- # logging is disabled in non-debug builds
debug = warning = info = error = _no_op
Why this scored 15/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.