From 79d5860a2bf1374c243b551ce73b0e298c29d364 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sun, 7 Apr 2024 11:07:57 +1000 Subject: [PATCH] AP_BoardConfig: force user to ack crashdump or get prearm failure --- libraries/AP_BoardConfig/AP_BoardConfig.cpp | 29 +++++++++++++++++++ libraries/AP_BoardConfig/AP_BoardConfig.h | 12 ++++++++ .../AP_BoardConfig/AP_BoardConfig_config.h | 4 +++ 3 files changed, 45 insertions(+) diff --git a/libraries/AP_BoardConfig/AP_BoardConfig.cpp b/libraries/AP_BoardConfig/AP_BoardConfig.cpp index 1457d86b6235d5..7e18e60f74c721 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig.cpp +++ b/libraries/AP_BoardConfig/AP_BoardConfig.cpp @@ -378,6 +378,16 @@ const AP_Param::GroupInfo AP_BoardConfig::var_info[] = { // @User: Advanced AP_GROUPINFO("IO_DSHOT", 28, AP_BoardConfig, state.io_dshot, 0), #endif + +#if AP_CRASHDUMP_ACK_ENABLED + // @Param: CRSHDMP_ACK + // @DisplayName: CrashDump Acknowledgement Required + // @Description: Must have value "1" if a crashdump is present on the system, or prearm failure will be raised. Do not set this parameter unless the risks of doing so are fully understood. + // @Values: 0:Crash dump NOT acked,1:Crash dump acked + // @User: Advanced + AP_GROUPINFO("CRSHDMP_ACK", 30, AP_BoardConfig, crashdump_ack.acked, 0), +#endif // AP_CRASHDUMP_ACK_ENABLED + AP_GROUPEND }; @@ -418,7 +428,26 @@ void AP_BoardConfig::init() printf("SDCard failed to start\n"); } #endif + +#if AP_CRASHDUMP_ACK_ENABLED + crashdump_ack.check_reset(); +#endif +} + +#if AP_CRASHDUMP_ACK_ENABLED +void AP_BoardConfig::CrashDump::check_reset() +{ + // if there is no crash_dump.bin then clear the crash dump ack. + // This means on subsequent crash-dumps appearing the user must + // re-acknowledge. + int fd = AP::FS().open("@SYS/crash_dump.bin", O_RDONLY); + if (fd == -1) { + // no (or probably empty) crash_dump.bin, so clear ack: + acked.set_and_save_ifchanged(0); + } + AP::FS().close(fd); } +#endif // AP_CRASHDUMP_ACK_ENABLED // set default value for BRD_SAFETY_MASK void AP_BoardConfig::set_default_safety_ignore_mask(uint32_t mask) diff --git a/libraries/AP_BoardConfig/AP_BoardConfig.h b/libraries/AP_BoardConfig/AP_BoardConfig.h index 938180a238bb95..b05407d0e8506d 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig.h +++ b/libraries/AP_BoardConfig/AP_BoardConfig.h @@ -27,6 +27,10 @@ class AP_BoardConfig { void init(void); void init_safety(void); +#if AP_CRASHDUMP_ACK_ENABLED + bool crashdump_acknowledged() const { return crashdump_ack.acked; } +#endif + static const struct AP_Param::GroupInfo var_info[]; // notify user of a fatal startup error related to available sensors. @@ -321,6 +325,14 @@ class AP_BoardConfig { AP_Int32 _options; AP_Int8 _alt_config; + +#if AP_CRASHDUMP_ACK_ENABLED + struct CrashDump { + void check_reset(); + AP_Int8 acked; + } crashdump_ack; +#endif // AP_CRASHDUMP_ACK_ENABLED + }; namespace AP { diff --git a/libraries/AP_BoardConfig/AP_BoardConfig_config.h b/libraries/AP_BoardConfig/AP_BoardConfig_config.h index c85f95439af3f4..05a2b1985b7c41 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig_config.h +++ b/libraries/AP_BoardConfig/AP_BoardConfig_config.h @@ -35,3 +35,7 @@ #ifndef AP_SDCARD_STORAGE_ENABLED #define AP_SDCARD_STORAGE_ENABLED (HAL_MEM_CLASS >= HAL_MEM_CLASS_1000) && (AP_FILESYSTEM_POSIX_ENABLED || AP_FILESYSTEM_FATFS_ENABLED) && BOARD_FLASH_SIZE > 1024 #endif + +#ifndef AP_CRASHDUMP_ACK_ENABLED +#define AP_CRASHDUMP_ACK_ENABLED AP_CRASHDUMP_ENABLED && AP_FILESYSTEM_SYS_ENABLED +#endif