From fbf87e05127b65b5140469345fd128d66c3d281f Mon Sep 17 00:00:00 2001 From: Bruce Wayne Date: Sat, 5 Aug 2023 15:14:29 -0700 Subject: [PATCH] init bootloader --- board/boards/black.h | 9 ++++++++- board/boards/board_declarations.h | 2 ++ board/boards/dos.h | 1 + board/boards/grey.h | 11 ++--------- board/boards/pedal.h | 1 + board/boards/red.h | 1 + board/boards/red_v2.h | 1 + board/boards/tres.h | 1 + board/boards/uno.h | 8 ++++++++ board/boards/unused_funcs.h | 3 +++ board/boards/white.h | 17 ++++++++++------- board/early_init.h | 3 +++ 12 files changed, 41 insertions(+), 17 deletions(-) diff --git a/board/boards/black.h b/board/boards/black.h index 486e0e29f75..d6e6bec8e1f 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -99,8 +99,8 @@ void black_init(void) { set_gpio_mode(GPIOC, 3, MODE_ANALOG); // GPS OFF - set_gpio_output(GPIOC, 12, 0); set_gpio_output(GPIOC, 5, 0); + set_gpio_output(GPIOC, 12, 0); // C10: OBD_SBU1_RELAY (harness relay driving output) // C11: OBD_SBU2_RELAY (harness relay driving output) @@ -137,6 +137,12 @@ void black_init(void) { } } +void black_init_bootloader(void) { + // GPS OFF + set_gpio_output(GPIOC, 5, 0); + set_gpio_output(GPIOC, 12, 0); +} + const harness_configuration black_harness_config = { .has_harness = true, .GPIO_SBU1 = GPIOC, @@ -166,6 +172,7 @@ const board board_black = { .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, .init = black_init, + .init_bootloader = black_init_bootloader, .enable_can_transceiver = black_enable_can_transceiver, .enable_can_transceivers = black_enable_can_transceivers, .set_led = black_set_led, diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index 6a13f9d4f55..e8b1cdcffa5 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -1,5 +1,6 @@ // ******************** Prototypes ******************** typedef void (*board_init)(void); +typedef void (*board_init_bootloader)(void); typedef void (*board_enable_can_transceiver)(uint8_t transceiver, bool enabled); typedef void (*board_enable_can_transceivers)(bool enabled); typedef void (*board_set_led)(uint8_t color, bool enabled); @@ -27,6 +28,7 @@ struct board { const bool fan_stall_recovery; const uint8_t fan_enable_cooldown_time; board_init init; + board_init_bootloader init_bootloader; board_enable_can_transceiver enable_can_transceiver; board_enable_can_transceivers enable_can_transceivers; board_set_led set_led; diff --git a/board/boards/dos.h b/board/boards/dos.h index 616c6ca0466..a5c2e4bcea3 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -221,6 +221,7 @@ const board board_dos = { .fan_stall_recovery = true, .fan_enable_cooldown_time = 3U, .init = dos_init, + .init_bootloader = unused_init_bootloader, .enable_can_transceiver = dos_enable_can_transceiver, .enable_can_transceivers = dos_enable_can_transceivers, .set_led = dos_set_led, diff --git a/board/boards/grey.h b/board/boards/grey.h index 89f67d0dcbc..a74f894480c 100644 --- a/board/boards/grey.h +++ b/board/boards/grey.h @@ -4,14 +4,6 @@ // Most hardware functionality is similar to white panda -void grey_init(void) { - white_grey_common_init(); - - // GPS off - set_gpio_output(GPIOC, 14, 0); - set_gpio_output(GPIOC, 5, 0); -} - const board board_grey = { .board_type = "Grey", .board_tick = unused_board_tick, @@ -26,7 +18,8 @@ const board board_grey = { .avdd_mV = 3300U, .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, - .init = grey_init, + .init = white_grey_init, + .init_bootloader = white_grey_init_bootloader, .enable_can_transceiver = white_enable_can_transceiver, .enable_can_transceivers = white_enable_can_transceivers, .set_led = white_set_led, diff --git a/board/boards/pedal.h b/board/boards/pedal.h index 17dc1712f99..f2ae367e5d6 100644 --- a/board/boards/pedal.h +++ b/board/boards/pedal.h @@ -81,6 +81,7 @@ const board board_pedal = { .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, .init = pedal_init, + .init_bootloader = unused_init_bootloader, .enable_can_transceiver = pedal_enable_can_transceiver, .enable_can_transceivers = pedal_enable_can_transceivers, .set_led = pedal_set_led, diff --git a/board/boards/red.h b/board/boards/red.h index d64a61c2351..43e71bdf943 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -181,6 +181,7 @@ const board board_red = { .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, .init = red_init, + .init_bootloader = unused_init_bootloader, .enable_can_transceiver = red_enable_can_transceiver, .enable_can_transceivers = red_enable_can_transceivers, .set_led = red_set_led, diff --git a/board/boards/red_v2.h b/board/boards/red_v2.h index 8724a046c0d..4f0a2cb6229 100644 --- a/board/boards/red_v2.h +++ b/board/boards/red_v2.h @@ -25,6 +25,7 @@ const board board_red_v2 = { .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, .init = red_panda_v2_init, + .init_bootloader = unused_init_bootloader, .enable_can_transceiver = red_chiplet_enable_can_transceiver, .enable_can_transceivers = red_chiplet_enable_can_transceivers, .set_led = red_set_led, diff --git a/board/boards/tres.h b/board/boards/tres.h index 4b1520bebab..0b9b94a6820 100644 --- a/board/boards/tres.h +++ b/board/boards/tres.h @@ -100,6 +100,7 @@ const board board_tres = { .fan_stall_recovery = false, .fan_enable_cooldown_time = 3U, .init = tres_init, + .init_bootloader = unused_init_bootloader, .enable_can_transceiver = red_chiplet_enable_can_transceiver, .enable_can_transceivers = red_chiplet_enable_can_transceivers, .set_led = red_set_led, diff --git a/board/boards/uno.h b/board/boards/uno.h index b935335be42..e0dc0d2c5f3 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -197,6 +197,13 @@ void uno_init(void) { uno_bootkick(); } +void uno_init_bootloader(void) { + // GPS off + set_gpio_output(GPIOB, 1, 0); + set_gpio_output(GPIOC, 5, 0); + set_gpio_output(GPIOC, 12, 0); +} + const harness_configuration uno_harness_config = { .has_harness = true, .GPIO_SBU1 = GPIOC, @@ -226,6 +233,7 @@ const board board_uno = { .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, .init = uno_init, + .init_bootloader = uno_init_bootloader, .enable_can_transceiver = uno_enable_can_transceiver, .enable_can_transceivers = uno_enable_can_transceivers, .set_led = uno_set_led, diff --git a/board/boards/unused_funcs.h b/board/boards/unused_funcs.h index cf5a0baed63..24279d2bf97 100644 --- a/board/boards/unused_funcs.h +++ b/board/boards/unused_funcs.h @@ -1,3 +1,6 @@ +void unused_init_bootloader(void) { +} + void unused_set_ir_power(uint8_t percentage) { UNUSED(percentage); } diff --git a/board/boards/white.h b/board/boards/white.h index 75b62b88dbc..f2dedf01072 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -133,7 +133,7 @@ bool white_check_ignition(void){ return !get_gpio_input(GPIOA, 1); } -void white_grey_common_init(void) { +void white_grey_init(void) { common_init_gpio(); // C3: current sense @@ -205,14 +205,16 @@ void white_grey_common_init(void) { } else { white_set_usb_power_mode(USB_POWER_CLIENT); } -} - -void white_init(void) { - white_grey_common_init(); - // ESP OFF + // ESP/GPS off + set_gpio_output(GPIOC, 5, 0); set_gpio_output(GPIOC, 14, 0); +} + +void white_grey_init_bootloader(void) { + // ESP/GPS off set_gpio_output(GPIOC, 5, 0); + set_gpio_output(GPIOC, 14, 0); } const harness_configuration white_harness_config = { @@ -233,7 +235,8 @@ const board board_white = { .avdd_mV = 3300U, .fan_stall_recovery = false, .fan_enable_cooldown_time = 0U, - .init = white_init, + .init = white_grey_init, + .init_bootloader = white_grey_init_bootloader, .enable_can_transceiver = white_enable_can_transceiver, .enable_can_transceivers = white_enable_can_transceivers, .set_led = white_set_led, diff --git a/board/early_init.h b/board/early_init.h index cf1866e3574..ae652aebced 100644 --- a/board/early_init.h +++ b/board/early_init.h @@ -51,6 +51,9 @@ void early_initialization(void) { detect_board_type(); if (enter_bootloader_mode == ENTER_BOOTLOADER_MAGIC) { + #ifdef PANDA + current_board->init_bootloader(); + #endif current_board->set_led(LED_GREEN, 1); jump_to_bootloader(); }