refactor(core): separate norcow config from flash layout
What changed, and why it matters
This commit is a straightforward internal code cleanup. It moves two configuration constants between header files to remove a circular include dependency between the flash and storage modules. There is no user-facing change, no bug fix, and no security-sensitive behavior change.
No security action required. Review as normal code-quality refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors header organization in the Trezor Core firmware. Previously sys/flash.h included norcow_config.h, which in turn included sys/flash.h, creating a circular dependency. The change moves STORAGE_AREAS_COUNT and STORAGE_AREAS declarations into sys/flash.h (where other flash-area declarations live) and keeps norcow-specific parameters in sec/storage/inc/norcow_config.h. NORCOW_SECTOR_COUNT is now derived from STORAGE_AREAS_COUNT instead of being a separate hardcoded value. A single translation unit (projects/unix/main_main.c) adds a direct include for trezor_model.h because the previous indirect include chain no longer provides it. Legacy code and storage tests are explicitly noted as unaffected.
Changed components
core/embed/sys/flash/inc/sys/flash.hcore/embed/sec/storage/inc/norcow_config.hcore/embed/projects/unix/main_main.cInspect captured patch +14 / −5
### core/embed/projects/unix/main_main.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
+#include <trezor_model.h>
#include <trezor_rtl.h>
#include <io/display.h>
### core/embed/sec/storage/inc/norcow_config.h
@@ -17,6 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+// This header provides the norcow configuration required by the storage
+// module, which includes it by this exact name. It intentionally stays flat
+// rather than under `inc/sec/` for that reason.
+//
+// Do not include this header or add dependencies to it unless required by
+// storage.
+
#ifndef __NORCOW_CONFIG_H__
#define __NORCOW_CONFIG_H__
@@ -26,10 +33,9 @@
#include <sys/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];
+// Norcow uses all the storage areas provided by the flash layout
+#define NORCOW_SECTOR_COUNT STORAGE_AREAS_COUNT
/*
* Current storage version.
### core/embed/sys/flash/inc/sys/flash.h
@@ -26,8 +26,6 @@
#include <trezor-storage/flash_area.h>
#include <trezor-storage/flash_ll.h>
-#include "../norcow_config.h"
-
void flash_init(void);
void flash_deinit(void);
@@ -39,6 +37,10 @@ extern const flash_area_t ASSETS_AREA;
extern const flash_area_t BOOTLOADER_AREA;
extern const flash_area_t UNUSED_AREA;
+// Number of flash areas holding the storage
+#define STORAGE_AREAS_COUNT 2
+extern const flash_area_t STORAGE_AREAS[STORAGE_AREAS_COUNT];
+
#ifdef SECMON
extern flash_area_t FIRMWARE_AREA;
#elseWhy 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.