From cd06b5f60058c0146b36b24f39e834d23363fce2 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Tue, 5 Nov 2024 08:27:34 +0100 Subject: [PATCH] chore(core): add storage flash area size checks [no changelog] --- core/embed/trezorhal/stm32f4/mpu.c | 5 +++++ core/embed/trezorhal/stm32u5/mpu.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/core/embed/trezorhal/stm32f4/mpu.c b/core/embed/trezorhal/stm32f4/mpu.c index ddcd75608..073e1553d 100644 --- a/core/embed/trezorhal/stm32f4/mpu.c +++ b/core/embed/trezorhal/stm32f4/mpu.c @@ -23,6 +23,7 @@ #include "irq.h" #include "mpu.h" +#include "sizedefs.h" #include "stm32f4xx_ll_cortex.h" @@ -74,6 +75,10 @@ mpu_driver_t g_mpu_driver = { #define KERNEL_CCMRAM_FB_START (KERNEL_CCMRAM_START - KERNEL_FRAMEBUFFER_SIZE) +_Static_assert(NORCOW_SECTOR_SIZE == STORAGE_1_MAXSIZE, "norcow misconfigured"); +_Static_assert(NORCOW_SECTOR_SIZE == STORAGE_2_MAXSIZE, "norcow misconfigured"); +_Static_assert(NORCOW_SECTOR_SIZE == SIZE_64K, "norcow misconfigured"); + static void mpu_init_fixed_regions(void) { // Regions #0 to #4 are fixed for all targets diff --git a/core/embed/trezorhal/stm32u5/mpu.c b/core/embed/trezorhal/stm32u5/mpu.c index ebfe90792..6e77a4ebd 100644 --- a/core/embed/trezorhal/stm32u5/mpu.c +++ b/core/embed/trezorhal/stm32u5/mpu.c @@ -124,6 +124,8 @@ static void mpu_set_attributes(void) { } #define STORAGE_SIZE NORCOW_SECTOR_SIZE* STORAGE_AREAS_COUNT +_Static_assert(NORCOW_SECTOR_SIZE == STORAGE_1_MAXSIZE, "norcow misconfigured"); +_Static_assert(NORCOW_SECTOR_SIZE == STORAGE_2_MAXSIZE, "norcow misconfigured"); #if defined STM32U5A9xx #define SRAM_SIZE (SRAM1_SIZE + SRAM2_SIZE + SRAM3_SIZE + SRAM5_SIZE)