Skip to content

Commit 0797548

Browse files
fougeclaude
andcommitted
feat(diamond): add security MCU reboot request
Allow the Jetson or CLI to request a security MCU reboot by having the main MCU drive EXP_MCU_RST_RQST_3V3 GPIO high for 100ms. - Add exp-mcu-rst-rqst-gpios to diamond_main DTS (gpio_exp1 pin 11) - Add handle_reboot_security_mcu handler in runner.c - Add `orb reboot_sec` CLI command (Diamond only) Signed-off-by: Cyril Fougeray <cyril.fougeray@toolsforhumanity.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d985945 commit 0797548

4 files changed

Lines changed: 75 additions & 2 deletions

File tree

boards/tfh/diamond_main/diamond_main.dts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@
121121

122122
// for gpio based tachometer (coarse estimation)
123123
fan-main-tach-gpios = <&gpiod 7 GPIO_ACTIVE_HIGH>;
124+
125+
// request security MCU reboot
126+
exp-mcu-rst-rqst-gpios = <&gpio_exp1 11 GPIO_ACTIVE_HIGH>;
124127
};
125128

126129
buttons {

main_board/src/cli/cli.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,20 @@ execute_date(const struct shell *sh, size_t argc, char **argv)
457457
}
458458

459459
#ifdef CONFIG_BOARD_DIAMOND_MAIN
460+
static int
461+
execute_reboot_sec_mcu(const struct shell *sh, size_t argc, char **argv)
462+
{
463+
UNUSED_PARAMETER(argc);
464+
UNUSED_PARAMETER(argv);
465+
466+
orb_mcu_main_JetsonToMcu message = {
467+
.which_payload = orb_mcu_main_JetsonToMcu_reboot_security_mcu_tag,
468+
};
469+
470+
shell_print(sh, "Requesting security MCU reboot");
471+
return runner_handle_new_cli(&message);
472+
}
473+
460474
static int
461475
execute_white_leds(const struct shell *sh, size_t argc, char **argv)
462476
{
@@ -861,6 +875,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
861875
#ifdef CONFIG_BOARD_DIAMOND_MAIN
862876
SHELL_CMD(white_leds, NULL, "Control white LEDs", execute_white_leds),
863877
SHELL_CMD(polarizer, NULL, "Control polarizer wheel", execute_polarizer),
878+
SHELL_CMD(reboot_sec, NULL, "Reboot security MCU", execute_reboot_sec_mcu),
864879
#endif
865880
SHELL_CMD(boot_config, NULL, "Get/set boot behavior (button|always_on)",
866881
execute_boot_config),

main_board/src/runner/runner.c

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@
3232
#include <stdlib.h>
3333
#include <uart_messaging.h>
3434
#include <ui/rgb_leds/front_leds/front_leds.h>
35+
#include <zephyr/drivers/gpio.h>
3536
#include <zephyr/kernel.h>
3637

3738
#if defined(CONFIG_BOARD_DIAMOND_MAIN)
3839
#include "ui/rgb_leds/cone_leds/cone_leds.h"
3940
#include "ui/white_leds/white_leds.h"
41+
42+
static const struct gpio_dt_spec exp_mcu_rst_rqst_gpio_spec =
43+
GPIO_DT_SPEC_GET(DT_PATH(zephyr_user), exp_mcu_rst_rqst_gpios);
4044
#endif
4145

4246
#if defined(CONFIG_MEMFAULT_METRICS_CONNECTIVITY_CONNECTED_TIME)
@@ -1196,6 +1200,55 @@ handle_power_cycle(job_t *job)
11961200
}
11971201

