Skip to content

Commit

Permalink
fixup! chore(core, legacy, storage): refactor flash drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
cepetr committed Nov 15, 2023
1 parent b57209a commit a74a954
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions core/embed/trezorhal/stm32u5/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,11 @@
#define FLASH_STATUS_ALL_FLAGS \
(FLASH_NSSR_PGSERR | FLASH_NSSR_PGAERR | FLASH_NSSR_WRPERR | FLASH_NSSR_EOP)

static bool g_otp_cache_valid = false;

static bool flash_sector_is_secure(uint32_t sector) {
static uint16_t bank1_secure_start = 0;
static uint16_t bank1_secure_end = 0;
static uint16_t bank2_secure_start = 0;
static uint16_t bank2_secure_end = 0;

if (!g_otp_cache_valid) {
// reload OTP values
bank1_secure_start = (FLASH->SECWM1R1 & FLASH_SECWM1R1_SECWM1_PSTRT) >>
FLASH_SECWM1R1_SECWM1_PSTRT_Pos;
bank1_secure_end = (FLASH->SECWM1R1 & FLASH_SECWM1R1_SECWM1_PEND) >>
FLASH_SECWM1R1_SECWM1_PEND_Pos;

bank2_secure_start =
256 + ((FLASH->SECWM2R1 & FLASH_SECWM1R1_SECWM1_PSTRT) >>
FLASH_SECWM1R1_SECWM1_PSTRT_Pos);
bank2_secure_end = 256 + ((FLASH->SECWM2R1 & FLASH_SECWM1R1_SECWM1_PEND) >>
FLASH_SECWM1R1_SECWM1_PEND_Pos);
}

return (sector >= bank1_secure_start && sector <= bank1_secure_end) ||
(sector >= bank2_secure_start && sector <= bank2_secure_end);
// We always return true since the entire flash memory is currently secure -
// partially through option bytes and partially through FLASH controller
// settings
return true;
}

const void *flash_get_address(uint16_t sector, uint32_t offset, uint32_t size) {
Expand Down

0 comments on commit a74a954

Please sign in to comment.