20
20
#ifndef MEMORY_H
21
21
#define MEMORY_H
22
22
23
+ //#include <libopencm3/cm3/mpu.h>
23
24
#include "trezor/crypto/sha2.h"
24
25
25
26
#include <stddef.h>
26
27
#include <stdbool.h>
27
28
#include <inttypes.h>
28
29
30
+
29
31
/*
30
32
31
33
flash memory layout:
32
34
--------------------
33
- name | range | size | function | permissions
34
- -----------+-------------------------+---------+------------------+-------------
35
- Sector 0 | 0x08000000 - 0x08003FFF | 16 KiB | bootstrap code | Read
36
- Sector 1 | 0x08004000 - 0x08007FFF | 16 KiB | storage/config | Read Write
37
- -----------+-------------------------+---------+------------------+-------------
38
- Sector 2 | 0x08008000 - 0x0800BFFF | 16 KiB | storage/config | Read Write
39
- Sector 3 | 0x0800C000 - 0x0800FFFF | 16 KiB | storage/config | Read Write
40
- -----------+-------------------------+---------+------------------+-------------
41
- Sector 4 | 0x08010000 - 0x0801FFFF | 64 KiB | empty | Read Write
42
- Sector 5 | 0x08020000 - 0x0803FFFF | 128 KiB | bootloader code | Read
43
- Sector 6 | 0x08040000 - 0x0805FFFF | 128 KiB | bootloader code | Read
44
- Sector 7 | 0x08060000 - 0x0807FFFF | 128 KiB | application code | Read Write
45
- ===========+=========================+============================+=============
46
- Sector 8 | 0x08080000 - 0x0809FFFF | 128 KiB | application code | Read Write
47
- Sector 9 | 0x080A0000 - 0x080BFFFF | 128 KiB | application code | Read Write
48
- Sector 10 | 0x080C0000 - 0x080DFFFF | 128 KiB | application code | Read Write
49
- Sector 11 | 0x080E0000 - 0x080FFFFF | 128 KiB | application code | Read Write
35
+ name | range | size | function | MPU Protection
36
+ -----------+-------------------------+---------+------------------+----------------------
37
+ Sector 0 | 0x08000000 - 0x08003FFF | 16 KiB | bootstrap code | signature dependent
38
+ Sector 1 | 0x08004000 - 0x08007FFF | 16 KiB | storage/config | full access
39
+ -----------+-------------------------+---------+------------------+----------------------
40
+ Sector 2 | 0x08008000 - 0x0800BFFF | 16 KiB | storage/config | full access
41
+ Sector 3 | 0x0800C000 - 0x0800FFFF | 16 KiB | storage/config | full access
42
+ -----------+-------------------------+---------+------------------+----------------------
43
+ Sector 4 | 0x08010000 - 0x0801FFFF | 64 KiB | empty | full access
44
+ Sector 5 | 0x08020000 - 0x0803FFFF | 128 KiB | bootloader code | signature dependent
45
+ Sector 6 | 0x08040000 - 0x0805FFFF | 128 KiB | bootloader code | signature dependent
46
+ Sector 7 | 0x08060000 - 0x0807FFFF | 128 KiB | application code | full access
47
+ ===========+=========================+============================+======================
48
+ Sector 8 | 0x08080000 - 0x0809FFFF | 128 KiB | application code | full access
49
+ Sector 9 | 0x080A0000 - 0x080BFFFF | 128 KiB | application code | full access
50
+ Sector 10 | 0x080C0000 - 0x080DFFFF | 128 KiB | application code | full access
51
+ Sector 11 | 0x080E0000 - 0x080FFFFF | 128 KiB | application code | full access
50
52
51
53
Application metadata area:
52
54
-------------------------
68
70
69
71
*/
70
72
73
+ /* === Defines ============================================================= */
74
+
75
+
76
+
71
77
#ifdef EMULATOR
72
78
extern uint8_t * emulator_flash_base ;
73
79
#define FLASH_PTR (x ) (emulator_flash_base + (x - FLASH_ORIGIN))
@@ -92,6 +98,10 @@ extern uint8_t *emulator_flash_base;
92
98
#define BLDR_FLASH_SECT_LEN 0x20000
93
99
#define APP_FLASH_SECT_LEN 0x20000
94
100
101
+ #define BSTRP_FLASH_SECT_START 0x08000000
102
+ #define BLDR_FLASH_SECT_START 0x08020000
103
+
104
+
95
105
/* meta info */
96
106
#define META_MAGIC_STR "KPKY"
97
107
@@ -130,16 +140,19 @@ extern uint8_t *emulator_flash_base;
130
140
#define FLASH_META_SIG2 (FLASH_META_SIG1 + sizeof(((app_meta_td *)NULL)->sig1))
131
141
#define FLASH_META_SIG3 (FLASH_META_SIG2 + sizeof(((app_meta_td *)NULL)->sig2))
132
142
143
+
133
144
#define META_MAGIC_SIZE (sizeof(((app_meta_td *)NULL)->magic))
134
145
135
- #define FLASH_APP_START (FLASH_META_START + FLASH_META_DESC_LEN) //0x0806_0100 - 0x080F_FFFF
146
+ #define FLASH_APP_START (FLASH_META_START + FLASH_META_DESC_LEN) //0x0806_0200 - 0x080F_FFFF
136
147
#define FLASH_APP_LEN (FLASH_END - FLASH_APP_START)
137
148
138
149
#define SIG_FLAG (*( uint8_t const *)FLASH_META_FLAGS)
139
150
140
151
/* Misc Info. */
141
- #define FLASH_BOOTSTRAP_SECTOR_FIRST 0
142
- #define FLASH_BOOTSTRAP_SECTOR_LAST 0
152
+ #define FLASH_BOOTSTRAP_SECTOR 0
153
+
154
+ #define FLASH_BOOTSTRAP_SECTOR_FIRST 0
155
+ #define FLASH_BOOTSTRAP_SECTOR_LAST 0
143
156
144
157
#define FLASH_STORAGE_SECTOR_FIRST 1
145
158
#define FLASH_STORAGE_SECTOR_LAST 3
@@ -209,6 +222,8 @@ static const FlashSector flash_sector_map[] =
209
222
{ -1 , 0 , 0 , FLASH_INVALID }
210
223
};
211
224
225
+ void mpu_config (int );
226
+
212
227
void memory_protect (void );
213
228
214
229
/// Enable writing. This exercises a bug in the STM32F2 that allows writing to
@@ -228,4 +243,11 @@ const char *memory_firmware_hash_str(char digest[SHA256_DIGEST_STRING_LENGTH]);
228
243
int memory_storage_hash (uint8_t * hash , Allocation storage_location );
229
244
bool find_active_storage (Allocation * storage_location );
230
245
246
+
247
+ extern void * _timerusr_isr ;
248
+ extern void * _buttonusr_isr ;
249
+ extern void * _mmhusr_isr ;
250
+
251
+
252
+
231
253
#endif
0 commit comments