Files
openpilot/panda/board/early_init.h
T

58 lines
1.5 KiB
C

// Early bringup
#define ENTER_BOOTLOADER_MAGIC 0xdeadbeefU
#define ENTER_SOFTLOADER_MAGIC 0xdeadc0deU
#define BOOT_NORMAL 0xdeadb111U
extern void *g_pfnVectors;
extern uint32_t enter_bootloader_mode;
typedef void (*bootloader_fcn)(void);
typedef bootloader_fcn *bootloader_fcn_ptr;
static void jump_to_bootloader(void) {
// do enter bootloader
enter_bootloader_mode = 0;
bootloader_fcn_ptr bootloader_ptr = (bootloader_fcn_ptr)BOOTLOADER_ADDRESS;
bootloader_fcn bootloader = *bootloader_ptr;
// jump to bootloader
enable_interrupts();
bootloader();
// reset on exit
enter_bootloader_mode = BOOT_NORMAL;
NVIC_SystemReset();
}
void early_initialization(void) {
// Reset global critical depth
disable_interrupts();
global_critical_depth = 0;
// Init register and interrupt tables
init_registers();
// Always clear any bootloader magic left in RAM. A stale value from a
// previous bootloader/DFU session would otherwise send us back into the ROM
// bootloader on a plain hardware reset (which then does not enumerate USB).
enter_bootloader_mode = BOOT_NORMAL;
// if wrong chip, reboot
volatile unsigned int id = DBGMCU->IDCODE;
if ((id & 0xFFFU) != MCU_IDCODE) {
enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
}
// setup interrupt table
SCB->VTOR = (uint32_t)&g_pfnVectors;
// early GPIOs float everything
early_gpio_float();
detect_board_type();
// Bootloader entry is done directly by the 0xd1 comms handler via
// jump_to_bootloader(), not through a magic RAM value (which can be stale).
}