1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

Fixes for emulator

This commit is contained in:
Jochen Hoenicke 2018-03-26 19:02:50 +02:00 committed by Pavol Rusnak
parent 68e02c94da
commit ed7a8bfa6c
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
6 changed files with 46 additions and 9 deletions

View File

@ -18,6 +18,8 @@
*/
#include <string.h>
#include <assert.h>
#include <stdbool.h>
#include "memory.h"
@ -110,3 +112,24 @@ void flash_program_word(uint32_t address, uint32_t data) {
void flash_program_byte(uint32_t address, uint8_t data) {
*(volatile uint8_t *)FLASH_PTR(address) = data;
}
static bool flash_locked = true;
void svc_flash_unlock(void) {
assert (flash_locked);
flash_locked = false;
}
void svc_flash_program(uint32_t size) {
(void) size;
assert (!flash_locked);
}
void svc_flash_erase_sector(uint16_t sector) {
assert (!flash_locked);
assert (sector >= FLASH_META_SECTOR_FIRST &&
sector <= FLASH_META_SECTOR_LAST);
flash_erase_sector(sector, 3);
}
uint32_t svc_flash_lock(void) {
assert (!flash_locked);
flash_locked = true;
return 0;
}

View File

@ -6,9 +6,9 @@ ifeq ($(EMULATOR),1)
OBJS += udp.o
else
OBJS += usb.o
OBJS += bl_check.o
endif
OBJS += bl_check.o
OBJS += u2f.o
OBJS += messages.o
OBJS += storage.o

View File

@ -122,12 +122,10 @@ void storage_show_error(void)
void storage_check_flash_errors(uint32_t status)
{
#if !EMULATOR
// flash operation failed
if (status & (FLASH_SR_PGAERR | FLASH_SR_PGPERR | FLASH_SR_PGSERR | FLASH_SR_WRPERR)) {
storage_show_error();
}
#endif
}
bool storage_from_flash(void)

View File

@ -111,4 +111,11 @@ void memory_protect(void);
void memory_write_unlock(void);
int memory_bootloader_hash(uint8_t *hash);
inline void flash_write32(uint32_t addr, uint32_t word) {
*(volatile uint32_t *) FLASH_PTR(addr) = word;
}
inline void flash_write8(uint32_t addr, uint8_t byte) {
*(volatile uint8_t *) FLASH_PTR(addr) = byte;
}
#endif

View File

@ -22,6 +22,8 @@
#include "supervise.h"
#include "memory.h"
#if !EMULATOR
static void svhandler_flash_unlock(void) {
flash_clear_status_flags();
flash_unlock();
@ -86,3 +88,5 @@ void svc_handler_main(uint32_t *stack) {
break;
}
}
#endif

View File

@ -20,6 +20,8 @@
#ifndef __SUPERVISE_H__
#define __SUPERVISE_H__
#if !EMULATOR
#define SVC_FLASH_UNLOCK 0
#define SVC_FLASH_ERASE 1
#define SVC_FLASH_PROGRAM 2
@ -67,11 +69,14 @@ inline uint32_t svc_timer_ms(void) {
return r0;
}
inline void flash_write32(uint32_t addr, uint32_t word) {
*((volatile uint32_t *) addr) = word;
}
inline void flash_write8(uint32_t addr, uint8_t byte) {
*((volatile uint8_t *) addr) = byte;
}
#else
extern void svc_flash_unlock(void);
extern void svc_flash_program(uint32_t program_size);
extern void svc_flash_erase_sector(uint16_t sector);
extern uint32_t svc_flash_lock(void);
extern uint32_t svc_timer_ms(void);
#endif
#endif