mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-12 18:49:07 +00:00
trezorhal, unix: drop flash_write_{byte,word} usage, rename flash_write_{byte,word}_rel to flash_write_{byte,word}
This commit is contained in:
parent
1e7920435c
commit
00c193f5cc
@ -125,7 +125,7 @@ static secbool copy_sdcard(void)
|
||||
for (int i = 0; i < (IMAGE_HEADER_SIZE + codelen) / SDCARD_BLOCK_SIZE; i++) {
|
||||
ensure(sdcard_read_blocks(buf, i, 1), NULL);
|
||||
for (int j = 0; j < SDCARD_BLOCK_SIZE / sizeof(uint32_t); j++) {
|
||||
ensure(flash_write_word(BOOTLOADER_START + i * SDCARD_BLOCK_SIZE + j * sizeof(uint32_t), buf[j]), NULL);
|
||||
ensure(flash_write_word(FLASH_SECTOR_BOOTLOADER, i * SDCARD_BLOCK_SIZE + j * sizeof(uint32_t), buf[j]), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -440,7 +440,7 @@ int process_msg_FirmwareUpload(uint8_t iface_num, uint32_t msg_size, uint8_t *bu
|
||||
|
||||
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_rel(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);
|
||||
|
@ -38,17 +38,17 @@ static secbool norcow_write(uint8_t sector, uint32_t offset, uint32_t prefix, co
|
||||
ensure(flash_unlock(), NULL);
|
||||
|
||||
// write prefix
|
||||
ensure(flash_write_word_rel(norcow_sectors[sector], offset, prefix), NULL);
|
||||
ensure(flash_write_word(norcow_sectors[sector], offset, prefix), NULL);
|
||||
|
||||
if (len > 0) {
|
||||
offset += sizeof(uint32_t);
|
||||
// write data
|
||||
for (uint16_t i = 0; i < len; i++, offset++) {
|
||||
ensure(flash_write_byte_rel(norcow_sectors[sector], offset, data[i]), NULL);
|
||||
ensure(flash_write_byte(norcow_sectors[sector], offset, data[i]), NULL);
|
||||
}
|
||||
// pad with zeroes
|
||||
for (; offset % 4; offset++) {
|
||||
ensure(flash_write_byte_rel(norcow_sectors[sector], offset, 0x00), NULL);
|
||||
ensure(flash_write_byte(norcow_sectors[sector], offset, 0x00), NULL);
|
||||
}
|
||||
}
|
||||
ensure(flash_lock(), NULL);
|
||||
@ -287,7 +287,7 @@ secbool norcow_update(uint16_t key, uint16_t offset, uint32_t value)
|
||||
}
|
||||
uint32_t sector_offset = (const uint8_t*) ptr - (const uint8_t *)norcow_ptr(norcow_active_sector, 0, NORCOW_SECTOR_SIZE) + offset;
|
||||
ensure(flash_unlock(), NULL);
|
||||
ensure(flash_write_word_rel(norcow_sectors[norcow_active_sector], sector_offset, value), NULL);
|
||||
ensure(flash_write_word(norcow_sectors[norcow_active_sector], sector_offset, value), NULL);
|
||||
ensure(flash_lock(), NULL);
|
||||
return sectrue;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ static void progress_callback(int pos, int len)
|
||||
display_printf(".");
|
||||
}
|
||||
|
||||
static void flash_from_sdcard(uint32_t target, uint32_t source, uint32_t length)
|
||||
static void flash_from_sdcard(uint8_t sector, uint32_t source, uint32_t length)
|
||||
{
|
||||
static uint32_t buf[SDCARD_BLOCK_SIZE / sizeof(uint32_t)];
|
||||
|
||||
@ -45,7 +45,7 @@ static void flash_from_sdcard(uint32_t target, uint32_t source, uint32_t length)
|
||||
"sdcard_read_blocks");
|
||||
|
||||
for (uint32_t j = 0; j < SDCARD_BLOCK_SIZE / sizeof(uint32_t); j++) {
|
||||
ensure(flash_write_word(target + i * SDCARD_BLOCK_SIZE + j * sizeof(uint32_t), buf[j]), NULL);
|
||||
ensure(flash_write_word(sector, i * SDCARD_BLOCK_SIZE + j * sizeof(uint32_t), buf[j]), NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,13 +78,16 @@ int main(void)
|
||||
|
||||
ensure(flash_unlock(), NULL);
|
||||
|
||||
sdcard_power_on();
|
||||
ensure(sdcard_power_on(), NULL);
|
||||
|
||||
#define BOARDLOADER_SIZE (3 * 16 * 1024)
|
||||
#define BOOTLOADER_SIZE (128 * 1024)
|
||||
#define BOARDLOADER_CHUNK_SIZE (16 * 1024)
|
||||
#define BOARDLOADER_TOTAL_SIZE (3 * BOARDLOADER_CHUNK_SIZE)
|
||||
#define BOOTLOADER_TOTAL_SIZE (128 * 1024)
|
||||
|
||||
flash_from_sdcard(BOARDLOADER_START, 0, BOARDLOADER_SIZE);
|
||||
flash_from_sdcard(BOOTLOADER_START, BOARDLOADER_SIZE, BOOTLOADER_SIZE);
|
||||
flash_from_sdcard(FLASH_SECTOR_BOARDLOADER_START, 0 * BOARDLOADER_CHUNK_SIZE, BOARDLOADER_CHUNK_SIZE);
|
||||
flash_from_sdcard(1, 1 * BOARDLOADER_CHUNK_SIZE, BOARDLOADER_CHUNK_SIZE);
|
||||
flash_from_sdcard(FLASH_SECTOR_BOARDLOADER_END, 2 * BOARDLOADER_CHUNK_SIZE, BOARDLOADER_CHUNK_SIZE);
|
||||
flash_from_sdcard(FLASH_SECTOR_BOOTLOADER, BOARDLOADER_TOTAL_SIZE, BOOTLOADER_TOTAL_SIZE);
|
||||
|
||||
display_printf("done\n");
|
||||
sdcard_power_off();
|
||||
|
@ -105,27 +105,25 @@ secbool flash_erase_sectors(const uint8_t *sectors, int len, void (*progress)(in
|
||||
return sectrue;
|
||||
}
|
||||
|
||||
secbool flash_write_byte(uint32_t address, uint8_t data)
|
||||
secbool flash_write_byte(uint8_t sector, uint32_t offset, uint8_t data)
|
||||
{
|
||||
uint32_t address = (uint32_t)flash_get_address(sector, offset, 1);
|
||||
if (address == 0) {
|
||||
return secfalse;
|
||||
}
|
||||
return sectrue * (HAL_OK == HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, address, data));
|
||||
}
|
||||
|
||||
secbool flash_write_word(uint32_t address, uint32_t data)
|
||||
{
|
||||
return sectrue * (HAL_OK == HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data));
|
||||
}
|
||||
|
||||
secbool flash_write_byte_rel(uint8_t sector, uint32_t offset, uint8_t data)
|
||||
{
|
||||
return sectrue * (HAL_OK == HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, FLASH_SECTOR_TABLE[sector] + offset, data));
|
||||
}
|
||||
|
||||
secbool flash_write_word_rel(uint8_t sector, uint32_t offset, uint32_t data)
|
||||
secbool flash_write_word(uint8_t sector, uint32_t offset, uint32_t data)
|
||||
{
|
||||
uint32_t address = (uint32_t)flash_get_address(sector, offset, 4);
|
||||
if (address == 0) {
|
||||
return secfalse;
|
||||
}
|
||||
if (offset % 4 != 0) {
|
||||
return secfalse;
|
||||
}
|
||||
return sectrue * (HAL_OK == HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, FLASH_SECTOR_TABLE[sector] + offset, data));
|
||||
return sectrue * (HAL_OK == HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data));
|
||||
}
|
||||
|
||||
#define FLASH_OTP_LOCK_BASE 0x1FFF7A00U
|
||||
@ -149,7 +147,8 @@ secbool flash_otp_write(uint8_t block, uint8_t offset, const uint8_t *data, uint
|
||||
ensure(flash_unlock(), NULL);
|
||||
secbool ret = secfalse;
|
||||
for (uint8_t i = 0; i < datalen; i++) {
|
||||
ensure(flash_write_byte(FLASH_OTP_BASE + block * FLASH_OTP_BLOCK_SIZE + offset + i, data[i]), NULL);
|
||||
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);
|
||||
return ret;
|
||||
|
@ -52,10 +52,8 @@ 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); }
|
||||
secbool __wur flash_write_byte(uint32_t address, uint8_t data);
|
||||
secbool __wur flash_write_word(uint32_t address, uint32_t data);
|
||||
secbool __wur flash_write_byte_rel(uint8_t sector, uint32_t offset, uint8_t data);
|
||||
secbool __wur flash_write_word_rel(uint8_t sector, uint32_t offset, uint32_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);
|
||||
|
||||
#define FLASH_OTP_NUM_BLOCKS 16
|
||||
#define FLASH_OTP_BLOCK_SIZE 32
|
||||
|
@ -132,7 +132,7 @@ secbool flash_erase_sectors(const uint8_t *sectors, int len, void (*progress)(in
|
||||
return sectrue;
|
||||
}
|
||||
|
||||
secbool flash_write_byte_rel(uint8_t sector, uint32_t offset, uint8_t data)
|
||||
secbool flash_write_byte(uint8_t sector, uint32_t offset, uint8_t data)
|
||||
{
|
||||
uint8_t *flash = (uint8_t *)flash_get_address(sector, offset, sizeof(data));
|
||||
if (!flash) {
|
||||
@ -145,7 +145,7 @@ secbool flash_write_byte_rel(uint8_t sector, uint32_t offset, uint8_t data)
|
||||
return sectrue;
|
||||
}
|
||||
|
||||
secbool flash_write_word_rel(uint8_t sector, uint32_t offset, uint32_t data)
|
||||
secbool flash_write_word(uint8_t sector, uint32_t offset, uint32_t data)
|
||||
{
|
||||
if (offset % 4) { // we write only at 4-byte boundary
|
||||
return secfalse;
|
||||
|
Loading…
Reference in New Issue
Block a user