mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
trezorhal: introduce flash_write_{byte,word}
This commit is contained in:
parent
ef353f7bc6
commit
d50eeb581a
@ -89,7 +89,7 @@ bool copy_sdcard(void)
|
|||||||
for (int i = 0; i < (HEADER_SIZE + hdr.codelen) / SDCARD_BLOCK_SIZE; i++) {
|
for (int i = 0; i < (HEADER_SIZE + hdr.codelen) / SDCARD_BLOCK_SIZE; i++) {
|
||||||
sdcard_read_blocks((uint8_t *)buf, i, 1);
|
sdcard_read_blocks((uint8_t *)buf, i, 1);
|
||||||
for (int j = 0; j < SDCARD_BLOCK_SIZE / sizeof(uint32_t); j++) {
|
for (int j = 0; j < SDCARD_BLOCK_SIZE / sizeof(uint32_t); j++) {
|
||||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, BOOTLOADER_START + i * SDCARD_BLOCK_SIZE + j * sizeof(uint32_t), buf[j]) != HAL_OK) {
|
if (!flash_write_word(BOOTLOADER_START + i * SDCARD_BLOCK_SIZE + j * sizeof(uint32_t), buf[j])) {
|
||||||
display_printf("copy failed\n");
|
display_printf("copy failed\n");
|
||||||
sdcard_power_off();
|
sdcard_power_off();
|
||||||
flash_lock();
|
flash_lock();
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#include STM32_HAL_H
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <pb_decode.h>
|
#include <pb_decode.h>
|
||||||
@ -279,7 +277,7 @@ static bool _read_payload(pb_istream_t *stream, const pb_field_t *field, void **
|
|||||||
}
|
}
|
||||||
// write data
|
// write data
|
||||||
for (int i = 0; i < BUFSIZE / sizeof(uint32_t); i++) {
|
for (int i = 0; i < BUFSIZE / sizeof(uint32_t); i++) {
|
||||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, FIRMWARE_START + firmware_flashed + chunk_written + i * sizeof(uint32_t), buf[i]) != HAL_OK) {
|
if (!flash_write_word(FIRMWARE_START + firmware_flashed + chunk_written + i * sizeof(uint32_t), buf[i])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
#if defined TREZOR_STM32
|
#if defined TREZOR_STM32
|
||||||
|
|
||||||
#define NORCOW_STM32 1
|
#define NORCOW_STM32 1
|
||||||
#define NORCOW_START_SECTOR 2
|
|
||||||
|
#define NORCOW_START_SECTOR 2
|
||||||
#define NORCOW_START_ADDRESS 0x08008000
|
#define NORCOW_START_ADDRESS 0x08008000
|
||||||
|
|
||||||
#elif defined TREZOR_UNIX
|
#elif defined TREZOR_UNIX
|
||||||
|
|
||||||
#define NORCOW_UNIX 1
|
#define NORCOW_UNIX 1
|
||||||
|
|
||||||
#define NORCOW_FILE "/var/tmp/trezor.config"
|
#define NORCOW_FILE "/var/tmp/trezor.config"
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#error Unsupported TREZOR port. Only STM32 and UNIX ports are supported.
|
#error Unsupported TREZOR port. Only STM32 and UNIX ports are supported.
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -45,8 +45,7 @@ void flash_set_option_bytes(void)
|
|||||||
bool flash_unlock(void)
|
bool flash_unlock(void)
|
||||||
{
|
{
|
||||||
HAL_FLASH_Unlock();
|
HAL_FLASH_Unlock();
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
||||||
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +79,16 @@ bool flash_erase_sectors(int start, int end, void (*progress)(uint16_t val))
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool flash_write_byte(uint32_t address, uint8_t data)
|
||||||
|
{
|
||||||
|
return HAL_OK == HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, address, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool flash_write_word(uint32_t address, uint32_t data)
|
||||||
|
{
|
||||||
|
return HAL_OK == HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data);
|
||||||
|
}
|
||||||
|
|
||||||
#define FLASH_OTP_LOCK_BASE 0x1FFF7A00U
|
#define FLASH_OTP_LOCK_BASE 0x1FFF7A00U
|
||||||
#define FLASH_OTP_NUM_BLOCKS 16
|
#define FLASH_OTP_NUM_BLOCKS 16
|
||||||
#define FLASH_OTP_BLOCK_SIZE 32
|
#define FLASH_OTP_BLOCK_SIZE 32
|
||||||
@ -103,15 +112,15 @@ bool flash_otp_write(uint8_t block, uint8_t offset, const uint8_t *data, uint8_t
|
|||||||
if (!flash_unlock()) {
|
if (!flash_unlock()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HAL_StatusTypeDef ret;
|
bool ret;
|
||||||
for (uint8_t i = 0; i < datalen; i++) {
|
for (uint8_t i = 0; i < datalen; i++) {
|
||||||
ret = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, FLASH_OTP_BASE + block * FLASH_OTP_BLOCK_SIZE + offset + i, data[i]);
|
ret = flash_write_byte(FLASH_OTP_BASE + block * FLASH_OTP_BLOCK_SIZE + offset + i, data[i]);
|
||||||
if (ret != HAL_OK) {
|
if (!ret) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flash_lock();
|
flash_lock();
|
||||||
return ret == HAL_OK;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool flash_otp_lock(uint8_t block)
|
bool flash_otp_lock(uint8_t block)
|
||||||
|
@ -24,6 +24,8 @@ bool flash_unlock(void);
|
|||||||
bool flash_lock(void);
|
bool flash_lock(void);
|
||||||
|
|
||||||
bool flash_erase_sectors(int start, int end, void (*progress)(uint16_t val));
|
bool flash_erase_sectors(int start, int end, void (*progress)(uint16_t val));
|
||||||
|
bool flash_write_byte(uint32_t address, uint8_t data);
|
||||||
|
bool flash_write_word(uint32_t address, uint32_t data);
|
||||||
|
|
||||||
bool flash_otp_read(uint8_t block, uint8_t offset, uint8_t *data, uint8_t datalen);
|
bool flash_otp_read(uint8_t block, uint8_t offset, uint8_t *data, uint8_t datalen);
|
||||||
bool flash_otp_write(uint8_t block, uint8_t offset, const uint8_t *data, uint8_t datalen);
|
bool flash_otp_write(uint8_t block, uint8_t offset, const uint8_t *data, uint8_t datalen);
|
||||||
|
2
vendor/norcow
vendored
2
vendor/norcow
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 81c00e0a53792c5d2c29895824c861e5d4341737
|
Subproject commit 8d2843aeb58f8fd0fc5162a11d5be1e2575776ca
|
Loading…
Reference in New Issue
Block a user