diff --git a/boards/tfh/diamond_main/diamond_main.dts b/boards/tfh/diamond_main/diamond_main.dts index 216b6154..3979fabb 100644 --- a/boards/tfh/diamond_main/diamond_main.dts +++ b/boards/tfh/diamond_main/diamond_main.dts @@ -121,6 +121,9 @@ // for gpio based tachometer (coarse estimation) fan-main-tach-gpios = <&gpiod 7 GPIO_ACTIVE_HIGH>; + + // request security MCU reboot + exp-mcu-rst-rqst-gpios = <&gpio_exp1 11 GPIO_ACTIVE_HIGH>; }; buttons { diff --git a/main_board/src/cli/cli.c b/main_board/src/cli/cli.c index b96cc867..42841c1a 100644 --- a/main_board/src/cli/cli.c +++ b/main_board/src/cli/cli.c @@ -456,6 +456,20 @@ execute_date(const struct shell *sh, size_t argc, char **argv) } #ifdef CONFIG_BOARD_DIAMOND_MAIN +static int +execute_reboot_sec_mcu(const struct shell *sh, size_t argc, char **argv) +{ + UNUSED_PARAMETER(argc); + UNUSED_PARAMETER(argv); + + orb_mcu_main_JetsonToMcu message = { + .which_payload = orb_mcu_main_JetsonToMcu_reboot_security_mcu_tag, + }; + + shell_print(sh, "Requesting security MCU reboot"); + return runner_handle_new_cli(&message); +} + static int execute_white_leds(const struct shell *sh, size_t argc, char **argv) { @@ -825,6 +839,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( #ifdef CONFIG_BOARD_DIAMOND_MAIN SHELL_CMD(white_leds, NULL, "Control white LEDs", execute_white_leds), SHELL_CMD(polarizer, NULL, "Control polarizer wheel", execute_polarizer), + SHELL_CMD(reboot_sec, NULL, "Reboot security MCU", execute_reboot_sec_mcu), #endif SHELL_CMD(stats, NULL, "Show runner statistics", execute_runner_stats), SHELL_CMD(ping_sec, NULL, "Send ping to security MCU", execute_ping_sec), diff --git a/main_board/src/runner/runner.c b/main_board/src/runner/runner.c index 510ffadf..16ffec29 100644 --- a/main_board/src/runner/runner.c +++ b/main_board/src/runner/runner.c @@ -29,11 +29,15 @@ #include #include #include +#include #include #if defined(CONFIG_BOARD_DIAMOND_MAIN) #include "ui/rgb_leds/cone_leds/cone_leds.h" #include "ui/white_leds/white_leds.h" + +static const struct gpio_dt_spec exp_mcu_rst_rqst_gpio_spec = + GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), exp_mcu_rst_rqst_gpios); #endif #if defined(CONFIG_MEMFAULT_METRICS_CONNECTIVITY_CONNECTED_TIME) @@ -1168,6 +1172,48 @@ handle_power_cycle(job_t *job) } #ifdef CONFIG_BOARD_DIAMOND_MAIN +static void +handle_reboot_security_mcu(job_t *job) +{ + orb_mcu_main_JetsonToMcu *msg = &job->message.jetson_cmd; + MAKE_ASSERTS(orb_mcu_main_JetsonToMcu_reboot_security_mcu_tag); + + int ret; + + if (!gpio_is_ready_dt(&exp_mcu_rst_rqst_gpio_spec)) { + LOG_ERR("GPIO for security MCU reset request not ready"); + job_ack(orb_mcu_Ack_ErrorCode_FAIL, job); + return; + } + + ret = gpio_pin_configure_dt(&exp_mcu_rst_rqst_gpio_spec, + GPIO_OUTPUT_INACTIVE); + if (ret != 0) { + LOG_ERR("Failed to configure GPIO: %d", ret); + job_ack(orb_mcu_Ack_ErrorCode_FAIL, job); + return; + } + + ret = gpio_pin_set_dt(&exp_mcu_rst_rqst_gpio_spec, 1); + if (ret != 0) { + LOG_ERR("Failed to set GPIO high: %d", ret); + job_ack(orb_mcu_Ack_ErrorCode_FAIL, job); + return; + } + + k_msleep(100); + + ret = gpio_pin_set_dt(&exp_mcu_rst_rqst_gpio_spec, 0); + if (ret != 0) { + LOG_ERR("Failed to set GPIO low: %d", ret); + job_ack(orb_mcu_Ack_ErrorCode_FAIL, job); + return; + } + + LOG_INF("Security MCU reboot requested"); + job_ack(orb_mcu_Ack_ErrorCode_SUCCESS, job); +} + static void handle_polarizer(job_t *job) { @@ -1805,6 +1851,8 @@ static const hm_callback handle_message_callbacks[] = { [orb_mcu_main_JetsonToMcu_polarizer_tag] = handle_polarizer, [orb_mcu_main_JetsonToMcu_polarizer_wheel_settings_tag] = handle_polarizer_wheel_settings, + [orb_mcu_main_JetsonToMcu_reboot_security_mcu_tag] = + handle_reboot_security_mcu, #elif defined(CONFIG_BOARD_PEARL_MAIN) [orb_mcu_main_JetsonToMcu_cone_leds_sequence_tag] = handle_not_supported, [orb_mcu_main_JetsonToMcu_cone_leds_pattern_tag] = handle_not_supported, @@ -1814,7 +1862,7 @@ static const hm_callback handle_message_callbacks[] = { #endif }; -BUILD_ASSERT((ARRAY_SIZE(handle_message_callbacks) <= 56), +BUILD_ASSERT((ARRAY_SIZE(handle_message_callbacks) <= 57), "It seems like the `handle_message_callbacks` array is too large"); _Noreturn static void diff --git a/west.yml b/west.yml index af7df0b6..04d02d83 100644 --- a/west.yml +++ b/west.yml @@ -23,7 +23,7 @@ manifest: remote: memfault revision: 1.31.0 - name: orb-messages - revision: cac4f26ae09ca75ca2e2911376e5273be8454a52 + revision: 3644a0635cd3c8304536de1a166785ff46c8b63f path: modules/orb-messages/public - name: priv-orb-messages revision: 0da6bab271385e952813bfcbef9ce9bf38b0f27a