forked from dmitrystu/sboot_stm32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.h
295 lines (253 loc) · 9.54 KB
/
config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/* This file is the part of the STM32 secure bootloader
*
* Copyright ©2016 Dmitry Filimonchuk <dmitrystu[at]gmail[dot]com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _DFU_BOOTLOADER_H_
#define _DFU_BOOTLOADER_H_
/* Internal variables. Do not touch this section */
#define _AUTO -1 /* set automatically */
#define _DISABLE 0 /* disable feature */
#define _ENABLE 1 /* enable feature */
#define _LOW 2
#define _HIGH 3
/** DFU cipher definitions. */
#define DFU_CIPHER_ARC4 10 /* ARCFOUR (Rivest RC-4) stream cipher */
#define DFU_CIPHER_CHACHA 11 /* RFC7539-CHACHA20 stream cipher */
#define DFU_CIPHER_CHACHA_A 12 /* RFC7539-CHACHA20 stream cipher (ASM) */
#define DFU_CIPHER_GOST 13 /* GOST R 34.12-2015 "MAGMA" block cipher */
#define DFU_CIPHER_RAIDEN 14 /* RAIDEN block cipher */
#define DFU_CIPHER_RC5 15 /* Rivest RC5-32/12/128 clock cipher */
#define DFU_CIPHER_RC5_A 16 /* Rivest RC5-32/12/128 clock cipher (ASM) */
#define DFU_CIPHER_SPECK 17 /* SPECK 64/128 block cipher */
#define DFU_CIPHER_XTEA 18 /* XTEA block cipher */
#define DFU_CIPHER_XTEA1 19 /* XTEA-1 block cipher */
#define DFU_CIPHER_BLOWFISH 20 /* Blowfish block cipher */
#define DFU_CIPHER_RTEA 21 /* Ruptor's TEA or Repaired TEA */
#define DFU_CIPHER_RC6 22 /* Rivest RC6-32/20/128 block cipher */
#define DFU_CIPHER_RC6_A 23 /* Rivest RC6-32/20/128 block cipher (ASM)*/
#define DFU_CIPHER_RIJNDAEL 24 /* Rinjdael AES-128 block cipher */
#define DFU_CIPHER_MAGMA 25 /* GOST R 34.12-2015 "MAGMA" (Endianess fixed) block cipher */
/** Modes for using with block cipher */
#define DFU_CIPHER_ECB 0 /* Electronic Codebook (ECB) */
#define DFU_CIPHER_CBC 1 /* Cipher Block Chaining (CBC) */
#define DFU_CIPHER_PCBC 2 /* Propagating Cipher Block Chaining (PCBC) */
#define DFU_CIPHER_CFB 3 /* Cipher Feedback (CFB) */
#define DFU_CIPHER_OFB 4 /* Output Feedback (OFB) */
#define DFU_CIPHER_CTR 5 /* Counter (CTR) */
/** Checksum definitions. */
#define CRC32FAST 1 /* Lookup table based crc32 algorithm, consumes 1Kb of RAM for the table */
#define CRC32SMALL 2 /* Permutation based crc32 algorithm, no lookup table required but slower */
#define FNV1A32 3 /* Fowler–Noll–Vo 32 bit Hash */
#define FNV1A64 4 /* Fowler–Noll–Vo 64 bit Hash */
#define CRC64FAST 5 /* Lookup table based crc64 algorithm, consumes 2Kb of RAM for the table */
#define CRC64SMALL 6 /* Permutation based crc32 algorithm, no lookup table required but extremly slow */
#define __STR(x) #x
#define STR(x) __STR(x)
#ifdef DFU_USER_CONFIG
#include STR(DFU_USER_CONFIG)
#endif
/* DEFAULT CONFIG STARTS HERE */
/* Skip unwanted dfuDNLOAD_SYNC phase. Slightly improve speed, but don't meets DFU1.1 state diagram */
#ifndef DFU_DNLOAD_NOSYNC
#define DFU_DNLOAD_NOSYNC _ENABLE
#endif
/** Add extra DFU interface for EEPROM */
#ifndef DFU_INTF_EEPROM
#define DFU_INTF_EEPROM _AUTO
#endif
/** Firmware can be uploaded from device */
#ifndef DFU_CAN_UPLOAD
#define DFU_CAN_UPLOAD _ENABLE
#endif
/** Handle DFU_DETACH request in DFU mode. System reset will be issued. */
#ifndef DFU_DETACH
#define DFU_DETACH _ENABLE
#endif
/** Whether application image is checked by its vector table */
#ifndef DFU_VERIFY_VTABLE
#define DFU_VERIFY_VTABLE _ENABLE
#endif
/** Whether application image is verified by a checksum algorithm */
#ifndef DFU_VERIFY_CHECKSUM
#define DFU_VERIFY_CHECKSUM _DISABLE
#endif
/** Memory Readout Protection level **/
#ifndef DFU_SEAL_LEVEL
#define DFU_SEAL_LEVEL 0
#endif
/* USB VID */
#ifndef DFU_VENDOR_ID
#define DFU_VENDOR_ID 0x0483
#endif
/* USB PID */
#ifndef DFU_DEVICE_ID
#define DFU_DEVICE_ID 0xDF11
#endif
/* USB manufacturer string */
#ifndef DFU_STR_MANUF
#define DFU_STR_MANUF "Your company name"
#endif
/* USB product sting */
#ifndef DFU_STR_PRODUCT
#define DFU_STR_PRODUCT "Secure bootloader"
#endif
/* USB string for DFU configuration string descriptor. */
#ifndef DFU_DSC_CONFIG
#define DFU_DSC_CONFIG _ENABLE
#endif
#ifndef DFU_STR_CONFIG
#define DFU_STR_CONFIG "DFU"
#endif
/* USB string for DFU flash interface string descriptor. */
#ifndef DFU_DSC_FLASH
#define DFU_DSC_FLASH _ENABLE
#endif
#ifndef DFU_STR_FLASH
#define DFU_STR_FLASH "Internal flash"
//#define DFU_STR_FLASH "@Internal Flash/0x08000000/04*016Kg,01*064Kg,03*128Kg"
#endif
/* USB string for DFU EEPROM interface sreing descriptor */
#ifndef DFU_DSC_EEPROM
#define DFU_DSC_EEPROM _ENABLE
#endif
#ifndef DFU_STR_EEPROM
#define DFU_STR_EEPROM "Internal EEPROM"
#endif
/* USB EP0 size. Must be 8 for USB FS */
#define DFU_EP0_SIZE 8
/* DFU properties */
#ifndef DFU_POLL_TIMEOUT
#define DFU_POLL_TIMEOUT 20
#endif
#ifndef DFU_DETACH_TIMEOUT
#define DFU_DETACH_TIMEOUT 200
#endif
#ifndef DFU_BLOCKSZ
#define DFU_BLOCKSZ 0x800
#endif
/** Whether the RTC register is checked to enforce bootloader or user application mode */
#ifndef DFU_CHECK_RTC_MAGIC_NUMBER
#define DFU_CHECK_RTC_MAGIC_NUMBER _ENABLE
#endif
#ifndef RTC_MAGIC_NUMBER_BOOTLOADER
#define RTC_MAGIC_NUMBER_BOOTLOADER 0x424c
#endif
#ifndef RTC_MAGIC_NUMBER_USERAPP
#define RTC_MAGIC_NUMBER_USERAPP 0x424d
#endif
/* 32 bit DFU bootkey value */
#ifndef DFU_BOOTKEY
#define DFU_BOOTKEY 0x157F32D4
#endif
/* DFU bootkey address. Top of the ram by default. _AUTO, _DISABLE or set address.
* May be enabled internally. */
#ifndef DFU_BOOTKEY_ADDR
#define DFU_BOOTKEY_ADDR _AUTO
#endif
/* DFU bootstrap port/pin settings. Set GPIOx or _DISABLE */
#ifndef DFU_BOOTSTRAP_GPIO
#define DFU_BOOTSTRAP_GPIO GPIOA
#endif
#ifndef DFU_BOOTSTRAP_PIN
#define DFU_BOOTSTRAP_PIN 0
#endif
/* Active bootstrap pin logic level. _HIGH, _LOW */
#ifndef DFU_BOOTSTRAP_LEVEL
#define DFU_BOOTSTRAP_LEVEL _LOW
#endif
/* Pullup or pulldown settings for the bootstrap pin _AUTO, _DISABLE, _HIGH, _LOW */
#ifndef DFU_BOOTSTRAP_PULL
#define DFU_BOOTSTRAP_PULL _AUTO
#endif
/* Double reset waiting time in mS. _DISABLE or time in mS */
#ifndef DFU_DBLRESET_MS
#define DFU_DBLRESET_MS 300
#endif
/* DFU bootstrap port/pin settings. Set GPIOx or _DISABLE */
#ifndef DFU_LED_GPIO
#define DFU_LED_GPIO GPIOC
#endif
#ifndef DFU_LED_RCC
#define DFU_LED_RCC 0x004 // (0x1UL << 'x'-'A') => A=0x001, B=0x002, C=0x004 etc
#endif
#ifndef DFU_LED_PIN
#define DFU_LED_PIN 13
#endif
#ifndef DFU_LED_ON_LEVEL
#define DFU_LED_ON_LEVEL _LOW
#endif
/* Exit the bootloader into the user application after this many "time units" */
/* (0 = never, 1 = instantly/fastboot, 6 = 0.5s/minimum, 680 = 60s, ...32bit) */
#ifndef DFU_TIMEOUT_DEFAULT
#define DFU_TIMEOUT_DEFAULT 6 // = 0.5s: use dfu-util -w
#endif
#ifndef DFU_TIMEOUT_RTC_MAGIC
#define DFU_TIMEOUT_RTC_MAGIC 35 // = 3s
#endif
#ifndef DFU_TIMEOUT_UPDOWNLOAD
#define DFU_TIMEOUT_UPDOWNLOAD 680 // = 60s
#endif
/* Skip entering the bootloader after download even when fastboot is disabled */
#ifndef DFU_SKIP_BOOTLOADER_AFTER_DOWNLOAD
#define DFU_SKIP_BOOTLOADER_AFTER_DOWNLOAD _DISABLE
#endif
/* User application address. _AUTO or page aligned address.
* for _AUTO check __app_start address in output linker map file*/
#ifndef DFU_APP_START
#define DFU_APP_START _AUTO
#endif
/* User application size. _AUTO or required size in bytes. */
#ifndef DFU_APP_SIZE
#define DFU_APP_SIZE _AUTO
#endif
/* Microsoft WCID allows automatic driver (WinUSB) installation on device
* connection. Use _ENABLE to make your device likeable by Windows. */
#ifndef DFU_WCID
#define DFU_WCID _DISABLE
#endif
/* Cipher to use. set _DISABLE or choose from implemented ciphers */
#ifndef DFU_CIPHER
#define DFU_CIPHER DFU_CIPHER_RC5
#endif
#ifndef DFU_CIPHER_MODE
#define DFU_CIPHER_MODE DFU_CIPHER_CBC
#endif
/** DFU secure key. */
#define DFU_AES_KEY_A 0x2D, 0x4D, 0x61, 0x6B, 0x65, 0x4C, 0x6F, 0x76, \
0x65, 0x4E, 0x6F, 0x74, 0x57, 0x61, 0x72, 0x2D
#define DFU_AES_KEY_B 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
#ifndef DFU_AES_KEY_128
#define DFU_AES_KEY_128 DFU_AES_KEY_A
#endif
#ifndef DFU_AES_KEY_192
#define DFU_AES_KEY_192 0x2D, 0x4D, 0x61, 0x6B, 0x65, 0x4C, 0x6F, 0x76, \
0x65, 0x4E, 0x6F, 0x74, 0x57, 0x61, 0x72, 0x2D, \
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
#endif
#ifndef DFU_AES_KEY_256
#define DFU_AES_KEY_256 DFU_AES_KEY_A, DFU_AES_KEY_B
#endif
/** cipher initialization vector for block cipher and CHACHA */
#ifndef DFU_AES_IV_64
#define DFU_AES_IV_64 0x44, 0x33, 0x22, 0x11, 0x88, 0x77, 0x66, 0x55
#endif
#ifndef DFU_AES_IV_96
#define DFU_AES_IV_96 0x44, 0x33, 0x22, 0x11, 0x88, 0x77, 0x66, 0x55, \
0xCC, 0xBB, 0xAA, 0x99
#endif
#ifndef DFU_AES_IV_128
#define DFU_AES_IV_128 0x44, 0x33, 0x22, 0x11, 0x88, 0x77, 0x66, 0x55,\
0xCC, 0xBB, 0xAA, 0x99, 0x44, 0x33, 0x22, 0x11
#endif
#endif // _DFU_BOOTLOADER_H_