mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-11 19:38:48 +00:00
Fixes for emulator
This commit is contained in:
parent
68e02c94da
commit
ed7a8bfa6c
@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "memory.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) {
|
void flash_program_byte(uint32_t address, uint8_t data) {
|
||||||
*(volatile uint8_t *)FLASH_PTR(address) = 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;
|
||||||
|
}
|
||||||
|
@ -6,9 +6,9 @@ ifeq ($(EMULATOR),1)
|
|||||||
OBJS += udp.o
|
OBJS += udp.o
|
||||||
else
|
else
|
||||||
OBJS += usb.o
|
OBJS += usb.o
|
||||||
|
OBJS += bl_check.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
OBJS += bl_check.o
|
|
||||||
OBJS += u2f.o
|
OBJS += u2f.o
|
||||||
OBJS += messages.o
|
OBJS += messages.o
|
||||||
OBJS += storage.o
|
OBJS += storage.o
|
||||||
|
@ -122,12 +122,10 @@ void storage_show_error(void)
|
|||||||
|
|
||||||
void storage_check_flash_errors(uint32_t status)
|
void storage_check_flash_errors(uint32_t status)
|
||||||
{
|
{
|
||||||
#if !EMULATOR
|
|
||||||
// flash operation failed
|
// flash operation failed
|
||||||
if (status & (FLASH_SR_PGAERR | FLASH_SR_PGPERR | FLASH_SR_PGSERR | FLASH_SR_WRPERR)) {
|
if (status & (FLASH_SR_PGAERR | FLASH_SR_PGPERR | FLASH_SR_PGSERR | FLASH_SR_WRPERR)) {
|
||||||
storage_show_error();
|
storage_show_error();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool storage_from_flash(void)
|
bool storage_from_flash(void)
|
||||||
|
7
memory.h
7
memory.h
@ -111,4 +111,11 @@ void memory_protect(void);
|
|||||||
void memory_write_unlock(void);
|
void memory_write_unlock(void);
|
||||||
int memory_bootloader_hash(uint8_t *hash);
|
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
|
#endif
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include "supervise.h"
|
#include "supervise.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
#if !EMULATOR
|
||||||
|
|
||||||
static void svhandler_flash_unlock(void) {
|
static void svhandler_flash_unlock(void) {
|
||||||
flash_clear_status_flags();
|
flash_clear_status_flags();
|
||||||
flash_unlock();
|
flash_unlock();
|
||||||
@ -86,3 +88,5 @@ void svc_handler_main(uint32_t *stack) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
17
supervise.h
17
supervise.h
@ -20,6 +20,8 @@
|
|||||||
#ifndef __SUPERVISE_H__
|
#ifndef __SUPERVISE_H__
|
||||||
#define __SUPERVISE_H__
|
#define __SUPERVISE_H__
|
||||||
|
|
||||||
|
#if !EMULATOR
|
||||||
|
|
||||||
#define SVC_FLASH_UNLOCK 0
|
#define SVC_FLASH_UNLOCK 0
|
||||||
#define SVC_FLASH_ERASE 1
|
#define SVC_FLASH_ERASE 1
|
||||||
#define SVC_FLASH_PROGRAM 2
|
#define SVC_FLASH_PROGRAM 2
|
||||||
@ -67,11 +69,14 @@ inline uint32_t svc_timer_ms(void) {
|
|||||||
return r0;
|
return r0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flash_write32(uint32_t addr, uint32_t word) {
|
#else
|
||||||
*((volatile uint32_t *) addr) = word;
|
|
||||||
}
|
extern void svc_flash_unlock(void);
|
||||||
inline void flash_write8(uint32_t addr, uint8_t byte) {
|
extern void svc_flash_program(uint32_t program_size);
|
||||||
*((volatile uint8_t *) addr) = byte;
|
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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user