Skip to content

Commit 954c934

Browse files
authored
Merge pull request #43 from pennam/skip_sig_check
Directly jump into sketch if MCUBoot keys are not configured
2 parents ba87573 + b5f4ad5 commit 954c934

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

envie/target_init.cpp

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,38 @@ static inline void LED_pulse(DigitalOut* led)
108108
}
109109
}
110110

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+
111143

112144
int target_init(void) {
113145
DigitalIn boot_sel(PI_8,PullDown);
@@ -213,17 +245,14 @@ int target_init(void) {
213245

214246
HAL_Delay(10);
215247

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) {
225249
RTCSetBKPRegister(RTC_BKP_DR0, 0);
226250
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+
}
227256
BOOT_LOG_DBG("Envie app magic 0x%x", RTCGetBKPRegister(RTC_BKP_DR0));
228257
swap_ticker.attach(&swap_feedback, 250ms);
229258
return 0;

0 commit comments

Comments
 (0)