refactor(core): move translatations module to io layer
What changed, and why it matters
This commit is a pure code reorganization: it moves the 'translations' module from one directory location to another without changing what the code does. The functions that read, write, and erase translation data in device flash remain identical. There is no visible security bug or fix in the change.
No security action required. Treat as ordinary refactoring; review can focus on whether include-path and build-path updates are complete.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors the translations subsystem from embed/util/translations/ to embed/io/translations/. It updates all SConscript build paths, Rust bindgen include paths, and C #include directives from <util/translations.h> to <io/translations.h>. The header and implementation file contents are byte-for-byte the same as before, including the same bounds checks, MPU reconfiguration, flash unlock/write/lock sequence, and erase behavior. No functional logic was modified.
Changed components
core/embed/io/translationscore/embed/util/translationscore/SConscript.* build scriptscore/embed/rust build.rs / trezorhal.hcore/embed/sys/syscall/stm32Inspect captured patch +118 / −118
diff --git a/core/SConscript.bootloader b/core/SConscript.bootloader
index 9b09aa68..87291349 100644
--- a/core/SConscript.bootloader
+++ b/core/SConscript.bootloader
@@ -206,10 +206,10 @@ ALLPATHS = [
'embed/projects/bootloader/protob',
'embed/rtl/inc',
'embed/models',
- 'embed/sys/bsp/inc',
'embed/gfx/inc',
+ 'embed/io/translations/inc',
'embed/sec/image/inc',
- 'embed/util/translations/inc',
+ 'embed/sys/bsp/inc',
'embed/util/rsod/inc',
'embed/upymod/modtrezorui',
'vendor/nanopb',
diff --git a/core/SConscript.bootloader_emu b/core/SConscript.bootloader_emu
index 9186e5d6..21c610bc 100644
--- a/core/SConscript.bootloader_emu
+++ b/core/SConscript.bootloader_emu
@@ -181,9 +181,9 @@ ALLPATHS = ['embed/rust',
'embed/projects/unix',
'embed/upymod/modtrezorui',
'embed/gfx/inc',
+ 'embed/io/translations/inc',
'embed/sec/image/inc',
'embed/util/rsod/inc',
- 'embed/util/translations/inc',
'vendor/nanopb',
] + CPPPATH_MOD + PATH_HAL
diff --git a/core/SConscript.firmware b/core/SConscript.firmware
index 5e03be1a..3bccaac5 100644
--- a/core/SConscript.firmware
+++ b/core/SConscript.firmware
@@ -260,7 +260,7 @@ SOURCE_MOD += [
'embed/gfx/gfx_draw.c',
'embed/gfx/terminal.c',
'embed/io/display/display_utils.c',
- 'embed/util/translations/translations.c',
+ 'embed/io/translations/translations.c',
'embed/util/rsod/rsod.c',
'embed/rtl/error_handling.c',
'embed/rtl/scm_revision.c',
@@ -489,10 +489,10 @@ ALLPATHS = [
'embed/rtl/inc',
'embed/models',
'embed/gfx/inc',
+ 'embed/io/translations/inc',
'embed/sys/bsp/inc',
'embed/sec/image/inc',
'embed/util/rsod/inc',
- 'embed/util/translations/inc',
'embed/upymod/modtrezorui',
'vendor/micropython',
] + CPPPATH_MOD + PATH_HAL
diff --git a/core/SConscript.kernel b/core/SConscript.kernel
index 8e6d9de8..ab53bab7 100644
--- a/core/SConscript.kernel
+++ b/core/SConscript.kernel
@@ -217,7 +217,7 @@ SOURCE_MOD += [
'embed/gfx/gfx_color.c',
'embed/gfx/gfx_draw.c',
'embed/gfx/terminal.c',
- 'embed/util/translations/translations.c',
+ 'embed/io/translations/translations.c',
'embed/util/rsod/rsod.c',
'embed/util/rsod/rsod_special.c',
'embed/rtl/error_handling.c',
@@ -314,10 +314,10 @@ ALLPATHS = [
'embed/rtl/inc',
'embed/models',
'embed/gfx/inc',
+ 'embed/io/translations/inc',
'embed/sec/image/inc',
'embed/sys/bsp/inc',
'embed/util/rsod/inc',
- 'embed/util/translations/inc',
] + CPPPATH_MOD + PATH_HAL
env.Replace(
diff --git a/core/SConscript.prodtest b/core/SConscript.prodtest
index 6c9cb527..2613f37b 100644
--- a/core/SConscript.prodtest
+++ b/core/SConscript.prodtest
@@ -255,11 +255,11 @@ ALLPATHS = [
'embed/rtl/inc',
'embed/models',
'embed/gfx/inc',
+ 'embed/io/translations/inc',
'embed/sys/bsp/inc',
'embed/sec/image/inc',
'embed/sec/storage/inc',
'embed/util/rsod/inc',
- 'embed/util/translations/inc',
'embed/upymod/modtrezorui',
]
diff --git a/core/SConscript.prodtest_emu b/core/SConscript.prodtest_emu
index 07aafede..288f1660 100644
--- a/core/SConscript.prodtest_emu
+++ b/core/SConscript.prodtest_emu
@@ -221,9 +221,9 @@ ALLPATHS = ['embed/rust',
'embed/models',
'embed/projects/unix',
'embed/gfx/inc',
+ 'embed/io/translations/inc',
'embed/sec/image/inc',
'embed/util/rsod/inc',
- 'embed/util/translations/inc',
] + CPPPATH_MOD + PATH_HAL
env.Replace(
diff --git a/core/SConscript.secmon b/core/SConscript.secmon
index 8f63cc81..bb5843d3 100644
--- a/core/SConscript.secmon
+++ b/core/SConscript.secmon
@@ -213,7 +213,7 @@ if 'boot_ucb' in FEATURES_AVAILABLE:
]
SOURCE_MOD += [
- 'embed/util/translations/translations.c',
+ 'embed/io/translations/translations.c',
'embed/util/rsod/rsod_special.c',
'embed/rtl/error_handling.c',
'embed/rtl/strutils.c',
@@ -308,10 +308,10 @@ ALLPATHS = [
'embed/rtl/inc',
'embed/models',
'embed/gfx/inc',
+ 'embed/io/translations/inc',
'embed/sec/image/inc',
'embed/sys/bsp/inc',
'embed/util/rsod/inc',
- 'embed/util/translations/inc',
] + CPPPATH_MOD + PATH_HAL
env.Replace(
diff --git a/core/SConscript.unix b/core/SConscript.unix
index 0f9730ef..3e5463b8 100644
--- a/core/SConscript.unix
+++ b/core/SConscript.unix
@@ -243,7 +243,7 @@ SOURCE_MOD += [
'embed/gfx/gfx_draw.c',
'embed/gfx/terminal.c',
'embed/io/display/display_utils.c',
- 'embed/util/translations/translations.c',
+ 'embed/io/translations/translations.c',
'embed/util/rsod/rsod.c',
'embed/util/rsod/rsod_special.c',
'embed/rtl/error_handling.c',
@@ -498,9 +498,9 @@ ALLPATHS=['.',
'embed/projects/unix',
'embed/upymod/modtrezorui',
'embed/gfx/inc',
+ 'embed/io/translations/inc',
'embed/sec/image/inc',
'embed/util/rsod/inc',
- 'embed/util/translations/inc',
'vendor/micropython',
'vendor/micropython/ports/unix',
'vendor/micropython/lib/mp-readline',
diff --git a/core/embed/io/translations/inc/io/translations.h b/core/embed/io/translations/inc/io/translations.h
new file mode 100644
index 00000000..6ea3c42d
--- /dev/null
+++ b/core/embed/io/translations/inc/io/translations.h
@@ -0,0 +1,33 @@
+/*
+ * 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 LIB_TRANSLATIONS_H
+#define LIB_TRANSLATIONS_H
+
+#include <trezor_types.h>
+
+bool translations_write(const uint8_t* data, uint32_t offset, uint32_t len);
+
+const uint8_t* translations_read(uint32_t* len, uint32_t offset);
+
+void translations_erase(void);
+
+uint32_t translations_area_bytesize(void);
+
+#endif // LIB_TRANSLATIONS_H
diff --git a/core/embed/io/translations/translations.c b/core/embed/io/translations/translations.c
new file mode 100644
index 00000000..0274422e
--- /dev/null
+++ b/core/embed/io/translations/translations.c
@@ -0,0 +1,67 @@
+/*
+ * 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>
+
+#include <io/translations.h>
+#include <sys/flash.h>
+#include <sys/mpu.h>
+
+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) {
+ return false;
+ }
+
+ mpu_mode_t mpu_mode = mpu_reconfig(MPU_MODE_ASSETS);
+
+ ensure(flash_unlock_write(), "translations_write unlock");
+ // todo consider alignment
+ ensure(flash_area_write_data_padded(&ASSETS_AREA, offset, data, len, 0xFF,
+ FLASH_ALIGN(len)),
+ "translations_write write");
+ ensure(flash_lock_write(), "translations_write lock");
+
+ mpu_restore(mpu_mode);
+
+ return true;
+}
+
+const uint8_t* translations_read(uint32_t* len, uint32_t offset) {
+ // TODO: _Static_assert was not happy with ASSETS_AREA.num_subareas == 1
+ // error: expression in static assertion is not constant
+ assert(ASSETS_AREA.num_subareas == 1);
+ *len = flash_area_get_size(&ASSETS_AREA) - offset;
+ return flash_area_get_address(&ASSETS_AREA, offset, 0);
+}
+
+void translations_erase(void) {
+ mpu_mode_t mpu_mode = mpu_reconfig(MPU_MODE_ASSETS);
+ ensure(flash_area_erase(&ASSETS_AREA, NULL), "translations erase");
+ mpu_restore(mpu_mode);
+}
+
+uint32_t translations_area_bytesize(void) {
+ return flash_area_get_size(&ASSETS_AREA);
+}
+
+#endif // KERNEL_MODE
diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs
index f0ce7dfb..1cdc5a20 100644
--- a/core/embed/rust/build.rs
+++ b/core/embed/rust/build.rs
@@ -45,6 +45,7 @@ const DEFAULT_BINDGEN_MACROS_COMMON: &[&str] = &[
"-I../io/touch/inc",
"-I../io/power_manager/inc",
"-I../io/rgb_led/inc",
+ "-I../io/translations/inc",
"-I../io/usb/inc",
"-I../sec/storage/inc",
"-I../sys/dbg/inc",
@@ -54,7 +55,6 @@ const DEFAULT_BINDGEN_MACROS_COMMON: &[&str] = &[
"-I../sys/suspend/inc",
"-I../sys/irq/inc",
"-I../sys/flash/inc",
- "-I../util/translations/inc",
"-I../models",
"-DTREZOR_EMULATOR",
"-DUSE_BUTTON",
diff --git a/core/embed/rust/trezorhal.h b/core/embed/rust/trezorhal.h
index a86eb92e..98eaefba 100644
--- a/core/embed/rust/trezorhal.h
+++ b/core/embed/rust/trezorhal.h
@@ -5,6 +5,7 @@
#include <gfx/gfx_bitblt.h>
#include <io/display.h>
#include <io/display_utils.h>
+#include <io/translations.h>
#include <io/usb.h>
#include <rtl/secbool.h>
#include <sys/flash.h>
@@ -12,7 +13,6 @@
#include <sys/logging.h>
#include <sys/sysevent.h>
#include <sys/systick.h>
-#include <util/translations.h>
#include "rust_types.h"
#ifdef USE_HW_JPEG_DECODER
diff --git a/core/embed/sys/syscall/stm32/syscall_dispatch.c b/core/embed/sys/syscall/stm32/syscall_dispatch.c
index ecfc5bb9..158321ed 100644
--- a/core/embed/sys/syscall/stm32/syscall_dispatch.c
+++ b/core/embed/sys/syscall/stm32/syscall_dispatch.c
@@ -26,6 +26,7 @@
#include <gfx/dma2d_bitblt.h>
#include <io/display.h>
#include <io/notify.h>
+#include <io/translations.h>
#include <io/usb.h>
#include <sec/fwutils.h>
#include <sec/rng_strong.h>
@@ -38,7 +39,6 @@
#include <sys/systask.h>
#include <sys/system.h>
#include <sys/systick.h>
-#include <util/translations.h>
#ifdef USE_BLE
#include <io/ble.h>
diff --git a/core/embed/sys/syscall/stm32/syscall_stubs.c b/core/embed/sys/syscall/stm32/syscall_stubs.c
index 03197ce1..c3610d3d 100644
--- a/core/embed/sys/syscall/stm32/syscall_stubs.c
+++ b/core/embed/sys/syscall/stm32/syscall_stubs.c
@@ -564,7 +564,7 @@ secbool storage_next_counter(const uint16_t key, uint32_t *count) {
// translations.h
// =============================================================================
-#include <util/translations.h>
+#include <io/translations.h>
bool translations_write(const uint8_t *data, uint32_t offset, uint32_t len) {
return (bool)syscall_invoke3((uint32_t)data, offset, len,
diff --git a/core/embed/sys/syscall/stm32/syscall_verifiers.h b/core/embed/sys/syscall/stm32/syscall_verifiers.h
index 783b0fa5..fdaaf4b6 100644
--- a/core/embed/sys/syscall/stm32/syscall_verifiers.h
+++ b/core/embed/sys/syscall/stm32/syscall_verifiers.h
@@ -186,7 +186,7 @@ void rng_fill_buffer__verified(void *buffer, size_t buffer_size);
bool rng_fill_buffer_strong__verified(void *buffer, size_t buffer_size);
// ---------------------------------------------------------------------
-#include <util/translations.h>
+#include <io/translations.h>
bool translations_write__verified(const uint8_t *data, uint32_t offset,
uint32_t len);
diff --git a/core/embed/util/translations/inc/util/translations.h b/core/embed/util/translations/inc/util/translations.h
deleted file mode 100644
index 6ea3c42d..00000000
--- a/core/embed/util/translations/inc/util/translations.h
+++ /dev/null
@@ -1,33 +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 LIB_TRANSLATIONS_H
-#define LIB_TRANSLATIONS_H
-
-#include <trezor_types.h>
-
-bool translations_write(const uint8_t* data, uint32_t offset, uint32_t len);
-
-const uint8_t* translations_read(uint32_t* len, uint32_t offset);
-
-void translations_erase(void);
-
-uint32_t translations_area_bytesize(void);
-
-#endif // LIB_TRANSLATIONS_H
diff --git a/core/embed/util/translations/translations.c b/core/embed/util/translations/translations.c
deleted file mode 100644
index 4bebf41c..00000000
--- a/core/embed/util/translations/translations.c
+++ /dev/null
@@ -1,67 +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 KERNEL_MODE
-
-#include <trezor_model.h>
-#include <trezor_rtl.h>
-
-#include <sys/flash.h>
-#include <sys/mpu.h>
-#include <util/translations.h>
-
-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) {
- return false;
- }
-
- mpu_mode_t mpu_mode = mpu_reconfig(MPU_MODE_ASSETS);
-
- ensure(flash_unlock_write(), "translations_write unlock");
- // todo consider alignment
- ensure(flash_area_write_data_padded(&ASSETS_AREA, offset, data, len, 0xFF,
- FLASH_ALIGN(len)),
- "translations_write write");
- ensure(flash_lock_write(), "translations_write lock");
-
- mpu_restore(mpu_mode);
-
- return true;
-}
-
-const uint8_t* translations_read(uint32_t* len, uint32_t offset) {
- // TODO: _Static_assert was not happy with ASSETS_AREA.num_subareas == 1
- // error: expression in static assertion is not constant
- assert(ASSETS_AREA.num_subareas == 1);
- *len = flash_area_get_size(&ASSETS_AREA) - offset;
- return flash_area_get_address(&ASSETS_AREA, offset, 0);
-}
-
-void translations_erase(void) {
- mpu_mode_t mpu_mode = mpu_reconfig(MPU_MODE_ASSETS);
- ensure(flash_area_erase(&ASSETS_AREA, NULL), "translations erase");
- mpu_restore(mpu_mode);
-}
-
-uint32_t translations_area_bytesize(void) {
- return flash_area_get_size(&ASSETS_AREA);
-}
-
-#endif // KERNEL_MODE
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.