Files
panda-meb/board/bootstub.c

86 lines
1.9 KiB
C
Raw Normal View History

#define VERS_TAG 0x53524556
#define MIN_VERSION 2
// ********************* Includes *********************
#include "board/config.h"
2017-04-06 18:11:36 -07:00
#include "board/drivers/led.h"
#include "board/drivers/pwm.h"
#include "board/drivers/usb.h"
#include "board/early_init.h"
#include "board/provision.h"
2017-07-29 18:16:08 -07:00
2017-04-25 18:03:58 -07:00
#include "crypto/rsa.h"
#include "crypto/sha.h"
#include "board/obj/cert.h"
#include "board/obj/gitversion.h"
#include "board/flasher.h"
2017-04-27 20:32:16 -07:00
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
2019-07-07 15:05:47 -07:00
void __initialize_hardware_early(void) {
early_initialization();
2017-04-06 18:11:36 -07:00
}
2019-07-07 15:05:47 -07:00
void fail(void) {
2017-07-24 15:16:22 -07:00
soft_flasher_start();
2017-04-25 18:03:58 -07:00
}
2017-07-22 14:28:11 -07:00
// know where to sig check
extern void *_app_start[];
2019-07-07 15:05:47 -07:00
int main(void) {
// Init interrupt table
init_interrupts(true);
disable_interrupts();
2017-04-17 13:57:34 -07:00
clock_init();
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 15:07:06 -07:00
detect_board_type();
#ifdef PANDA_JUNGLE
current_board->set_panda_power(true);
#endif
2017-07-24 15:16:22 -07:00
if (enter_bootloader_mode == ENTER_SOFTLOADER_MAGIC) {
enter_bootloader_mode = 0;
soft_flasher_start();
}
2017-04-25 18:03:58 -07:00
// validate length
2017-05-01 22:59:10 -07:00
int len = (int)_app_start[0];
2017-07-27 15:54:55 -07:00
if ((len < 8) || (len > (0x1000000 - 0x4000 - 4 - RSANUMBYTES))) goto fail;
2017-04-25 18:03:58 -07:00
// compute SHA hash
2017-05-01 22:59:10 -07:00
uint8_t digest[SHA_DIGEST_SIZE];
2017-04-26 10:41:57 -07:00
SHA_hash(&_app_start[1], len-4, digest);
2017-04-25 18:03:58 -07:00
// verify version, last bytes in the signed area
uint32_t vers[2] = {0};
memcpy(&vers, ((void*)&_app_start[0]) + len - sizeof(vers), sizeof(vers));
if (vers[0] != VERS_TAG || vers[1] < MIN_VERSION) {
goto fail;
}
2017-04-25 18:03:58 -07:00
// verify RSA signature
2017-04-28 15:06:01 -07:00
if (RSA_verify(&release_rsa_key, ((void*)&_app_start[0]) + len, RSANUMBYTES, digest, SHA_DIGEST_SIZE)) {
goto good;
2017-04-26 10:41:57 -07:00
}
2017-04-17 13:57:34 -07:00
2017-04-28 20:13:00 -07:00
// 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;
2017-04-28 15:06:01 -07:00
}
2017-04-28 20:13:00 -07:00
#endif
2017-04-28 15:06:01 -07:00
// here is a failure
2017-07-27 15:54:55 -07:00
fail:
2017-04-28 15:06:01 -07:00
fail();
2017-07-27 15:54:55 -07:00
return 0;
2017-04-28 15:06:01 -07:00
good:
2017-04-17 13:57:34 -07:00
// jump to flash
2019-07-07 15:05:47 -07:00
((void(*)(void)) _app_start[1])();
2017-04-06 18:11:36 -07:00
return 0;
}