11981202
#ifdef CONFIG_BOARD_DIAMOND_MAIN
1203+
static void
1204+
handle_reboot_security_mcu(job_t *job)
1205+
{
1206+
orb_mcu_main_JetsonToMcu *msg = &job->message.jetson_cmd;
1207+
MAKE_ASSERTS(orb_mcu_main_JetsonToMcu_reboot_security_mcu_tag);
1208+
1209+
int ret;
1210+
1211+
orb_mcu_Hardware hw_revision = version_get();
1212+
if (hw_revision.version <
1213+
orb_mcu_Hardware_OrbVersion_HW_VERSION_DIAMOND_V4_5) {
1214+
job_ack(orb_mcu_Ack_ErrorCode_VERSION, job);
1215+
return;
1216+
}
1217+
1218+
if (!gpio_is_ready_dt(&exp_mcu_rst_rqst_gpio_spec)) {
1219+
LOG_ERR("GPIO for security MCU reset request not ready");
1220+
job_ack(orb_mcu_Ack_ErrorCode_FAIL, job);
1221+
return;
1222+
}
1223+
1224+
ret = gpio_pin_configure_dt(&exp_mcu_rst_rqst_gpio_spec,
1225+
GPIO_OUTPUT_INACTIVE);
1226+
if (ret != 0) {
1227+
LOG_ERR("Failed to configure GPIO: %d", ret);
1228+
job_ack(orb_mcu_Ack_ErrorCode_FAIL, job);
1229+
return;
1230+
}
1231+
1232+
ret = gpio_pin_set_dt(&exp_mcu_rst_rqst_gpio_spec, 1);
1233+
if (ret != 0) {
1234+
LOG_ERR("Failed to set GPIO high: %d", ret);
1235+
job_ack(orb_mcu_Ack_ErrorCode_FAIL, job);
1236+
return;
1237+
}
1238+
1239+
k_msleep(100);
1240+
1241+
ret = gpio_pin_set_dt(&exp_mcu_rst_rqst_gpio_spec, 0);
1242+
if (ret != 0) {
1243+
LOG_ERR("Failed to set GPIO low: %d", ret);
1244+
job_ack(orb_mcu_Ack_ErrorCode_FAIL, job);
1245+
return;
1246+
}
1247+
1248+
LOG_INF("Security MCU reboot requested");
1249+
job_ack(orb_mcu_Ack_ErrorCode_SUCCESS, job);
1250+
}
1251+
11991252
static void
12001253
handle_polarizer(job_t *job)
12011254
{
@@ -1834,6 +1887,8 @@ static const hm_callback handle_message_callbacks[] = {
18341887
[orb_mcu_main_JetsonToMcu_polarizer_tag] = handle_polarizer,
18351888
[orb_mcu_main_JetsonToMcu_polarizer_wheel_settings_tag] =
18361889
handle_polarizer_wheel_settings,
1890+
[orb_mcu_main_JetsonToMcu_reboot_security_mcu_tag] =
1891+
handle_reboot_security_mcu,
18371892
#elif defined(CONFIG_BOARD_PEARL_MAIN)
18381893
[orb_mcu_main_JetsonToMcu_cone_leds_sequence_tag] = handle_not_supported,
18391894
[orb_mcu_main_JetsonToMcu_cone_leds_pattern_tag] = handle_not_supported,
@@ -1843,7 +1898,7 @@ static const hm_callback handle_message_callbacks[] = {
18431898
#endif
18441899
};
18451900

1846-
BUILD_ASSERT((ARRAY_SIZE(handle_message_callbacks) <= 57),
1901+
BUILD_ASSERT((ARRAY_SIZE(handle_message_callbacks) <= 58),
18471902
"It seems like the `handle_message_callbacks` array is too large");
18481903

18491904
_Noreturn static void

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ manifest:
2323
remote: memfault
2424
revision: 1.31.0
2525
- name: orb-messages
26-
revision: af472fadb57ce55ac63f8f94bd2a0608e62405c7
26+
revision: 3cb63e197d02cecf993314c2f15bead7db898e17
2727
path: modules/orb-messages/public
2828
- name: priv-orb-messages
2929
revision: 0da6bab271385e952813bfcbef9ce9bf38b0f27a

0 commit comments

Comments
 (0)