mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-14 03:30:02 +00:00
Fix emulator memory access.
This commit is contained in:
parent
4f32cb5083
commit
d970597ddd
@ -3,7 +3,7 @@ EMULATOR := 1
|
|||||||
OBJS += setup.o
|
OBJS += setup.o
|
||||||
|
|
||||||
OBJS += buttons.o
|
OBJS += buttons.o
|
||||||
OBJS += flash.o
|
OBJS += memory.o
|
||||||
OBJS += oled.o
|
OBJS += oled.o
|
||||||
OBJS += rng.o
|
OBJS += rng.o
|
||||||
OBJS += timer.o
|
OBJS += timer.o
|
||||||
|
24
flash.c
24
flash.c
@ -71,7 +71,7 @@ const void *flash_get_address(uint8_t sector, uint32_t offset, uint32_t size)
|
|||||||
if (addr + size > next) {
|
if (addr + size > next) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return (const void *)addr;
|
return (const void *) FLASH_PTR(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
secbool flash_erase(uint8_t sector)
|
secbool flash_erase(uint8_t sector)
|
||||||
@ -83,7 +83,7 @@ secbool flash_erase(uint8_t sector)
|
|||||||
// Check whether the sector was really deleted (contains only 0xFF).
|
// Check whether the sector was really deleted (contains only 0xFF).
|
||||||
const uint32_t addr_start = FLASH_SECTOR_TABLE[sector], addr_end = FLASH_SECTOR_TABLE[sector + 1];
|
const uint32_t addr_start = FLASH_SECTOR_TABLE[sector], addr_end = FLASH_SECTOR_TABLE[sector + 1];
|
||||||
for (uint32_t addr = addr_start; addr < addr_end; addr += 4) {
|
for (uint32_t addr = addr_start; addr < addr_end; addr += 4) {
|
||||||
if (*((const uint32_t *)addr) != 0xFFFFFFFF) {
|
if (*((const uint32_t *)FLASH_PTR(addr)) != 0xFFFFFFFF) {
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,19 +92,19 @@ secbool flash_erase(uint8_t sector)
|
|||||||
|
|
||||||
secbool flash_write_byte(uint8_t sector, uint32_t offset, 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);
|
uint8_t *address = (uint8_t *) flash_get_address(sector, offset, 1);
|
||||||
if (address == 0) {
|
if (address == NULL) {
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*((uint8_t*)address) & data) != data) {
|
if ((*address & data) != data) {
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
svc_flash_program(FLASH_CR_PROGRAM_X8);
|
svc_flash_program(FLASH_CR_PROGRAM_X8);
|
||||||
flash_write8(address, data);
|
*(volatile uint8_t *) address = data;
|
||||||
|
|
||||||
if (*((uint8_t*)address) != data) {
|
if (*address != data) {
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,8 +113,8 @@ secbool flash_write_byte(uint8_t sector, uint32_t offset, uint8_t data)
|
|||||||
|
|
||||||
secbool flash_write_word(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);
|
uint32_t *address = (uint32_t *) flash_get_address(sector, offset, 4);
|
||||||
if (address == 0) {
|
if (address == NULL) {
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,14 +122,14 @@ secbool flash_write_word(uint8_t sector, uint32_t offset, uint32_t data)
|
|||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*((uint32_t*)address) & data) != data) {
|
if ((*address & data) != data) {
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
svc_flash_program(FLASH_CR_PROGRAM_X32);
|
svc_flash_program(FLASH_CR_PROGRAM_X32);
|
||||||
flash_write32(address, data);
|
*(volatile uint32_t *) address = data;
|
||||||
|
|
||||||
if (*((uint32_t*)address) != data) {
|
if (*address != data) {
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
flash.h
6
flash.h
@ -17,8 +17,8 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TREZORHAL_FLASH_H
|
#ifndef FLASH_H
|
||||||
#define TREZORHAL_FLASH_H
|
#define FLASH_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -44,4 +44,4 @@ secbool __wur flash_erase(uint8_t sector);
|
|||||||
secbool __wur flash_write_byte(uint8_t sector, uint32_t offset, uint8_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);
|
secbool __wur flash_write_word(uint8_t sector, uint32_t offset, uint32_t data);
|
||||||
|
|
||||||
#endif // TREZORHAL_FLASH_H
|
#endif // FLASH_H
|
||||||
|
Loading…
Reference in New Issue
Block a user