panda/board/bootstub.c

46 lines
750 B
C
Raw Normal View History

2017-04-06 19:11:36 -06:00
#ifdef STM32F4
#define PANDA
#include "stm32f4xx.h"
#else
#include "stm32f2xx.h"
#endif
#include "early.h"
#include "libc.h"
2017-04-06 19:11:36 -06:00
2017-04-25 19:03:58 -06:00
#include "crypto/rsa.h"
#include "crypto/sha.h"
#include "obj/cert.h"
2017-04-06 19:11:36 -06:00
void __initialize_hardware_early() {
early();
}
2017-04-25 19:03:58 -06:00
void fail() {
enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
NVIC_SystemReset();
}
2017-04-06 19:11:36 -06:00
int main() {
2017-04-17 14:57:34 -06:00
clock_init();
2017-04-25 19:03:58 -06:00
// validate length
int len = _app_start[0];
if (len < 4) fail();
// compute SHA hash
char digest[SHA_DIGEST_SIZE];
SHA_hash(&_app_start[1], len, digest);
// verify RSA signature
/*if (!RSA_verify(&rsa_key, ((void*)&_app_start[1]) + len, 0x80, digest, SHA_DIGEST_SIZE)) {
fail();
}*/
2017-04-17 14:57:34 -06:00
// jump to flash
((void(*)()) _app_start[1])();
2017-04-06 19:11:36 -06:00
return 0;
}