2019-07-24 06:07:06 +08:00
|
|
|
// Early bringup
|
2021-06-19 05:24:15 +08:00
|
|
|
#define ENTER_BOOTLOADER_MAGIC 0xdeadbeefU
|
|
|
|
#define ENTER_SOFTLOADER_MAGIC 0xdeadc0deU
|
|
|
|
#define BOOT_NORMAL 0xdeadb111U
|
2017-07-23 05:18:00 +08:00
|
|
|
|
|
|
|
extern void *g_pfnVectors;
|
|
|
|
extern uint32_t enter_bootloader_mode;
|
|
|
|
|
2019-06-25 01:25:30 +08:00
|
|
|
void jump_to_bootloader(void) {
|
2017-07-23 05:18:00 +08:00
|
|
|
// do enter bootloader
|
2017-07-28 05:29:07 +08:00
|
|
|
enter_bootloader_mode = 0;
|
2021-07-03 09:25:35 +08:00
|
|
|
void (*bootloader)(void) = (void (*)(void)) (*((uint32_t *)BOOTLOADER_ADDRESS));
|
2017-07-23 05:18:00 +08:00
|
|
|
|
|
|
|
// jump to bootloader
|
2021-04-22 17:24:03 +08:00
|
|
|
enable_interrupts();
|
2017-07-23 05:18:00 +08:00
|
|
|
bootloader();
|
|
|
|
|
2017-07-28 05:29:07 +08:00
|
|
|
// reset on exit
|
|
|
|
enter_bootloader_mode = BOOT_NORMAL;
|
|
|
|
NVIC_SystemReset();
|
2017-07-23 05:18:00 +08:00
|
|
|
}
|
|
|
|
|
2021-07-03 09:25:35 +08:00
|
|
|
void early_initialization(void) {
|
2019-08-29 03:53:51 +08:00
|
|
|
// Reset global critical depth
|
2021-04-22 17:24:03 +08:00
|
|
|
disable_interrupts();
|
2019-08-29 03:53:51 +08:00
|
|
|
global_critical_depth = 0;
|
|
|
|
|
2019-12-06 06:19:29 +08:00
|
|
|
// Init register and interrupt tables
|
|
|
|
init_registers();
|
|
|
|
|
2017-07-23 05:18:00 +08:00
|
|
|
// after it's been in the bootloader, things are initted differently, so we reset
|
2019-06-27 07:16:35 +08:00
|
|
|
if ((enter_bootloader_mode != BOOT_NORMAL) &&
|
|
|
|
(enter_bootloader_mode != ENTER_BOOTLOADER_MAGIC) &&
|
|
|
|
(enter_bootloader_mode != ENTER_SOFTLOADER_MAGIC)) {
|
2017-07-28 05:29:07 +08:00
|
|
|
enter_bootloader_mode = BOOT_NORMAL;
|
2017-07-23 05:18:00 +08:00
|
|
|
NVIC_SystemReset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if wrong chip, reboot
|
|
|
|
volatile unsigned int id = DBGMCU->IDCODE;
|
2021-12-02 12:28:31 +08:00
|
|
|
if ((id & 0xFFFU) != MCU_IDCODE) {
|
|
|
|
enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
|
|
|
|
}
|
2017-07-23 05:18:00 +08:00
|
|
|
|
|
|
|
// setup interrupt table
|
|
|
|
SCB->VTOR = (uint32_t)&g_pfnVectors;
|
|
|
|
|
|
|
|
// early GPIOs float everything
|
2021-07-03 09:25:35 +08:00
|
|
|
early_gpio_float();
|
2017-07-23 05:18:00 +08:00
|
|
|
|
2019-07-24 06:07:06 +08:00
|
|
|
detect_board_type();
|
2017-07-23 05:18:00 +08:00
|
|
|
|
|
|
|
if (enter_bootloader_mode == ENTER_BOOTLOADER_MAGIC) {
|
2023-08-07 03:29:54 +08:00
|
|
|
#ifdef PANDA
|
|
|
|
current_board->init_bootloader();
|
|
|
|
#endif
|
2019-07-24 06:07:06 +08:00
|
|
|
current_board->set_led(LED_GREEN, 1);
|
2017-07-23 05:18:00 +08:00
|
|
|
jump_to_bootloader();
|
|
|
|
}
|
2020-08-27 06:37:50 +08:00
|
|
|
}
|