mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
embed/trezorhal: rename flash functions
flash_erase_sector -> flash_erase flash_lock -> flash_lock_write flash_unlock -> flash_unlock_write
This commit is contained in:
parent
b754ee8cf6
commit
8832c6e63b
@ -133,7 +133,7 @@ static secbool copy_sdcard(void)
|
|||||||
}
|
}
|
||||||
display_printf(" done\n\n");
|
display_printf(" done\n\n");
|
||||||
|
|
||||||
ensure(flash_unlock(), NULL);
|
ensure(flash_unlock_write(), NULL);
|
||||||
|
|
||||||
// copy bootloader from SD card to Flash
|
// copy bootloader from SD card to Flash
|
||||||
display_printf("copying new bootloader from SD card\n\n");
|
display_printf("copying new bootloader from SD card\n\n");
|
||||||
@ -149,7 +149,7 @@ static secbool copy_sdcard(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sdcard_power_off();
|
sdcard_power_off();
|
||||||
ensure(flash_lock(), NULL);
|
ensure(flash_lock_write(), NULL);
|
||||||
|
|
||||||
display_printf("\ndone\n\n");
|
display_printf("\ndone\n\n");
|
||||||
display_printf("Unplug the device and remove the SD card\n");
|
display_printf("Unplug the device and remove the SD card\n");
|
||||||
|
@ -517,14 +517,14 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, uint8_t *bu
|
|||||||
return -6;
|
return -6;
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure(flash_unlock(), NULL);
|
ensure(flash_unlock_write(), NULL);
|
||||||
|
|
||||||
const uint32_t * const src = (const uint32_t * const)chunk_buffer;
|
const uint32_t * const src = (const uint32_t * const)chunk_buffer;
|
||||||
for (int i = 0; i < chunk_size / sizeof(uint32_t); i++) {
|
for (int i = 0; i < chunk_size / sizeof(uint32_t); i++) {
|
||||||
ensure(flash_write_word(firmware_sectors[firmware_block], i * sizeof(uint32_t), src[i]), NULL);
|
ensure(flash_write_word(firmware_sectors[firmware_block], i * sizeof(uint32_t), src[i]), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure(flash_lock(), NULL);
|
ensure(flash_lock_write(), NULL);
|
||||||
|
|
||||||
firmware_remaining -= chunk_requested;
|
firmware_remaining -= chunk_requested;
|
||||||
firmware_block++;
|
firmware_block++;
|
||||||
|
@ -305,11 +305,11 @@ power_off:
|
|||||||
static void test_wipe(void)
|
static void test_wipe(void)
|
||||||
{
|
{
|
||||||
// erase start of the firmware (metadata) -> invalidate FW
|
// erase start of the firmware (metadata) -> invalidate FW
|
||||||
ensure(flash_unlock(), NULL);
|
ensure(flash_unlock_write(), NULL);
|
||||||
for (int i = 0; i < 1024 / sizeof(uint32_t); i++) {
|
for (int i = 0; i < 1024 / sizeof(uint32_t); i++) {
|
||||||
ensure(flash_write_word(FLASH_SECTOR_FIRMWARE_START, i * sizeof(uint32_t), 0x00000000), NULL);
|
ensure(flash_write_word(FLASH_SECTOR_FIRMWARE_START, i * sizeof(uint32_t), 0x00000000), NULL);
|
||||||
}
|
}
|
||||||
ensure(flash_lock(), NULL);
|
ensure(flash_lock_write(), NULL);
|
||||||
display_clear();
|
display_clear();
|
||||||
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY / 2 + 10, "WIPED", -1, FONT_BOLD, COLOR_WHITE, COLOR_BLACK);
|
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY / 2 + 10, "WIPED", -1, FONT_BOLD, COLOR_WHITE, COLOR_BLACK);
|
||||||
display_refresh();
|
display_refresh();
|
||||||
|
@ -88,7 +88,7 @@ int main(void)
|
|||||||
display_printf("\n");
|
display_printf("\n");
|
||||||
display_printf("erased\n");
|
display_printf("erased\n");
|
||||||
|
|
||||||
ensure(flash_unlock(), NULL);
|
ensure(flash_unlock_write(), NULL);
|
||||||
|
|
||||||
ensure(sdcard_power_on(), NULL);
|
ensure(sdcard_power_on(), NULL);
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ int main(void)
|
|||||||
|
|
||||||
display_printf("done\n");
|
display_printf("done\n");
|
||||||
sdcard_power_off();
|
sdcard_power_off();
|
||||||
ensure(flash_lock(), NULL);
|
ensure(flash_lock_write(), NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -58,14 +58,14 @@ void flash_init(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
secbool flash_unlock(void)
|
secbool flash_unlock_write(void)
|
||||||
{
|
{
|
||||||
HAL_FLASH_Unlock();
|
HAL_FLASH_Unlock();
|
||||||
FLASH->SR |= FLASH_STATUS_ALL_FLAGS; // clear all status flags
|
FLASH->SR |= FLASH_STATUS_ALL_FLAGS; // clear all status flags
|
||||||
return sectrue;
|
return sectrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
secbool flash_lock(void)
|
secbool flash_lock_write(void)
|
||||||
{
|
{
|
||||||
HAL_FLASH_Lock();
|
HAL_FLASH_Lock();
|
||||||
return sectrue;
|
return sectrue;
|
||||||
@ -86,7 +86,7 @@ const void *flash_get_address(uint8_t sector, uint32_t offset, uint32_t size)
|
|||||||
|
|
||||||
secbool flash_erase_sectors(const uint8_t *sectors, int len, void (*progress)(int pos, int len))
|
secbool flash_erase_sectors(const uint8_t *sectors, int len, void (*progress)(int pos, int len))
|
||||||
{
|
{
|
||||||
ensure(flash_unlock(), NULL);
|
ensure(flash_unlock_write(), NULL);
|
||||||
FLASH_EraseInitTypeDef EraseInitStruct;
|
FLASH_EraseInitTypeDef EraseInitStruct;
|
||||||
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
|
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
|
||||||
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
|
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
|
||||||
@ -98,14 +98,14 @@ secbool flash_erase_sectors(const uint8_t *sectors, int len, void (*progress)(in
|
|||||||
EraseInitStruct.Sector = sectors[i];
|
EraseInitStruct.Sector = sectors[i];
|
||||||
uint32_t SectorError;
|
uint32_t SectorError;
|
||||||
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
|
if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) {
|
||||||
ensure(flash_lock(), NULL);
|
ensure(flash_lock_write(), NULL);
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
// check whether the sector was really deleted (contains only 0xFF)
|
// check whether the sector was really deleted (contains only 0xFF)
|
||||||
const uint32_t addr_start = FLASH_SECTOR_TABLE[sectors[i]], addr_end = FLASH_SECTOR_TABLE[sectors[i] + 1];
|
const uint32_t addr_start = FLASH_SECTOR_TABLE[sectors[i]], addr_end = FLASH_SECTOR_TABLE[sectors[i] + 1];
|
||||||
for (uint32_t addr = addr_start; addr < addr_end; addr += 4) {
|
for (uint32_t addr = addr_start; addr < addr_end; addr += 4) {
|
||||||
if (*((const uint32_t *)addr) != 0xFFFFFFFF) {
|
if (*((const uint32_t *)addr) != 0xFFFFFFFF) {
|
||||||
ensure(flash_lock(), NULL);
|
ensure(flash_lock_write(), NULL);
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ secbool flash_erase_sectors(const uint8_t *sectors, int len, void (*progress)(in
|
|||||||
progress(i + 1, len);
|
progress(i + 1, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ensure(flash_lock(), NULL);
|
ensure(flash_lock_write(), NULL);
|
||||||
return sectrue;
|
return sectrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,12 +175,12 @@ secbool flash_otp_write(uint8_t block, uint8_t offset, const uint8_t *data, uint
|
|||||||
if (block >= FLASH_OTP_NUM_BLOCKS || offset + datalen > FLASH_OTP_BLOCK_SIZE) {
|
if (block >= FLASH_OTP_NUM_BLOCKS || offset + datalen > FLASH_OTP_BLOCK_SIZE) {
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
ensure(flash_unlock(), NULL);
|
ensure(flash_unlock_write(), NULL);
|
||||||
for (uint8_t i = 0; i < datalen; i++) {
|
for (uint8_t i = 0; i < datalen; i++) {
|
||||||
uint32_t address = FLASH_OTP_BASE + block * FLASH_OTP_BLOCK_SIZE + offset + i;
|
uint32_t address = FLASH_OTP_BASE + block * FLASH_OTP_BLOCK_SIZE + offset + i;
|
||||||
ensure(sectrue * (HAL_OK == HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, address, data[i])), NULL);
|
ensure(sectrue * (HAL_OK == HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, address, data[i])), NULL);
|
||||||
}
|
}
|
||||||
ensure(flash_lock(), NULL);
|
ensure(flash_lock_write(), NULL);
|
||||||
return sectrue;
|
return sectrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,9 +189,9 @@ secbool flash_otp_lock(uint8_t block)
|
|||||||
if (block >= FLASH_OTP_NUM_BLOCKS) {
|
if (block >= FLASH_OTP_NUM_BLOCKS) {
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
ensure(flash_unlock(), NULL);
|
ensure(flash_unlock_write(), NULL);
|
||||||
HAL_StatusTypeDef ret = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, FLASH_OTP_LOCK_BASE + block, 0x00);
|
HAL_StatusTypeDef ret = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, FLASH_OTP_LOCK_BASE + block, 0x00);
|
||||||
ensure(flash_lock(), NULL);
|
ensure(flash_lock_write(), NULL);
|
||||||
return sectrue * (ret == HAL_OK);
|
return sectrue * (ret == HAL_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,13 +69,13 @@
|
|||||||
|
|
||||||
void flash_init(void);
|
void flash_init(void);
|
||||||
|
|
||||||
secbool __wur flash_unlock(void);
|
secbool __wur flash_unlock_write(void);
|
||||||
secbool __wur flash_lock(void);
|
secbool __wur flash_lock_write(void);
|
||||||
|
|
||||||
const void *flash_get_address(uint8_t sector, uint32_t offset, uint32_t size);
|
const void *flash_get_address(uint8_t sector, uint32_t offset, uint32_t size);
|
||||||
|
|
||||||
secbool __wur flash_erase_sectors(const uint8_t *sectors, int len, void (*progress)(int pos, int len));
|
secbool __wur flash_erase_sectors(const uint8_t *sectors, int len, void (*progress)(int pos, int len));
|
||||||
static inline secbool flash_erase_sector(uint8_t sector) { return flash_erase_sectors(§or, 1, NULL); }
|
static inline secbool flash_erase(uint8_t sector) { return flash_erase_sectors(§or, 1, NULL); }
|
||||||
secbool __wur flash_write_byte(uint8_t sector, uint32_t offset, uint8_t data);
|
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);
|
secbool __wur flash_write_word(uint8_t sector, uint32_t offset, uint32_t data);
|
||||||
|
|
||||||
|
@ -103,12 +103,12 @@ void flash_init(void)
|
|||||||
atexit(flash_exit);
|
atexit(flash_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
secbool flash_unlock(void)
|
secbool flash_unlock_write(void)
|
||||||
{
|
{
|
||||||
return sectrue;
|
return sectrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
secbool flash_lock(void)
|
secbool flash_lock_write(void)
|
||||||
{
|
{
|
||||||
return sectrue;
|
return sectrue;
|
||||||
}
|
}
|
||||||
|
2
vendor/trezor-storage
vendored
2
vendor/trezor-storage
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 8970e2bdebb3334ddd0bacf41c66be79e78880f8
|
Subproject commit fc29df6f874efa649bc3520c247b2169ffb563bf
|
Loading…
Reference in New Issue
Block a user