2018-02-26 13:06:10 +00:00
|
|
|
/*
|
2019-06-17 18:27:55 +00:00
|
|
|
* This file is part of the Trezor project, https://trezor.io/
|
2018-02-26 13:06:10 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2017-10-31 13:35:41 +00:00
|
|
|
#ifndef TREZORHAL_FLASH_H
|
|
|
|
#define TREZORHAL_FLASH_H
|
2017-03-07 14:52:19 +00:00
|
|
|
|
2017-06-20 17:53:24 +00:00
|
|
|
#include <stdint.h>
|
2018-11-14 14:12:19 +00:00
|
|
|
#include <stdlib.h>
|
2023-06-30 10:12:55 +00:00
|
|
|
#include "platform.h"
|
2017-10-26 21:51:39 +00:00
|
|
|
#include "secbool.h"
|
2017-06-20 17:53:24 +00:00
|
|
|
|
2023-06-30 10:12:55 +00:00
|
|
|
#define FLASH_OTP_NUM_BLOCKS 16
|
|
|
|
#define FLASH_OTP_BLOCK_SIZE 32
|
2019-02-22 16:22:46 +00:00
|
|
|
|
2023-06-30 10:12:55 +00:00
|
|
|
/**
|
|
|
|
* Flash driver interface is designed to abstract away differences between
|
|
|
|
* various MCUs used in Trezor devices.
|
|
|
|
*
|
|
|
|
* Generally, flash memory is divided into sectors. On different MCUs, sectors
|
|
|
|
* may have different sizes, and therefore, different number of sectors are used
|
|
|
|
* for a given purpose. For example, on STM32F4, the sectors are relatively
|
|
|
|
* large so we use single sector for Storage. On STM32U5, the sectors are
|
|
|
|
* smaller, so we use multiple sectors for the Storage. Storage implementation
|
|
|
|
* should not care about this, and should use flash_area_t interface to access
|
|
|
|
* the flash memory.
|
|
|
|
*
|
|
|
|
* flash_area_t represents a location in flash memory. It may be contiguous, or
|
|
|
|
* it may be composed of multiple non-contiguous subareas.
|
|
|
|
*
|
|
|
|
* flash_subarea_t represents a contiguous area in flash memory, specified by
|
|
|
|
* first_sector and num_sectors.
|
|
|
|
*/
|
2018-09-26 17:34:05 +00:00
|
|
|
|
2023-06-30 10:12:55 +00:00
|
|
|
#include "flash_common.h"
|
2017-10-26 17:09:53 +00:00
|
|
|
|
2017-12-09 13:48:49 +00:00
|
|
|
void flash_init(void);
|
2017-10-24 11:54:21 +00:00
|
|
|
|
2023-06-30 10:12:55 +00:00
|
|
|
uint32_t flash_wait_and_clear_status_flags(void);
|
2019-03-29 15:26:02 +00:00
|
|
|
|
2023-10-24 14:36:37 +00:00
|
|
|
// Erases the single sector in the designated flash area
|
|
|
|
// The 'offset' parameter must indicate the relative sector offset within the
|
|
|
|
// flash area If 'offset' is outside the bounds of the flash area,
|
|
|
|
// 'bytes_erased' is set to 0 otherwise, 'bytes_erased' is set to the size of
|
|
|
|
// the erased sector
|
|
|
|
secbool flash_area_erase_partial(const flash_area_t *area, uint32_t offset,
|
|
|
|
uint32_t *bytes_erased);
|
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
secbool __wur flash_otp_read(uint8_t block, uint8_t offset, uint8_t *data,
|
|
|
|
uint8_t datalen);
|
|
|
|
secbool __wur flash_otp_write(uint8_t block, uint8_t offset,
|
|
|
|
const uint8_t *data, uint8_t datalen);
|
2017-12-16 16:54:04 +00:00
|
|
|
secbool __wur flash_otp_lock(uint8_t block);
|
|
|
|
secbool __wur flash_otp_is_locked(uint8_t block);
|
2017-06-20 15:32:21 +00:00
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
#endif // TREZORHAL_FLASH_H
|