@@ -108,6 +108,38 @@ static inline void LED_pulse(DigitalOut* led)
108
108
}
109
109
}
110
110
111
+ static bool valid_application () {
112
+ /* Test if user code is programmed starting from USBD_DFU_APP_DEFAULT_ADD
113
+ * address.
114
+ */
115
+ return (((*(__IO uint32_t *) 0x08040000 ) & 0xFF000000 ) == 0x20000000 ) \
116
+ || (((*(__IO uint32_t *) 0x08040000 ) & 0xFF000000 ) == 0x24000000 ) \
117
+ || (((*(__IO uint32_t *) 0x08040000 ) & 0xFF000000 ) == 0x30000000 ) \
118
+ || (((*(__IO uint32_t *) 0x08040000 ) & 0xFF000000 ) == 0x38000000 );
119
+
120
+ }
121
+
122
+
123
+ static bool empty_keys () {
124
+ unsigned int i;
125
+ extern const unsigned char enc_priv_key[];
126
+ extern const unsigned int enc_priv_key_len;
127
+ extern const unsigned char rsa_pub_key[];
128
+ extern unsigned int rsa_pub_key_len;
129
+
130
+ for (i = 0 ; i < enc_priv_key_len; i++) {
131
+ if (enc_priv_key[i] != 0xFF )
132
+ return false ;
133
+ }
134
+
135
+ for (i = 0 ; i < rsa_pub_key_len; i++) {
136
+ if (rsa_pub_key[i] != 0xFF )
137
+ return false ;
138
+ }
139
+
140
+ return true ;
141
+ }
142
+
111
143
112
144
int target_init (void ) {
113
145
DigitalIn boot_sel (PI_8,PullDown);
@@ -213,17 +245,14 @@ int target_init(void) {
213
245
214
246
HAL_Delay (10 );
215
247
216
- /* Test if user code is programmed starting from USBD_DFU_APP_DEFAULT_ADD
217
- * address. TODO check MCUBoot header instead.
218
- */
219
- // int app_valid = (((*(__IO uint32_t *) 0x08040000) & 0xFF000000) == 0x20000000)
220
- // || (((*(__IO uint32_t *) 0x08040000) & 0xFF000000) == 0x24000000)
221
- // || (((*(__IO uint32_t *) 0x08040000) & 0xFF000000) == 0x30000000)
222
- // || (((*(__IO uint32_t *) 0x08040000) & 0xFF000000) == 0x38000000);
223
-
224
- if (/* app_valid &&*/ magic != 0xDF59 /* && magic != 0x07AA*/ && boot_sel==0 ) {
248
+ if (magic != 0xDF59 && magic != 0x07AA && boot_sel==0 ) {
225
249
RTCSetBKPRegister (RTC_BKP_DR0, 0 );
226
250
HAL_FLASH_Lock ();
251
+ if (valid_application () && empty_keys ()) {
252
+ BOOT_LOG_INF (" MCUBoot not configured, but valid image found." );
253
+ BOOT_LOG_INF (" Booting firmware image at 0x%x\n " , USBD_DFU_APP_DEFAULT_ADD);
254
+ mbed_start_application (USBD_DFU_APP_DEFAULT_ADD);
255
+ }
227
256
BOOT_LOG_DBG (" Envie app magic 0x%x" , RTCGetBKPRegister (RTC_BKP_DR0));
228
257
swap_ticker.attach (&swap_feedback, 250ms);
229
258
return 0 ;
0 commit comments