1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 06:48:16 +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:
Pavol Rusnak 2019-01-29 15:51:15 +01:00
parent b754ee8cf6
commit 8832c6e63b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
8 changed files with 24 additions and 24 deletions

View File

@ -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");

View File

@ -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++;

View File

@ -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();

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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(&sector, 1, NULL); }
static inline secbool flash_erase(uint8_t sector) { return flash_erase_sectors(&sector, 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);

View File

@ -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;
}

@ -1 +1 @@
Subproject commit 8970e2bdebb3334ddd0bacf41c66be79e78880f8
Subproject commit fc29df6f874efa649bc3520c247b2169ffb563bf