From 8832c6e63b6b099f8333b7b7f97695160696547f Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 29 Jan 2019 15:51:15 +0100 Subject: [PATCH] embed/trezorhal: rename flash functions flash_erase_sector -> flash_erase flash_lock -> flash_lock_write flash_unlock -> flash_unlock_write --- embed/boardloader/main.c | 4 ++-- embed/bootloader/messages.c | 4 ++-- embed/prodtest/main.c | 4 ++-- embed/reflash/main.c | 4 ++-- embed/trezorhal/flash.c | 20 ++++++++++---------- embed/trezorhal/flash.h | 6 +++--- embed/unix/flash.c | 4 ++-- vendor/trezor-storage | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/embed/boardloader/main.c b/embed/boardloader/main.c index 1d32a3ce0c..d5ff4a4993 100644 --- a/embed/boardloader/main.c +++ b/embed/boardloader/main.c @@ -133,7 +133,7 @@ static secbool copy_sdcard(void) } display_printf(" done\n\n"); - ensure(flash_unlock(), NULL); + ensure(flash_unlock_write(), NULL); // copy bootloader from SD card to Flash display_printf("copying new bootloader from SD card\n\n"); @@ -149,7 +149,7 @@ static secbool copy_sdcard(void) } sdcard_power_off(); - ensure(flash_lock(), NULL); + ensure(flash_lock_write(), NULL); display_printf("\ndone\n\n"); display_printf("Unplug the device and remove the SD card\n"); diff --git a/embed/bootloader/messages.c b/embed/bootloader/messages.c index 28949c43ed..269215fe0a 100644 --- a/embed/bootloader/messages.c +++ b/embed/bootloader/messages.c @@ -517,14 +517,14 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, uint8_t *bu return -6; } - ensure(flash_unlock(), NULL); + ensure(flash_unlock_write(), NULL); const uint32_t * const src = (const uint32_t * const)chunk_buffer; 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_lock(), NULL); + ensure(flash_lock_write(), NULL); firmware_remaining -= chunk_requested; firmware_block++; diff --git a/embed/prodtest/main.c b/embed/prodtest/main.c index 8f3ca2fd2b..5a663c531b 100644 --- a/embed/prodtest/main.c +++ b/embed/prodtest/main.c @@ -305,11 +305,11 @@ power_off: static void test_wipe(void) { // 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++) { 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_text_center(DISPLAY_RESX / 2, DISPLAY_RESY / 2 + 10, "WIPED", -1, FONT_BOLD, COLOR_WHITE, COLOR_BLACK); display_refresh(); diff --git a/embed/reflash/main.c b/embed/reflash/main.c index 3013f4b4a9..236f4779ab 100644 --- a/embed/reflash/main.c +++ b/embed/reflash/main.c @@ -88,7 +88,7 @@ int main(void) display_printf("\n"); display_printf("erased\n"); - ensure(flash_unlock(), NULL); + ensure(flash_unlock_write(), NULL); ensure(sdcard_power_on(), NULL); @@ -103,7 +103,7 @@ int main(void) display_printf("done\n"); sdcard_power_off(); - ensure(flash_lock(), NULL); + ensure(flash_lock_write(), NULL); return 0; } diff --git a/embed/trezorhal/flash.c b/embed/trezorhal/flash.c index 5496677d5f..1f468e91f8 100644 --- a/embed/trezorhal/flash.c +++ b/embed/trezorhal/flash.c @@ -58,14 +58,14 @@ void flash_init(void) { } -secbool flash_unlock(void) +secbool flash_unlock_write(void) { HAL_FLASH_Unlock(); FLASH->SR |= FLASH_STATUS_ALL_FLAGS; // clear all status flags return sectrue; } -secbool flash_lock(void) +secbool flash_lock_write(void) { HAL_FLASH_Lock(); 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)) { - ensure(flash_unlock(), NULL); + ensure(flash_unlock_write(), NULL); FLASH_EraseInitTypeDef EraseInitStruct; EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; 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]; uint32_t SectorError; if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) { - ensure(flash_lock(), NULL); + ensure(flash_lock_write(), NULL); return secfalse; } // 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]; for (uint32_t addr = addr_start; addr < addr_end; addr += 4) { if (*((const uint32_t *)addr) != 0xFFFFFFFF) { - ensure(flash_lock(), NULL); + ensure(flash_lock_write(), NULL); return secfalse; } } @@ -113,7 +113,7 @@ secbool flash_erase_sectors(const uint8_t *sectors, int len, void (*progress)(in progress(i + 1, len); } } - ensure(flash_lock(), NULL); + ensure(flash_lock_write(), NULL); 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) { return secfalse; } - ensure(flash_unlock(), NULL); + ensure(flash_unlock_write(), NULL); for (uint8_t i = 0; i < datalen; 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(flash_lock(), NULL); + ensure(flash_lock_write(), NULL); return sectrue; } @@ -189,9 +189,9 @@ secbool flash_otp_lock(uint8_t block) if (block >= FLASH_OTP_NUM_BLOCKS) { 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); - ensure(flash_lock(), NULL); + ensure(flash_lock_write(), NULL); return sectrue * (ret == HAL_OK); } diff --git a/embed/trezorhal/flash.h b/embed/trezorhal/flash.h index a13c351766..2548571a48 100644 --- a/embed/trezorhal/flash.h +++ b/embed/trezorhal/flash.h @@ -69,13 +69,13 @@ void flash_init(void); -secbool __wur flash_unlock(void); -secbool __wur flash_lock(void); +secbool __wur flash_unlock_write(void); +secbool __wur flash_lock_write(void); 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)); -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_word(uint8_t sector, uint32_t offset, uint32_t data); diff --git a/embed/unix/flash.c b/embed/unix/flash.c index 52ec0ed74d..a76e6f2e46 100644 --- a/embed/unix/flash.c +++ b/embed/unix/flash.c @@ -103,12 +103,12 @@ void flash_init(void) atexit(flash_exit); } -secbool flash_unlock(void) +secbool flash_unlock_write(void) { return sectrue; } -secbool flash_lock(void) +secbool flash_lock_write(void) { return sectrue; } diff --git a/vendor/trezor-storage b/vendor/trezor-storage index 8970e2bdeb..fc29df6f87 160000 --- a/vendor/trezor-storage +++ b/vendor/trezor-storage @@ -1 +1 @@ -Subproject commit 8970e2bdebb3334ddd0bacf41c66be79e78880f8 +Subproject commit fc29df6f874efa649bc3520c247b2169ffb563bf