2018-02-26 13:06:10 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
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>
|
2017-10-26 21:51:39 +00:00
|
|
|
#include "secbool.h"
|
2017-06-20 17:53:24 +00:00
|
|
|
|
2017-10-16 12:22:10 +00:00
|
|
|
// see docs/memory.md for more information
|
2017-06-20 15:32:21 +00:00
|
|
|
|
2018-11-14 14:12:19 +00:00
|
|
|
#define FLASH_SECTOR_COUNT 24
|
|
|
|
|
2017-10-16 12:22:10 +00:00
|
|
|
#define FLASH_SECTOR_BOARDLOADER_START 0
|
|
|
|
// 1
|
|
|
|
#define FLASH_SECTOR_BOARDLOADER_END 2
|
2017-06-20 15:32:21 +00:00
|
|
|
|
2017-12-12 23:11:25 +00:00
|
|
|
// 3
|
2017-10-16 12:22:10 +00:00
|
|
|
|
|
|
|
#define FLASH_SECTOR_STORAGE_1 4
|
|
|
|
|
|
|
|
#define FLASH_SECTOR_BOOTLOADER 5
|
|
|
|
|
|
|
|
#define FLASH_SECTOR_FIRMWARE_START 6
|
|
|
|
// 7
|
|
|
|
// 8
|
|
|
|
// 9
|
|
|
|
// 10
|
|
|
|
#define FLASH_SECTOR_FIRMWARE_END 11
|
|
|
|
|
|
|
|
#define FLASH_SECTOR_UNUSED_START 12
|
|
|
|
// 13
|
|
|
|
// 14
|
|
|
|
#define FLASH_SECTOR_UNUSED_END 15
|
|
|
|
|
|
|
|
#define FLASH_SECTOR_STORAGE_2 16
|
|
|
|
|
|
|
|
#define FLASH_SECTOR_FIRMWARE_EXTRA_START 17
|
|
|
|
// 18
|
|
|
|
// 19
|
|
|
|
// 20
|
|
|
|
// 21
|
|
|
|
// 22
|
|
|
|
#define FLASH_SECTOR_FIRMWARE_EXTRA_END 23
|
2017-06-20 15:32:21 +00:00
|
|
|
|
2017-10-31 13:35:41 +00:00
|
|
|
// note: FLASH_SR_RDERR is STM32F42xxx and STM32F43xxx specific (STM32F427) (reference RM0090 section 3.7.5)
|
2018-09-30 14:39:40 +00:00
|
|
|
#ifndef STM32F427xx
|
2018-09-26 17:34:05 +00:00
|
|
|
#define FLASH_SR_RDERR 0
|
|
|
|
#endif
|
|
|
|
|
2017-10-31 13:35:41 +00:00
|
|
|
#define FLASH_STATUS_ALL_FLAGS (FLASH_SR_RDERR | FLASH_SR_PGSERR | FLASH_SR_PGPERR | FLASH_SR_PGAERR | FLASH_SR_WRPERR | FLASH_SR_SOP | FLASH_SR_EOP)
|
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
|
|
|
|
2019-01-29 14:51:15 +00:00
|
|
|
secbool __wur flash_unlock_write(void);
|
|
|
|
secbool __wur flash_lock_write(void);
|
2017-09-27 09:08:46 +00:00
|
|
|
|
2017-10-18 16:30:53 +00:00
|
|
|
const void *flash_get_address(uint8_t sector, uint32_t offset, uint32_t size);
|
|
|
|
|
2017-12-16 16:54:04 +00:00
|
|
|
secbool __wur flash_erase_sectors(const uint8_t *sectors, int len, void (*progress)(int pos, int len));
|
2019-01-29 14:51:15 +00:00
|
|
|
static inline secbool flash_erase(uint8_t sector) { return flash_erase_sectors(§or, 1, NULL); }
|
2018-01-23 12:43:18 +00:00
|
|
|
secbool __wur flash_write_byte(uint8_t sector, uint32_t offset, uint8_t data);
|
|
|
|
secbool __wur flash_write_word(uint8_t sector, uint32_t offset, uint32_t data);
|
2017-09-27 09:08:46 +00:00
|
|
|
|
2017-10-12 12:35:01 +00:00
|
|
|
#define FLASH_OTP_NUM_BLOCKS 16
|
|
|
|
#define FLASH_OTP_BLOCK_SIZE 32
|
|
|
|
|
2019-02-18 16:27:31 +00:00
|
|
|
// OTP blocks allocation
|
|
|
|
#define FLASH_OTP_BLOCK_BATCH 0
|
|
|
|
#define FLASH_OTP_BLOCK_BOOTLOADER_VERSION 1
|
|
|
|
#define FLASH_OTP_BLOCK_VENDOR_KEYS_LOCK 2
|
|
|
|
#define FLASH_OTP_BLOCK_RANDOMNESS 3
|
|
|
|
|
2017-12-16 16:54:04 +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);
|
|
|
|
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
|
|
|
|
2017-10-31 13:35:41 +00:00
|
|
|
#endif // TREZORHAL_FLASH_H
|