refactor(core): remove circular dependencies, new 'storage' feature
What changed, and why it matters
This is a large internal code reorganization in Trezor's embedded firmware. It moves flash/storage headers and build flags around so different firmware images (bootloader, kernel, production test, etc.) declare more explicitly which features they need. There is no obvious security bug introduced, but the change touches low-level memory-layout and storage code, so any mistake could in principle affect how secrets are stored. The commit itself is labeled a refactor and includes no changelog.
Treat as a normal refactor review. Verify that the new feature flags correctly preserve the previous KERNEL_MODE/SECURE_MODE coverage for each firmware target, that the MPU storage-size calculation remains equivalent (NORCOW_SECTOR_COUNT == 2 and STORAGE_AREAS_COUNT was 2), and that removing flash_init() from the Rust storage test does not hide a real initialization requirement. No immediate security response is indicated.
Security signals we found
Low-level flash layout and storage initialization code is reorganized
KERNEL_MODE / SECURE_MODE compile-time guards are changed to feature flags
Storage sector count macro changed from STORAGE_AREAS_COUNT to NORCOW_SECTOR_COUNT in MPU sizing
Rust storage test removes explicit flash_init() call
No changelog and no explicit security framing by vendor
Evidence from the diff
The commit refactors build configuration and header dependencies to remove circular includes and introduce a new ‘storage’ feature flag. It replaces compile-time defines KERNEL_MODE/SECURE_MODE with SCons feature flags (‘kernel_mode’, ‘secure_mode’, ‘storage’), moves norcow_config.h and flash-area definitions into a unified util/flash path, gates storage-related Rust modules and UI brightness code behind the ‘storage’ feature, and wraps several low-level C files in KERNEL_MODE/SECURE_MODE guards. A few functional side effects appear: mpu.c now uses NORCOW_SECTOR_COUNT instead of STORAGE_AREAS_COUNT for the storage size calculation, boot_image.c changes when uzlib is included, and the Rust storage test no longer calls flash_init() before init().
Changed components
core/SConscript.* build scriptscore/embed/util/flash/flash layout and norcow config headerscore/embed/sec/storage storage setupcore/embed/rust storage bindings and UI backlight codecore/embed/sys/mpu/stm32u5/mpu.ccore/embed/util/image/image.cstorage/flash_area.hstorage/storage.cInspect captured patch +238 / −246
diff --git a/core/SConscript.boardloader b/core/SConscript.boardloader
index f9903543..a9c4768c 100644
--- a/core/SConscript.boardloader
+++ b/core/SConscript.boardloader
@@ -10,9 +10,11 @@ HW_REVISION = ARGUMENTS.get('HW_REVISION', None)
FEATURES_WANTED = [
"boot_ucb",
"display",
+ "kernel_mode",
"pmic",
"sd_card",
"secure_domain",
+ "secure_mode",
]
CCFLAGS_MOD = ''
@@ -37,19 +39,14 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_
CCFLAGS_MOD += '-Wno-sequence-point '
CPPPATH_MOD += [
'vendor/trezor-crypto',
- 'vendor/trezor-storage',
]
CPPDEFINES_MOD += [
- 'KERNEL_MODE',
- 'SECURE_MODE',
'AES_128',
'AES_192',
'USE_KECCAK',
'ED25519_NO_PRECOMP',
]
-SOURCE_MOD += [
- 'vendor/trezor-storage/flash_area.c',
-]
+
SOURCE_MOD_CRYPTO += [
'vendor/trezor-crypto/blake2s.c',
'vendor/trezor-crypto/ed25519-donna/curve25519-donna-32bit.c',
diff --git a/core/SConscript.bootloader b/core/SConscript.bootloader
index 0f98bf75..7e6dcc4e 100644
--- a/core/SConscript.bootloader
+++ b/core/SConscript.bootloader
@@ -19,10 +19,12 @@ FEATURES_WANTED = [
"dma2d",
"input",
"iwdg",
+ "kernel_mode",
"power_manager",
"rgb_led",
"rtc",
"secure_domain",
+ "secure_mode",
"suspend",
"usb",
]
@@ -55,11 +57,8 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_
CCFLAGS_MOD += '-Wno-sequence-point '
CPPPATH_MOD += [
'vendor/trezor-crypto',
- 'vendor/trezor-storage',
]
CPPDEFINES_MOD += [
- 'KERNEL_MODE',
- 'SECURE_MODE',
'AES_128',
'AES_192',
'USE_KECCAK',
@@ -67,9 +66,6 @@ CPPDEFINES_MOD += [
'FANCY_FATAL_ERROR',
]
-SOURCE_MOD += [
- 'vendor/trezor-storage/flash_area.c',
-]
SOURCE_MOD_CRYPTO = [
'vendor/trezor-crypto/blake2s.c',
'vendor/trezor-crypto/chacha_drbg.c',
diff --git a/core/SConscript.bootloader_ci b/core/SConscript.bootloader_ci
index ac720500..0e5b4c35 100644
--- a/core/SConscript.bootloader_ci
+++ b/core/SConscript.bootloader_ci
@@ -12,9 +12,11 @@ FEATURES_WANTED = [
"consumption_mask",
"display",
"input",
+ "kernel_mode",
"powerctl",
"rgb_led",
"secure_domain",
+ "secure_mode",
"usb",
]
@@ -42,19 +44,14 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_
CCFLAGS_MOD += '-Wno-sequence-point '
CPPPATH_MOD += [
'vendor/trezor-crypto',
- 'vendor/trezor-storage',
]
CPPDEFINES_MOD += [
- 'KERNEL_MODE',
- 'SECURE_MODE',
'AES_128',
'AES_192',
'USE_KECCAK',
'ED25519_NO_PRECOMP',
]
-SOURCE_MOD += [
- 'vendor/trezor-storage/flash_area.c',
-]
+
SOURCE_MOD_CRYPTO += [
'vendor/trezor-crypto/blake2s.c',
'vendor/trezor-crypto/chacha_drbg.c',
diff --git a/core/SConscript.bootloader_emu b/core/SConscript.bootloader_emu
index 7db9f59c..a4a5d01e 100644
--- a/core/SConscript.bootloader_emu
+++ b/core/SConscript.bootloader_emu
@@ -25,8 +25,10 @@ FEATURES_WANTED = [
"display",
"dma2d",
"input",
+ "kernel_mode",
"power_manager",
"rgb_led",
+ "secure_mode",
]
CCFLAGS_MOD = ''
@@ -42,11 +44,8 @@ RUST_UI_FEATURES = []
CCFLAGS_MOD += '-Wno-sequence-point '
CPPPATH_MOD += [
'vendor/trezor-crypto',
- 'vendor/trezor-storage',
]
CPPDEFINES_MOD += [
- 'KERNEL_MODE',
- 'SECURE_MODE',
'AES_128',
'AES_192',
'USE_KECCAK',
@@ -95,7 +94,6 @@ SOURCE_MOD += [
'vendor/micropython/lib/uzlib/adler32.c',
'vendor/micropython/lib/uzlib/crc32.c',
'vendor/micropython/lib/uzlib/tinflate.c',
- 'vendor/trezor-storage/flash_area.c',
]
SOURCE_NANOPB = [
diff --git a/core/SConscript.firmware b/core/SConscript.firmware
index 3a513e35..e7e7cb58 100644
--- a/core/SConscript.firmware
+++ b/core/SConscript.firmware
@@ -60,6 +60,7 @@ FEATURES_WANTED = [
"rgb_led",
"sd_card",
"secmon_layout",
+ "storage",
"suspend",
"tropic",
"usb",
@@ -85,7 +86,6 @@ FROZEN = True
# modtrezorconfig
CPPPATH_MOD += [
'embed/upymod/modtrezorconfig',
- 'vendor/trezor-storage',
]
SOURCE_MOD += [
'embed/upymod/modtrezorconfig/modtrezorconfig.c',
@@ -471,7 +471,6 @@ ALLPATHS = [
'embed/rtl/inc',
'embed/models',
'embed/gfx/inc',
- 'embed/sec/storage/inc',
'embed/sys/bsp/inc',
'embed/util/image/inc',
'embed/util/rsod/inc',
diff --git a/core/SConscript.kernel b/core/SConscript.kernel
index f3edf085..d9c85f8c 100644
--- a/core/SConscript.kernel
+++ b/core/SConscript.kernel
@@ -39,6 +39,7 @@ FEATURES_WANTED = [
"dma2d",
"haptic",
"input",
+ "kernel_mode",
"optiga",
"power_manager",
"rgb_led",
@@ -46,12 +47,15 @@ FEATURES_WANTED = [
"sd_card",
"secmon_layout",
"smp",
+ "storage",
"suspend",
"tropic",
"usb",
-
]
+if not TREZOR_MODEL in ['T3W1', 'D002']:
+ FEATURES_WANTED += ["secure_mode"]
+
if DISABLE_OPTIGA:
# TODO use PYOPT instead of PRODUCTION, same as in firmware, blocked on #4253
if PRODUCTION:
@@ -69,23 +73,12 @@ PATH_HAL = []
FROZEN = True
-# modtrezorconfig
-CPPPATH_MOD += [
- 'embed/upymod/modtrezorconfig',
- 'vendor/trezor-storage',
- 'vendor/micropython/lib/uzlib',
-]
-SOURCE_MOD += [
- 'vendor/trezor-storage/flash_area.c',
-]
-
# modtrezorcrypto
CCFLAGS_MOD += '-Wno-sequence-point '
CPPPATH_MOD += [
'vendor/trezor-crypto',
]
CPPDEFINES_MOD += [
- 'KERNEL_MODE',
'AES_128',
'AES_192',
('USE_BIP32_CACHE', '0'),
@@ -97,9 +90,6 @@ CPPDEFINES_MOD += [
('USE_EOS', '1' if (EVERYTHING and TREZOR_MODEL == "T2T1") else '0'),
]
-if not TREZOR_MODEL in ['T3W1', 'D002']:
- CPPDEFINES_MOD += ['SECURE_MODE']
-
SOURCE_MOD_CRYPTO += [
'vendor/trezor-crypto/address.c',
'vendor/trezor-crypto/aes/aes_modes.c',
@@ -218,6 +208,10 @@ SOURCE_MOD += [
'vendor/micropython/lib/uzlib/tinflate.c',
]
+CPPPATH_MOD += [
+ 'vendor/micropython/lib/uzlib',
+]
+
CPPDEFINES_MOD += [
'TRANSLATIONS',
'RSOD_IN_COREAPP',
@@ -269,15 +263,6 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_
FEATURE_FLAGS["AES_GCM"] = FEATURE_FLAGS["AES_GCM"] or "tropic" in FEATURES_AVAILABLE
-if not 'secmon_layout' in FEATURES_AVAILABLE:
- SOURCE_MOD += [
- 'embed/sec/storage/storage_setup.c',
- 'vendor/trezor-storage/norcow.c',
- 'vendor/trezor-storage/storage.c',
- 'vendor/trezor-storage/storage_utils.c',
- ]
-
-
# AES-GCM
if FEATURE_FLAGS["AES_GCM"]:
CPPDEFINES_MOD += [
@@ -321,7 +306,6 @@ ALLPATHS = [
'embed/rtl/inc',
'embed/models',
'embed/gfx/inc',
- 'embed/sec/storage/inc',
'embed/sys/bsp/inc',
'embed/util/image/inc',
'embed/util/rsod/inc',
diff --git a/core/SConscript.prodtest b/core/SConscript.prodtest
index 3a7ce440..d421a285 100644
--- a/core/SConscript.prodtest
+++ b/core/SConscript.prodtest
@@ -28,6 +28,7 @@ FEATURES_WANTED = [
"haptic",
"hw_revision",
"input",
+ "kernel_mode",
"nfc",
"optiga",
"power_manager",
@@ -36,6 +37,7 @@ FEATURES_WANTED = [
"sbu",
"sd_card",
"secure_domain",
+ "secure_mode",
"smp",
"suspend",
"tropic",
@@ -45,8 +47,6 @@ FEATURES_WANTED = [
CCFLAGS_MOD = ''
CPPPATH_MOD = []
CPPDEFINES_MOD = [
- 'KERNEL_MODE',
- 'SECURE_MODE',
'AES_128',
'USE_INSECURE_PRNG',
]
@@ -70,11 +70,8 @@ FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_
# modtrezorcrypto
CPPPATH_MOD += [
'vendor/trezor-crypto',
- 'vendor/trezor-storage',
-]
-SOURCE_MOD += [
- 'vendor/trezor-storage/flash_area.c',
]
+
SOURCE_MOD_CRYPTO += [
'vendor/trezor-crypto/aes/aes_modes.c',
'vendor/trezor-crypto/aes/aesccm.c',
@@ -241,6 +238,7 @@ ALLPATHS = [
'embed/models',
'embed/gfx/inc',
'embed/sys/bsp/inc',
+ 'embed/sec/storage/inc',
'embed/util/image/inc',
'embed/util/rsod/inc',
'embed/util/scm_revision/inc',
diff --git a/core/SConscript.prodtest_emu b/core/SConscript.prodtest_emu
index d11257fa..80d7e273 100644
--- a/core/SConscript.prodtest_emu
+++ b/core/SConscript.prodtest_emu
@@ -24,13 +24,20 @@ if not models.has_emulator(TREZOR_MODEL):
)
Return()
-FEATURES_WANTED = ["input", "rgb_led", "display", "tropic", "sd_card", "usb"]
+FEATURES_WANTED = [
+ "display",
+ "input",
+ "kernel_mode",
+ "rgb_led",
+ "sd_card",
+ "secure_mode",
+ "tropic",
+ "usb"
+]
CCFLAGS_MOD = ''
CPPPATH_MOD = []
CPPDEFINES_MOD = [
- 'KERNEL_MODE',
- 'SECURE_MODE',
'AES_128',
'USE_INSECURE_PRNG',
]
@@ -44,11 +51,8 @@ RUST_UI_FEATURES = []
# modtrezorcrypto
CPPPATH_MOD += [
'vendor/trezor-crypto',
- 'vendor/trezor-storage',
-]
-SOURCE_MOD += [
- 'vendor/trezor-storage/flash_area.c',
]
+
SOURCE_MOD_CRYPTO += [
'vendor/trezor-crypto/aes/aes_modes.c',
'vendor/trezor-crypto/aes/aesccm.c',
diff --git a/core/SConscript.secmon b/core/SConscript.secmon
index 4b07d1ed..00e57f5c 100644
--- a/core/SConscript.secmon
+++ b/core/SConscript.secmon
@@ -35,8 +35,11 @@ FEATURES_WANTED = [
"boot_ucb",
"consumption_mask",
"optiga",
+ "kernel_mode",
"secmon_layout",
"secure_domain",
+ "secure_mode",
+ "storage",
"suspend",
"tropic",
]
@@ -68,28 +71,12 @@ env = Environment(
FEATURES_AVAILABLE = models.configure_board(TREZOR_MODEL, HW_REVISION, FEATURES_WANTED, env, CPPDEFINES_HAL, SOURCE_HAL, PATH_HAL)
-# modtrezorconfig
-CPPPATH_MOD += [
- 'embed/upymod/modtrezorconfig',
- 'vendor/trezor-storage',
- 'vendor/micropython/lib/uzlib',
-]
-SOURCE_MOD += [
- 'embed/sec/storage/storage_setup.c',
- 'vendor/trezor-storage/norcow.c',
- 'vendor/trezor-storage/storage.c',
- 'vendor/trezor-storage/storage_utils.c',
- 'vendor/trezor-storage/flash_area.c',
-]
-
# modtrezorcrypto
CCFLAGS_MOD += '-Wno-sequence-point '
CPPPATH_MOD += [
'vendor/trezor-crypto',
]
CPPDEFINES_MOD += [
- 'KERNEL_MODE',
- 'SECURE_MODE',
'AES_128',
'AES_192',
('USE_BIP32_CACHE', '0'),
@@ -321,7 +308,6 @@ ALLPATHS = [
'embed/rtl/inc',
'embed/models',
'embed/gfx/inc',
- 'embed/sec/storage/inc',
'embed/sys/bsp/inc',
'embed/util/image/inc',
'embed/util/rsod/inc',
diff --git a/core/SConscript.unix b/core/SConscript.unix
index 2ec16ec9..644b741e 100644
--- a/core/SConscript.unix
+++ b/core/SConscript.unix
@@ -27,10 +27,13 @@ FEATURES_WANTED = [
"display",
"dma2d",
"input",
+ "kernel_mode",
"optiga",
"powerctl",
"rgb_led",
"sd_card",
+ "secure_mode",
+ "storage",
]
if not DISABLE_TROPIC:
@@ -66,15 +69,9 @@ RUST_UI_FEATURES = []
# modtrezorconfig
CPPPATH_MOD += [
'embed/upymod/modtrezorconfig',
- 'vendor/trezor-storage',
]
SOURCE_MOD += [
'embed/upymod/modtrezorconfig/modtrezorconfig.c',
- 'embed/sec/storage/storage_setup.c',
- 'vendor/trezor-storage/norcow.c',
- 'vendor/trezor-storage/storage.c',
- 'vendor/trezor-storage/storage_utils.c',
- 'vendor/trezor-storage/flash_area.c',
]
# modtrezorcrypto
@@ -83,8 +80,6 @@ CPPPATH_MOD += [
'vendor/trezor-crypto',
]
CPPDEFINES_MOD += [
- 'KERNEL_MODE',
- 'SECURE_MODE',
'AES_128',
'AES_192',
'USE_INSECURE_PRNG',
@@ -486,7 +481,6 @@ ALLPATHS=['.',
'embed/util/rsod/inc',
'embed/util/scm_revision/inc',
'embed/util/translations/inc',
- 'embed/sec/storage/inc',
'vendor/micropython',
'vendor/micropython/ports/unix',
'vendor/micropython/lib/mp-readline',
diff --git a/core/embed/models/trezor_model.h b/core/embed/models/trezor_model.h
index 2d307d48..21c420fa 100644
--- a/core/embed/models/trezor_model.h
+++ b/core/embed/models/trezor_model.h
@@ -1,5 +1,4 @@
#pragma once
-#include <util/flash_layout.h>
-#include "otp_layout.h"
#include MODEL_HEADER
+#include "otp_layout.h"
diff --git a/core/embed/projects/prodtest/cmd/prodtest_boardloader.c b/core/embed/projects/prodtest/cmd/prodtest_boardloader.c
index e9da9682..ba5fe7fa 100644
--- a/core/embed/projects/prodtest/cmd/prodtest_boardloader.c
+++ b/core/embed/projects/prodtest/cmd/prodtest_boardloader.c
@@ -19,11 +19,10 @@
#include <trezor_rtl.h>
-#include <flash_area.h>
#include <rtl/cli.h>
#include <sys/mpu.h>
#include <util/board_capabilities.h>
-#include <util/flash_layout.h>
+#include <util/flash.h>
#include "common.h"
diff --git a/core/embed/rust/Cargo.toml b/core/embed/rust/Cargo.toml
index e85bef2b..07443c79 100644
--- a/core/embed/rust/Cargo.toml
+++ b/core/embed/rust/Cargo.toml
@@ -51,6 +51,7 @@ ble = []
nrf = []
smp = []
tropic = []
+storage = []
translations = ["crypto"]
secmon_layout = []
test = [
@@ -66,6 +67,7 @@ test = [
"optiga",
"protobuf",
"smp",
+ "storage",
"touch",
"translations",
"ui",
diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs
index f3b431ff..8d0c547b 100644
--- a/core/embed/rust/build.rs
+++ b/core/embed/rust/build.rs
@@ -33,6 +33,7 @@ const DEFAULT_BINDGEN_MACROS_COMMON: &[&str] = &[
"-I../../../storage",
"-I../../vendor/micropython",
"-I../../vendor/micropython/lib/uzlib",
+ "-I../../vendor/",
"-I../rtl/inc",
"-I../gfx/inc",
"-I../io/ble/inc",
@@ -44,6 +45,7 @@ const DEFAULT_BINDGEN_MACROS_COMMON: &[&str] = &[
"-I../io/rgb_led/inc",
"-I../io/usb/inc",
"-I../sec/entropy/inc",
+ "-I../sec/storage/inc",
"-I../sys/time/inc",
"-I../sys/task/inc",
"-I../sys/power_manager/inc",
@@ -61,6 +63,7 @@ const DEFAULT_BINDGEN_MACROS_COMMON: &[&str] = &[
"-DUSE_POWER_MANAGER",
"-DUSE_NRF",
"-DUSE_HW_JPEG_DECODER",
+ "-DUSE_STORAGE",
];
fn add_bindgen_macros<'a>(
@@ -329,8 +332,6 @@ fn generate_trezorhal_bindings() {
.must_use_type("secbool")
.allowlist_var("sectrue")
.allowlist_var("secfalse")
- // flash
- .allowlist_function("flash_init")
// storage
.allowlist_var("EXTERNAL_SALT_SIZE")
.allowlist_function("storage_setup")
diff --git a/core/embed/rust/src/lib.rs b/core/embed/rust/src/lib.rs
index a710f41f..2686f503 100644
--- a/core/embed/rust/src/lib.rs
+++ b/core/embed/rust/src/lib.rs
@@ -31,6 +31,7 @@ mod maybe_trace;
mod micropython;
#[cfg(feature = "protobuf")]
mod protobuf;
+#[cfg(feature = "storage")]
mod storage;
mod strutil;
mod time;
diff --git a/core/embed/rust/src/trezorhal/mod.rs b/core/embed/rust/src/trezorhal/mod.rs
index f8549d0d..d17a8d4b 100644
--- a/core/embed/rust/src/trezorhal/mod.rs
+++ b/core/embed/rust/src/trezorhal/mod.rs
@@ -25,6 +25,7 @@ pub mod random;
#[cfg(feature = "rgb_led")]
pub mod rgb_led;
pub mod slip39;
+#[cfg(feature = "storage")]
pub mod storage;
#[cfg(feature = "translations")]
pub mod translations;
diff --git a/core/embed/rust/src/trezorhal/storage.rs b/core/embed/rust/src/trezorhal/storage.rs
index 1322c616..f790f2a5 100644
--- a/core/embed/rust/src/trezorhal/storage.rs
+++ b/core/embed/rust/src/trezorhal/storage.rs
@@ -260,9 +260,6 @@ mod tests {
const APPKEY: u16 = 0x0101;
fn init_storage(unlock: bool) {
- unsafe {
- ffi::flash_init();
- }
init();
wipe();
lock();
diff --git a/core/embed/rust/src/ui/layout_bolt/component/mod.rs b/core/embed/rust/src/ui/layout_bolt/component/mod.rs
index c6170e87..feda2a47 100644
--- a/core/embed/rust/src/ui/layout_bolt/component/mod.rs
+++ b/core/embed/rust/src/ui/layout_bolt/component/mod.rs
@@ -27,6 +27,7 @@ mod page;
mod progress;
mod result;
mod scroll;
+#[cfg(feature = "storage")]
mod set_brightness;
#[cfg(feature = "translations")]
mod share_words;
@@ -65,6 +66,7 @@ pub use page::ButtonPage;
pub use progress::Progress;
pub use result::{ResultFooter, ResultScreen, ResultStyle};
pub use scroll::ScrollBar;
+#[cfg(feature = "storage")]
pub use set_brightness::SetBrightnessDialog;
#[cfg(feature = "translations")]
pub use share_words::ShareWords;
diff --git a/core/embed/rust/src/ui/layout_bolt/theme/backlight.rs b/core/embed/rust/src/ui/layout_bolt/theme/backlight.rs
index 46831336..71c09f66 100644
--- a/core/embed/rust/src/ui/layout_bolt/theme/backlight.rs
+++ b/core/embed/rust/src/ui/layout_bolt/theme/backlight.rs
@@ -1,4 +1,4 @@
-#[cfg(not(any(feature = "bootloader", feature = "prodtest")))]
+#[cfg(feature = "storage")]
use crate::storage;
// Typical backlight values.
@@ -9,24 +9,24 @@ const BACKLIGHT_NONE: u8 = 0;
const BACKLIGHT_MIN: u8 = 10;
const BACKLIGHT_MAX: u8 = 255;
-#[cfg(any(feature = "bootloader", feature = "prodtest"))]
+#[cfg(not(feature = "storage"))]
pub fn get_backlight_normal() -> u8 {
BACKLIGHT_NORMAL
}
-#[cfg(not(any(feature = "bootloader", feature = "prodtest")))]
+#[cfg(feature = "storage")]
pub fn get_backlight_normal() -> u8 {
storage::get_brightness()
.unwrap_or(BACKLIGHT_NORMAL)
.clamp(BACKLIGHT_MIN, BACKLIGHT_MAX)
}
-#[cfg(any(feature = "bootloader", feature = "prodtest"))]
+#[cfg(not(feature = "storage"))]
pub fn get_backlight_low() -> u8 {
BACKLIGHT_LOW
}
-#[cfg(not(any(feature = "bootloader", feature = "prodtest")))]
+#[cfg(feature = "storage")]
pub fn get_backlight_low() -> u8 {
storage::get_brightness()
.unwrap_or(BACKLIGHT_LOW)
diff --git a/core/embed/rust/src/ui/layout_delizia/theme/backlight.rs b/core/embed/rust/src/ui/layout_delizia/theme/backlight.rs
index fd92eed5..71c09f66 100644
--- a/core/embed/rust/src/ui/layout_delizia/theme/backlight.rs
+++ b/core/embed/rust/src/ui/layout_delizia/theme/backlight.rs
@@ -1,4 +1,4 @@
-#[cfg(not(feature = "bootloader"))]
+#[cfg(feature = "storage")]
use crate::storage;
// Typical backlight values.
@@ -9,24 +9,24 @@ const BACKLIGHT_NONE: u8 = 0;
const BACKLIGHT_MIN: u8 = 10;
const BACKLIGHT_MAX: u8 = 255;
-#[cfg(feature = "bootloader")]
+#[cfg(not(feature = "storage"))]
pub fn get_backlight_normal() -> u8 {
BACKLIGHT_NORMAL
}
-#[cfg(not(feature = "bootloader"))]
+#[cfg(feature = "storage")]
pub fn get_backlight_normal() -> u8 {
storage::get_brightness()
.unwrap_or(BACKLIGHT_NORMAL)
.clamp(BACKLIGHT_MIN, BACKLIGHT_MAX)
}
-#[cfg(feature = "bootloader")]
+#[cfg(not(feature = "storage"))]
pub fn get_backlight_low() -> u8 {
BACKLIGHT_LOW
}
-#[cfg(not(feature = "bootloader"))]
+#[cfg(feature = "storage")]
pub fn get_backlight_low() -> u8 {
storage::get_brightness()
.unwrap_or(BACKLIGHT_LOW)
diff --git a/core/embed/rust/src/ui/layout_eckhart/theme/backlight.rs b/core/embed/rust/src/ui/layout_eckhart/theme/backlight.rs
index fd92eed5..fa204d63 100644
--- a/core/embed/rust/src/ui/layout_eckhart/theme/backlight.rs
+++ b/core/embed/rust/src/ui/layout_eckhart/theme/backlight.rs
@@ -1,4 +1,4 @@
-#[cfg(not(feature = "bootloader"))]
+#[cfg(feature = "storage")]
use crate::storage;
// Typical backlight values.
@@ -9,24 +9,23 @@ const BACKLIGHT_NONE: u8 = 0;
const BACKLIGHT_MIN: u8 = 10;
const BACKLIGHT_MAX: u8 = 255;
-#[cfg(feature = "bootloader")]
+#[cfg(not(feature = "storage"))]
pub fn get_backlight_normal() -> u8 {
BACKLIGHT_NORMAL
}
-#[cfg(not(feature = "bootloader"))]
+#[cfg(feature = "storage")]
pub fn get_backlight_normal() -> u8 {
storage::get_brightness()
.unwrap_or(BACKLIGHT_NORMAL)
.clamp(BACKLIGHT_MIN, BACKLIGHT_MAX)
}
-#[cfg(feature = "bootloader")]
+#[cfg(not(feature = "storage"))]
pub fn get_backlight_low() -> u8 {
BACKLIGHT_LOW
}
-
-#[cfg(not(feature = "bootloader"))]
+#[cfg(feature = "storage")]
pub fn get_backlight_low() -> u8 {
storage::get_brightness()
.unwrap_or(BACKLIGHT_LOW)
diff --git a/core/embed/rust/trezorhal.h b/core/embed/rust/trezorhal.h
index ed0d0c90..ef13e3c5 100644
--- a/core/embed/rust/trezorhal.h
+++ b/core/embed/rust/trezorhal.h
@@ -7,7 +7,6 @@
#include <io/display_utils.h>
#include <io/usb.h>
#include <rtl/secbool.h>
-#include <sec/storage.h>
#include <sys/irq.h>
#include <sys/sysevent.h>
#include <sys/systick.h>
@@ -51,6 +50,10 @@
#include <sys/suspend.h>
#endif
+#ifdef USE_STORAGE
+#include <sec/storage.h>
+#endif
+
#include "bip39.h"
#include "rand.h"
#include "slip39.h"
diff --git a/core/embed/sec/entropy/stm32u5/entropy.c b/core/embed/sec/entropy/stm32u5/entropy.c
index 6d0b45a9..8720649e 100644
--- a/core/embed/sec/entropy/stm32u5/entropy.c
+++ b/core/embed/sec/entropy/stm32u5/entropy.c
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef SECURE_MODE
+
#include <trezor_model.h>
#include <trezor_rtl.h>
@@ -29,8 +31,6 @@
#include "stm32u5xx_ll_utils.h"
-#ifdef SECURE_MODE
-
static entropy_data_t g_entropy = {0};
#ifdef SECRET_PRIVILEGED_MASTER_KEY_SLOT
diff --git a/core/embed/sec/monoctr/stm32u5/monoctr.c b/core/embed/sec/monoctr/stm32u5/monoctr.c
index ef6102ed..af87f1ec 100644
--- a/core/embed/sec/monoctr/stm32u5/monoctr.c
+++ b/core/embed/sec/monoctr/stm32u5/monoctr.c
@@ -24,7 +24,7 @@
#include <sec/monoctr.h>
#include <sec/secret.h>
#include <sys/mpu.h>
-#include "flash_area.h"
+#include <util/flash.h>
static int32_t get_offset(monoctr_type_t type) {
switch (type) {
diff --git a/core/embed/sec/storage/inc/sec/storage.h b/core/embed/sec/storage/inc/sec/storage.h
index 8fffed21..d92c2ede 100644
--- a/core/embed/sec/storage/inc/sec/storage.h
+++ b/core/embed/sec/storage/inc/sec/storage.h
@@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <vendor/trezor-storage/storage.h>
+#include <trezor-storage/storage.h>
/**
* Initialize storage and optionally register a UI progress callback.
diff --git a/core/embed/sys/mpu/stm32u5/mpu.c b/core/embed/sys/mpu/stm32u5/mpu.c
index da52d66e..1dc4bceb 100644
--- a/core/embed/sys/mpu/stm32u5/mpu.c
+++ b/core/embed/sys/mpu/stm32u5/mpu.c
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef KERNEL_MODE
+
// Turning off the stack protector for this file significantly improves
// the performance of the syscall dispatching and interrupt handling.
#pragma GCC optimize("no-stack-protector")
@@ -28,12 +30,11 @@
#include <rtl/sizedefs.h>
#include <sys/irq.h>
#include <sys/mpu.h>
+#include <util/flash.h>
#include <util/image.h>
#include "stm32u5xx_ll_cortex.h"
-#ifdef KERNEL_MODE
-
// region type
#define MPUX_TYPE_FLASH_CODE 0
#define MPUX_TYPE_SRAM 1
@@ -127,7 +128,7 @@ static void mpu_set_attributes(void) {
MPU->MAIR0 |= 0x44 << 24;
}
-#define STORAGE_SIZE NORCOW_SECTOR_SIZE* STORAGE_AREAS_COUNT
+#define STORAGE_SIZE (NORCOW_SECTOR_SIZE * NORCOW_SECTOR_COUNT)
_Static_assert(NORCOW_SECTOR_SIZE == STORAGE_1_MAXSIZE, "norcow misconfigured");
_Static_assert(NORCOW_SECTOR_SIZE == STORAGE_2_MAXSIZE, "norcow misconfigured");
diff --git a/core/embed/sys/startup/stm32/bootutils.c b/core/embed/sys/startup/stm32/bootutils.c
index c540d27d..fd53daee 100644
--- a/core/embed/sys/startup/stm32/bootutils.c
+++ b/core/embed/sys/startup/stm32/bootutils.c
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef KERNEL_MODE
+
#include <trezor_bsp.h>
#include <trezor_model.h>
#include <trezor_rtl.h>
@@ -237,8 +239,6 @@ __attribute__((noreturn)) void reboot_or_halt_after_rsod(void) {
#endif // SECURE_MODE
-#ifdef KERNEL_MODE
-
static void jump_to_next_stage_phase_2(uint32_t arg1, uint32_t arg2) {
// We are now running on a new stack. We cannot be sure about
// any variables in the .bss and .data sections, so we must
diff --git a/core/embed/sys/trustzone/stm32u5/trustzone.c b/core/embed/sys/trustzone/stm32u5/trustzone.c
index 57d6cc9c..1a6bff28 100644
--- a/core/embed/sys/trustzone/stm32u5/trustzone.c
+++ b/core/embed/sys/trustzone/stm32u5/trustzone.c
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef KERNEL_MODE
+
#include <trezor_bsp.h>
#include <trezor_model.h>
#include <trezor_rtl.h>
@@ -24,6 +26,7 @@
#include <rtl/sizedefs.h>
#include <sys/irq.h>
#include <sys/trustzone.h>
+#include <util/flash.h>
#include <util/image.h>
#if defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
@@ -610,3 +613,5 @@ void tz_init(void) {
tz_enable_illegal_access_interrupt();
}
#endif // SECMON
+
+#endif // KERNEL_MODE
diff --git a/core/embed/upymod/modtrezorconfig/norcow_config.h b/core/embed/upymod/modtrezorconfig/norcow_config.h
deleted file mode 100644
index 1b5775ef..00000000
--- a/core/embed/upymod/modtrezorconfig/norcow_config.h
+++ /dev/null
@@ -1,36 +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/>.
- */
-
-#ifndef __NORCOW_CONFIG_H__
-#define __NORCOW_CONFIG_H__
-
-#include <trezor_model.h>
-#include <trezor_types.h>
-
-#include <util/flash.h>
-
-#define NORCOW_HEADER_LEN 0
-#define NORCOW_SECTOR_COUNT 2
-
-/*
- * Current storage version.
- */
-#define NORCOW_VERSION ((uint32_t)0x00000006)
-
-#endif
diff --git a/core/embed/util/flash/flash_utils.c b/core/embed/util/flash/flash_utils.c
index c518589f..67952f95 100644
--- a/core/embed/util/flash/flash_utils.c
+++ b/core/embed/util/flash/flash_utils.c
@@ -21,8 +21,8 @@
#include <trezor_rtl.h>
#include <sys/mpu.h>
+#include <util/flash.h>
#include <util/flash_utils.h>
-#include "flash_area.h"
typedef struct {
const flash_area_t* area;
diff --git a/core/embed/util/flash/inc/flash.h b/core/embed/util/flash/inc/flash.h
deleted file mode 100644
index 542e18af..00000000
--- a/core/embed/util/flash/inc/flash.h
+++ /dev/null
@@ -1,25 +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/>.
- */
-
-// This header is included in storage module
-//
-// Do not include this header or add dependencies to it unless required by
-// storage.
-
-#include "util/flash.h"
diff --git a/core/embed/util/flash/inc/norcow_config.h b/core/embed/util/flash/inc/norcow_config.h
new file mode 100644
index 00000000..36dc6ad3
--- /dev/null
+++ b/core/embed/util/flash/inc/norcow_config.h
@@ -0,0 +1,39 @@
+/*
+ * 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/>.
+ */
+
+#ifndef __NORCOW_CONFIG_H__
+#define __NORCOW_CONFIG_H__
+
+#include <trezor_model.h>
+#include <trezor_types.h>
+
+#include <util/flash.h>
+
+#define NORCOW_HEADER_LEN 0
+#define NORCOW_SECTOR_COUNT 2
+
+#define STORAGE_AREAS_COUNT NORCOW_SECTOR_COUNT
+extern const flash_area_t STORAGE_AREAS[STORAGE_AREAS_COUNT];
+
+/*
+ * Current storage version.
+ */
+#define NORCOW_VERSION ((uint32_t)0x00000006)
+
+#endif
diff --git a/core/embed/util/flash/inc/util/flash.h b/core/embed/util/flash/inc/util/flash.h
index 0aeafae0..43d22f18 100644
--- a/core/embed/util/flash/inc/util/flash.h
+++ b/core/embed/util/flash/inc/util/flash.h
@@ -17,13 +17,38 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef TREZORHAL_FLASH_H
-#define TREZORHAL_FLASH_H
+#pragma once
+
+#ifdef KERNEL_MODE
#include <trezor_types.h>
-#include "flash_ll.h"
+#include <trezor-storage/flash_area.h>
+#include <trezor-storage/flash_ll.h>
+
+#include "../norcow_config.h"
void flash_init(void);
-#endif // TREZORHAL_FLASH_H
+extern const flash_area_t BOARDLOADER_AREA;
+extern const flash_area_t SECRET_AREA;
+extern const flash_area_t BHK_AREA;
+extern const flash_area_t ASSETS_AREA;
+extern const flash_area_t BOOTLOADER_AREA;
+extern const flash_area_t UNUSED_AREA;
+
+#ifdef SECMON
+extern flash_area_t FIRMWARE_AREA;
+#else
+extern const flash_area_t FIRMWARE_AREA;
+#endif
+
+#ifdef USE_BOOT_UCB
+extern const flash_area_t BOOTUCB_AREA;
+extern const flash_area_t BOOTUPDATE_AREA;
+#ifdef BOARDLOADER
+extern const flash_area_t NONBOARDLOADER_AREA;
+#endif
+#endif // USE_BOOT_UCB
+
+#endif // KERNEL_MODE
diff --git a/core/embed/util/flash/inc/util/flash_layout.h b/core/embed/util/flash/inc/util/flash_layout.h
deleted file mode 100644
index 489fe596..00000000
--- a/core/embed/util/flash/inc/util/flash_layout.h
+++ /dev/null
@@ -1,49 +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/>.
- */
-
-#ifndef TREZORHAL_LAYOUT_H_
-#define TREZORHAL_LAYOUT_H_
-
-#include "flash_area.h"
-
-#define STORAGE_AREAS_COUNT (2)
-
-extern const flash_area_t STORAGE_AREAS[STORAGE_AREAS_COUNT];
-extern const flash_area_t BOARDLOADER_AREA;
-extern const flash_area_t SECRET_AREA;
-extern const flash_area_t BHK_AREA;
-extern const flash_area_t ASSETS_AREA;
-extern const flash_area_t BOOTLOADER_AREA;
-extern const flash_area_t UNUSED_AREA;
-
-#ifdef SECMON
-extern flash_area_t FIRMWARE_AREA;
-#else
-extern const flash_area_t FIRMWARE_AREA;
-#endif
-
-#ifdef USE_BOOT_UCB
-extern const flash_area_t BOOTUCB_AREA;
-extern const flash_area_t BOOTUPDATE_AREA;
-#ifdef BOARDLOADER
-extern const flash_area_t NONBOARDLOADER_AREA;
-#endif
-#endif // USE_BOOT_UCB
-
-#endif // TREZORHAL_LAYOUT_H_
diff --git a/core/embed/util/flash/stm32f4/flash_layout.c b/core/embed/util/flash/stm32f4/flash_layout.c
index ac2561b4..ee2d84aa 100644
--- a/core/embed/util/flash/stm32f4/flash_layout.c
+++ b/core/embed/util/flash/stm32f4/flash_layout.c
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef KERNEL_MODE
+
#include <trezor_bsp.h>
#include <trezor_model.h>
@@ -50,3 +52,5 @@ DEFINE_EMPTY_AREA(SECRET_AREA);
DEFINE_SINGLE_AREA(ASSETS_AREA, ASSETS, ACCESS_DEFAULT);
DEFINE_SPLIT2_AREA(UNUSED_AREA, UNUSED_1, ACCESS_DEFAULT, UNUSED_2,
ACCESS_DEFAULT);
+
+#endif // KERNEL_MODE
diff --git a/core/embed/util/flash/stm32u5/flash_layout.c b/core/embed/util/flash/stm32u5/flash_layout.c
index 11d6444e..cb711a0d 100644
--- a/core/embed/util/flash/stm32u5/flash_layout.c
+++ b/core/embed/util/flash/stm32u5/flash_layout.c
@@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef KERNEL_MODE
+
#include <trezor_bsp.h>
#include <trezor_model.h>
@@ -73,3 +75,5 @@ DEFINE_SINGLE_AREA(BOOTUPDATE_AREA, BOOTUPDATE, ACCESS_DEFAULT);
DEFINE_SINGLE_AREA(NONBOARDLOADER_AREA, NONBOARDLOADER, ACCESS_DEFAULT);
#endif
#endif
+
+#endif // KERNEL_MODE
diff --git a/core/embed/util/fwutils/fwutils.c b/core/embed/util/fwutils/fwutils.c
index 9282155c..15801cad 100644
--- a/core/embed/util/fwutils/fwutils.c
+++ b/core/embed/util/fwutils/fwutils.c
@@ -29,7 +29,6 @@
#include <util/image.h>
#include "blake2s.h"
-#include "flash_area.h"
#define FW_HASHING_CHUNK_SIZE 1024
diff --git a/core/embed/util/image/boot_image.c b/core/embed/util/image/boot_image.c
index 44dcceb9..bcfb7e30 100644
--- a/core/embed/util/image/boot_image.c
+++ b/core/embed/util/image/boot_image.c
@@ -31,11 +31,12 @@
#include "blake2s.h"
#include "memzero.h"
-#include "uzlib.h"
#ifdef USE_BOOT_UCB
#include <util/boot_header.h>
#include <util/boot_ucb.h>
+#else
+#include "uzlib.h"
#endif
#ifndef USE_BOOT_UCB
diff --git a/core/embed/util/image/image.c b/core/embed/util/image/image.c
index 615f75ca..08ebde17 100644
--- a/core/embed/util/image/image.c
+++ b/core/embed/util/image/image.c
@@ -233,6 +233,7 @@ secbool check_secmon_header_sig(const secmon_header_t *const hdr) {
*(const ed25519_signature *)hdr->sig));
}
+#ifdef SECURE_MODE
secbool check_secmon_contents(const secmon_header_t *const hdr,
size_t code_offset, const flash_area_t *area) {
if (0 == area) {
@@ -252,7 +253,9 @@ secbool check_secmon_contents(const secmon_header_t *const hdr,
return sectrue;
}
-#endif
+#endif // SECURE_MODE
+
+#endif // USE_SECMON_VERIFICATION
secbool __wur read_vendor_header(const uint8_t *const data,
vendor_header *const vhdr) {
@@ -364,6 +367,7 @@ secbool check_single_hash(const uint8_t *const hash, const uint8_t *const data,
return sectrue * (0 == memcmp(s_c, hash, IMAGE_HASH_DIGEST_LENGTH));
}
+#ifdef KERNEL_MODE
secbool check_image_contents(const image_header *const hdr, uint32_t firstskip,
const flash_area_t *area) {
if (0 == area) {
@@ -450,6 +454,7 @@ secbool check_image_contents(const image_header *const hdr, uint32_t firstskip,
return sectrue;
}
+#endif // KERNEL_MODE
secbool check_firmware_header(const uint8_t *header, size_t header_size,
firmware_header_info_t *info) {
diff --git a/core/embed/util/image/inc/util/image.h b/core/embed/util/image/inc/util/image.h
index 5e10a03a..7e242f31 100644
--- a/core/embed/util/image/inc/util/image.h
+++ b/core/embed/util/image/inc/util/image.h
@@ -180,9 +180,11 @@ void vendor_header_hash(const vendor_header *const vhdr, uint8_t *hash);
secbool __wur check_single_hash(const uint8_t *const hash,
const uint8_t *const data, int len);
+#ifdef KERNEL_MODE
secbool __wur check_image_contents(const image_header *const hdr,
uint32_t firstskip,
const flash_area_t *area);
+#endif
void get_image_fingerprint(const image_header *const hdr, uint8_t *const out);
@@ -199,7 +201,9 @@ secbool __wur check_secmon_model(const secmon_header_t *const hdr);
secbool __wur check_secmon_header_sig(const secmon_header_t *const hdr);
+#ifdef SECURE_MODE
secbool __wur check_secmon_contents(const secmon_header_t *const hdr,
size_t code_offset,
const flash_area_t *area);
#endif
+#endif
diff --git a/core/embed/util/translations/translations.c b/core/embed/util/translations/translations.c
index f2724054..4fcac4cb 100644
--- a/core/embed/util/translations/translations.c
+++ b/core/embed/util/translations/translations.c
@@ -1,3 +1,24 @@
+/*
+ * 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 KERNEL_MODE
+
#include <trezor_model.h>
#include <trezor_rtl.h>
@@ -5,8 +26,6 @@
#include <util/flash.h>
#include <util/translations.h>
-#ifdef KERNEL_MODE
-
bool translations_write(const uint8_t* data, uint32_t offset, uint32_t len) {
uint32_t size = translations_area_bytesize();
if (offset > size || size - offset < len) {
diff --git a/core/site_scons/models/__init__.py b/core/site_scons/models/__init__.py
index 5f4ec560..bbb56bd4 100644
--- a/core/site_scons/models/__init__.py
+++ b/core/site_scons/models/__init__.py
@@ -18,10 +18,50 @@ def configure_board(
paths: list[str],
) -> list[str]:
imported_module = importlib.import_module(f"models.{model}")
- return imported_module.configure_board(
+
+ features_available = imported_module.configure_board(
revision, features_wanted, env, defines, sources, paths
)
+ _configure_common_modules(
+ env, features_available, features_wanted, defines, sources, paths
+ )
+
+ return features_available
+
+
+def _configure_common_modules(
+ env: dict,
+ features_available: list[str],
+ features_wanted: list[str],
+ defines: list[str | tuple[str, str]],
+ sources: list[str],
+ paths: list[str],
+) -> list[str]:
+
+ if "kernel_mode" in features_wanted:
+ defines += [("KERNEL_MODE", "1")]
+ paths += ["vendor"]
+ sources += ["vendor/trezor-storage/flash_area.c"]
+
+ if "secure_mode" in features_wanted:
+ defines += [("SECURE_MODE", "1")]
+
+ if "storage" in features_wanted:
+ paths += ["embed/sec/storage/inc"]
+ paths += ["vendor"]
+ defines += [("USE_STORAGE", "1")]
+
+ if "secure_mode" in features_wanted:
+ sources += [
+ "embed/sec/storage/storage_setup.c",
+ "vendor/trezor-storage/norcow.c",
+ "vendor/trezor-storage/storage.c",
+ "vendor/trezor-storage/storage_utils.c",
+ ]
+
+ features_available.append("storage")
+
def has_emulator(model: str) -> bool:
imported_module = importlib.import_module(f"models.{model}")
diff --git a/storage/flash_area.h b/storage/flash_area.h
index 2f0b0128..a0b2ee1f 100644
--- a/storage/flash_area.h
+++ b/storage/flash_area.h
@@ -23,7 +23,7 @@
#include <stdint.h>
#include "secbool.h"
-#include "flash.h"
+#include "flash_ll.h"
/**
* Flash driver interface is designed to abstract away differences between
diff --git a/storage/storage.c b/storage/storage.c
index 68e11e19..b9e14a86 100644
--- a/storage/storage.c
+++ b/storage/storage.c
@@ -173,7 +173,6 @@ static secbool storage_set_encrypted(const uint16_t key, const void *val,
static secbool storage_get_encrypted(const uint16_t key, void *val_dest,
const uint16_t max_len, uint16_t *len);
-#include "flash.h"
#ifdef FLASH_BIT_ACCESS
#include "pinlogs_bitwise.h"
#else
Why this scored 17/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.