Files
dragonpilot/board/bootstub.c
Vehicle Researcher d21c6591c1 Squashed 'panda/' changes from 293fa33..9ee6285
9ee6285 optimize board build for size to avoid going over the limit. (#150)
20e8fa9 Start introducing Bounties
a2046e9 make it smaller
1dfcf2b update panda price
37ee289 chrysler safety: fixed comments
c2dfbad tesla safety: return -1 to block forward (#149)
74c0c1b update README
be0061d Chrysler: safety now based on motor torque
039d183 Chrysler: fixed regression test
9193eeb Chrysler: safety limits updated
04f1d44 Chrysler safety: 3 sa max rate down for now
cf3ecd6 Chrysler safety: re-using hyundai framework
49ed9bc Update CLICKS for longer bootup time of EONS and avoid unwanted fast charge mode

git-subtree-dir: panda
git-subtree-split: 9ee628557f3f33759c62b567964b918a597d3387
2019-01-23 15:28:16 -08:00

101 lines
1.9 KiB
C

#define BOOTSTUB
#include "config.h"
#include "obj/gitversion.h"
#ifdef STM32F4
#define PANDA
#include "stm32f4xx.h"
#include "stm32f4xx_hal_gpio_ex.h"
#else
#include "stm32f2xx.h"
#include "stm32f2xx_hal_gpio_ex.h"
#endif
#include "libc.h"
#include "provision.h"
#include "drivers/drivers.h"
#include "drivers/llgpio.h"
#include "gpio.h"
#include "drivers/spi.h"
#include "drivers/usb.h"
//#include "drivers/uart.h"
#ifdef PEDAL
#define CUSTOM_CAN_INTERRUPTS
#include "safety.h"
#include "drivers/can.h"
#endif
int puts(const char *a) { return 0; }
void puth(unsigned int i) {}
#include "crypto/rsa.h"
#include "crypto/sha.h"
#include "obj/cert.h"
#include "spi_flasher.h"
void __initialize_hardware_early() {
early();
}
void fail() {
soft_flasher_start();
}
// know where to sig check
extern void *_app_start[];
// FIXME: sometimes your panda will fail flashing and will quickly blink a single Green LED
// BOUNTY: $200 coupon on shop.comma.ai or $100 check.
int main() {
__disable_irq();
clock_init();
detect();
if (revision == PANDA_REV_C) {
set_usb_power_mode(USB_POWER_CLIENT);
}
if (enter_bootloader_mode == ENTER_SOFTLOADER_MAGIC) {
enter_bootloader_mode = 0;
soft_flasher_start();
}
// validate length
int len = (int)_app_start[0];
if ((len < 8) || (len > (0x1000000 - 0x4000 - 4 - RSANUMBYTES))) goto fail;
// compute SHA hash
uint8_t digest[SHA_DIGEST_SIZE];
SHA_hash(&_app_start[1], len-4, digest);
// verify RSA signature
if (RSA_verify(&release_rsa_key, ((void*)&_app_start[0]) + len, RSANUMBYTES, digest, SHA_DIGEST_SIZE)) {
goto good;
}
// allow debug if built from source
#ifdef ALLOW_DEBUG
if (RSA_verify(&debug_rsa_key, ((void*)&_app_start[0]) + len, RSANUMBYTES, digest, SHA_DIGEST_SIZE)) {
goto good;
}
#endif
// here is a failure
fail:
fail();
return 0;
good:
// jump to flash
((void(*)()) _app_start[1])();
return 0;
}