refactor(core): move emu profile to sys layer
What changed, and why it matters
This commit is a straightforward code reorganization: it moves the emulator's profile-handling code from one directory to another and updates the build files and include paths accordingly. There is no change to what the code does, no bug fix, and no security-related change.
No security action needed; treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change relocates the Unix emulator profile implementation from core/embed/projects/unix/profile.{c,h} to core/embed/sys/bsp/{inc,unix}/profile.{c,h}. It updates SCons build scripts to remove the old source file references and add the new one via unix_common_files(). It also updates consumers (display_driver.c, sdcard.c, usb.c, flash.c) to include <sys/profile.h> instead of "profile.h". The implementation logic is identical.
Changed components
core/embed/sys/bsp/unix/profile.ccore/embed/sys/bsp/inc/sys/profile.hcore/site_scons/models/unix_common.pycore/SConscript.unixcore/SConscript.bootloader_emucore/SConscript.prodtest_emucore/embed/io/display/unix/display_driver.ccore/embed/io/sdcard/unix/sdcard.ccore/embed/io/usb/unix/usb.ccore/embed/sys/flash/unix/flash.cInspect captured patch +119 / −130
diff --git a/core/SConscript.bootloader_emu b/core/SConscript.bootloader_emu
index 244dd0ce..96672085 100644
--- a/core/SConscript.bootloader_emu
+++ b/core/SConscript.bootloader_emu
@@ -150,9 +150,7 @@ if DEBUGLINK:
'embed/projects/bootloader/protob/pb/messages-debug.pb.c',
]
-SOURCE_UNIX = [
- 'embed/projects/unix/profile.c',
-]
+SOURCE_UNIX = []
ui.init_ui(TREZOR_MODEL, "bootloader", RUST_UI_FEATURES)
diff --git a/core/SConscript.prodtest_emu b/core/SConscript.prodtest_emu
index ada4f4f5..a494efa9 100644
--- a/core/SConscript.prodtest_emu
+++ b/core/SConscript.prodtest_emu
@@ -190,10 +190,6 @@ SOURCE_PRODTEST = [
'embed/projects/prodtest/emulator.c',
]
-SOURCE_HAL += [
- 'embed/projects/unix/profile.c',
-]
-
env.Replace(
CAT='cat',
CP='cp',
diff --git a/core/SConscript.unix b/core/SConscript.unix
index cb10f2bf..d23406d3 100644
--- a/core/SConscript.unix
+++ b/core/SConscript.unix
@@ -432,7 +432,6 @@ SOURCE_MICROPYTHON = [
SOURCE_UNIX = [
'embed/projects/unix/main_main.c',
'embed/projects/unix/main.c',
- 'embed/projects/unix/profile.c',
'embed/projects/unix/rust_c_setup.c',
'vendor/micropython/ports/unix/alloc.c',
'vendor/micropython/ports/unix/gccollect.c',
diff --git a/core/embed/io/display/unix/display_driver.c b/core/embed/io/display/unix/display_driver.c
index e1c72a58..e599282d 100644
--- a/core/embed/io/display/unix/display_driver.c
+++ b/core/embed/io/display/unix/display_driver.c
@@ -28,6 +28,7 @@
#include <io/display.h>
#include <io/unix/sdl_display.h>
#include <sys/logging.h>
+#include <sys/profile.h>
#include <sys/systask.h>
#include <SDL3/SDL.h>
@@ -36,8 +37,6 @@
#include <SDL3_image/SDL_image.h>
#include <stdlib.h>
-#include "profile.h"
-
#ifdef USE_POWER_MANAGER
#include "suspend_overlay.h"
#endif
diff --git a/core/embed/io/sdcard/unix/sdcard.c b/core/embed/io/sdcard/unix/sdcard.c
index f120fc7b..32e43e29 100644
--- a/core/embed/io/sdcard/unix/sdcard.c
+++ b/core/embed/io/sdcard/unix/sdcard.c
@@ -27,7 +27,7 @@
#include <unistd.h>
#include <io/sdcard.h>
-#include "profile.h"
+#include <sys/profile.h>
#ifndef SDCARD_FILE
#define SDCARD_FILE profile_sdcard_path()
diff --git a/core/embed/io/usb/unix/usb.c b/core/embed/io/usb/unix/usb.c
index 56637617..e98844fc 100644
--- a/core/embed/io/usb/unix/usb.c
+++ b/core/embed/io/usb/unix/usb.c
@@ -33,8 +33,7 @@
#include <io/usb_hid.h>
#include <io/usb_vcp.h>
#include <io/usb_webusb.h>
-
-#include "profile.h"
+#include <sys/profile.h>
#include "memzero.h"
diff --git a/core/embed/projects/unix/profile.c b/core/embed/projects/unix/profile.c
deleted file mode 100644
index 2dc34e54..00000000
--- a/core/embed/projects/unix/profile.c
+++ /dev/null
@@ -1,78 +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 _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#include <trezor_rtl.h>
-
-#include <stdlib.h>
-
-#include "profile.h"
-
-#define SVAR(varname) \
- static char *varname; \
- if (varname) { \
- return varname; \
- }
-
-#define GETENV(varname, envname, fallback) \
- varname = getenv(envname); \
- if (!varname) { \
- varname = fallback; \
- }
-
-#define FILE_PATH(varname, filename) \
- if (asprintf(&varname, "%s/" filename, profile_dir()) < 0) { \
- varname = NULL; \
- } \
- if (!varname) { \
- varname = PROFILE_DIR_DEFAULT filename; \
- }
-
-const char *profile_name(void) {
- SVAR(_profile_name);
- GETENV(_profile_name, "TREZOR_PROFILE_NAME", PROFILE_NAME_DEFAULT);
- return _profile_name;
-}
-
-const char *profile_dir(void) {
- SVAR(_profile_dir);
- GETENV(_profile_dir, "TREZOR_PROFILE_DIR", PROFILE_DIR_DEFAULT);
- return _profile_dir;
-}
-
-const char *profile_flash_path(void) {
- SVAR(_flash_path);
- FILE_PATH(_flash_path, "/trezor.flash");
- return _flash_path;
-}
-
-const char *profile_sdcard_path(void) {
- SVAR(_sdcard_path);
- FILE_PATH(_sdcard_path, "/trezor.sdcard");
- return _sdcard_path;
-}
-
-const char *profile_usb_disconnect_path(void) {
- SVAR(_disconnect_path);
- FILE_PATH(_disconnect_path, "/trezor.usb_data_disconnected");
- return _disconnect_path;
-}
diff --git a/core/embed/projects/unix/profile.h b/core/embed/projects/unix/profile.h
deleted file mode 100644
index 7df834cc..00000000
--- a/core/embed/projects/unix/profile.h
+++ /dev/null
@@ -1,38 +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 __TREZOR_PROFILE_H__
-#define __TREZOR_PROFILE_H__
-
-// Environment variables meaning:
-// TREZOR_PROFILE_NAME sets the title of the emulator window.
-// TREZOR_PROFILE_DIR contains flash files.
-//
-// If those are not set int the environment these default values are used.
-
-#define PROFILE_DIR_DEFAULT "/var/tmp"
-#define PROFILE_NAME_DEFAULT "/var/tmp"
-
-const char *profile_name(void);
-const char *profile_dir(void);
-const char *profile_flash_path(void);
-const char *profile_sdcard_path(void);
-const char *profile_usb_disconnect_path(void);
-
-#endif // __TREZOR_PROFILE_H__
diff --git a/core/embed/sys/bsp/inc/sys/profile.h b/core/embed/sys/bsp/inc/sys/profile.h
new file mode 100644
index 00000000..64caabbf
--- /dev/null
+++ b/core/embed/sys/bsp/inc/sys/profile.h
@@ -0,0 +1,35 @@
+/*
+ * 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
+
+// Environment variables meaning:
+// TREZOR_PROFILE_NAME sets the title of the emulator window.
+// TREZOR_PROFILE_DIR contains flash files.
+//
+// If those are not set int the environment these default values are used.
+
+#define PROFILE_DIR_DEFAULT "/var/tmp"
+#define PROFILE_NAME_DEFAULT "/var/tmp"
+
+const char *profile_name(void);
+const char *profile_dir(void);
+const char *profile_flash_path(void);
+const char *profile_sdcard_path(void);
+const char *profile_usb_disconnect_path(void);
diff --git a/core/embed/sys/bsp/unix/profile.c b/core/embed/sys/bsp/unix/profile.c
new file mode 100644
index 00000000..3952e162
--- /dev/null
+++ b/core/embed/sys/bsp/unix/profile.c
@@ -0,0 +1,78 @@
+/*
+ * 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 _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <trezor_rtl.h>
+
+#include <sys/profile.h>
+
+#include <stdlib.h>
+
+#define SVAR(varname) \
+ static char *varname; \
+ if (varname) { \
+ return varname; \
+ }
+
+#define GETENV(varname, envname, fallback) \
+ varname = getenv(envname); \
+ if (!varname) { \
+ varname = fallback; \
+ }
+
+#define FILE_PATH(varname, filename) \
+ if (asprintf(&varname, "%s/" filename, profile_dir()) < 0) { \
+ varname = NULL; \
+ } \
+ if (!varname) { \
+ varname = PROFILE_DIR_DEFAULT filename; \
+ }
+
+const char *profile_name(void) {
+ SVAR(_profile_name);
+ GETENV(_profile_name, "TREZOR_PROFILE_NAME", PROFILE_NAME_DEFAULT);
+ return _profile_name;
+}
+
+const char *profile_dir(void) {
+ SVAR(_profile_dir);
+ GETENV(_profile_dir, "TREZOR_PROFILE_DIR", PROFILE_DIR_DEFAULT);
+ return _profile_dir;
+}
+
+const char *profile_flash_path(void) {
+ SVAR(_flash_path);
+ FILE_PATH(_flash_path, "/trezor.flash");
+ return _flash_path;
+}
+
+const char *profile_sdcard_path(void) {
+ SVAR(_sdcard_path);
+ FILE_PATH(_sdcard_path, "/trezor.sdcard");
+ return _sdcard_path;
+}
+
+const char *profile_usb_disconnect_path(void) {
+ SVAR(_disconnect_path);
+ FILE_PATH(_disconnect_path, "/trezor.usb_data_disconnected");
+ return _disconnect_path;
+}
diff --git a/core/embed/sys/flash/unix/flash.c b/core/embed/sys/flash/unix/flash.c
index ef8925b5..f761e755 100644
--- a/core/embed/sys/flash/unix/flash.c
+++ b/core/embed/sys/flash/unix/flash.c
@@ -28,7 +28,7 @@
#include <unistd.h>
#include <sys/flash.h>
-#include "profile.h"
+#include <sys/profile.h>
#ifndef FLASH_FILE
#define FLASH_FILE profile_flash_path()
diff --git a/core/site_scons/models/unix_common.py b/core/site_scons/models/unix_common.py
index 799fe59e..41c56f59 100644
--- a/core/site_scons/models/unix_common.py
+++ b/core/site_scons/models/unix_common.py
@@ -47,6 +47,7 @@ def unix_common_files(env, features_wanted, defines, sources, paths):
"embed/sec/time_estimate/unix/time_estimate.c",
"embed/sec/trustzone/unix/tz_init.c",
"embed/sec/unit_properties/unix/unit_properties.c",
+ "embed/sys/bsp/unix/profile.c",
"embed/sys/cpuid/unix/cpuid.c",
"embed/sys/flash/unix/flash.c",
"embed/sys/flash/unix/flash_otp.c",
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.