From c01b1801c877f3aedd03c86e5a7d9da8a5356b27 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Fri, 18 Feb 2022 21:32:17 +0000 Subject: [PATCH] AP_BoardConfig: add options for write protecting bootloader and main flash add option to completely remove protection on flash banks --- libraries/AP_BoardConfig/AP_BoardConfig.cpp | 2 +- libraries/AP_BoardConfig/AP_BoardConfig.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libraries/AP_BoardConfig/AP_BoardConfig.cpp b/libraries/AP_BoardConfig/AP_BoardConfig.cpp index 1a55f78334..084c1964fa 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig.cpp +++ b/libraries/AP_BoardConfig/AP_BoardConfig.cpp @@ -275,7 +275,7 @@ const AP_Param::GroupInfo AP_BoardConfig::var_info[] = { // @Param: OPTIONS // @DisplayName: Board options // @Description: Board specific option flags - // @Bitmask: 0:Enable hardware watchdog, 1:Disable MAVftp, 2:Enable set of internal parameters, 3:Enable Debug Pins + // @Bitmask: 0:Enable hardware watchdog, 1:Disable MAVftp, 2:Enable set of internal parameters, 3:Enable Debug Pins, 4:Unlock flash on reboot, 5:Write protect firmware flash on reboot, 6:Write protect bootloader flash on reboot // @User: Advanced AP_GROUPINFO("OPTIONS", 19, AP_BoardConfig, _options, HAL_BRD_OPTIONS_DEFAULT), diff --git a/libraries/AP_BoardConfig/AP_BoardConfig.h b/libraries/AP_BoardConfig/AP_BoardConfig.h index 47ea8d4408..34297de10d 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig.h +++ b/libraries/AP_BoardConfig/AP_BoardConfig.h @@ -172,6 +172,9 @@ public: DISABLE_FTP = (1<<1), ALLOW_SET_INTERNAL_PARM = (1<<2), BOARD_OPTION_DEBUG_ENABLE = (1<<3), + UNLOCK_FLASH = (1<<4), + WRITE_PROTECT_FLASH = (1<<5), + WRITE_PROTECT_BOOTLOADER = (1<<6), }; // return true if ftp is disabled @@ -184,6 +187,21 @@ public: return _singleton?(_singleton->_options & BOARD_OPTION_WATCHDOG)!=0:HAL_WATCHDOG_ENABLED_DEFAULT; } + // return true if flash should be unlocked + static bool unlock_flash(void) { + return _singleton && (_singleton->_options & UNLOCK_FLASH) != 0; + } + + // return true if flash should be write protected + static bool protect_flash(void) { + return _singleton && (_singleton->_options & WRITE_PROTECT_FLASH) != 0; + } + + // return true if bootloader should be write protected + static bool protect_bootloader(void) { + return _singleton && (_singleton->_options & WRITE_PROTECT_BOOTLOADER) != 0; + } + // return true if we allow setting of internal parameters (for developers) static bool allow_set_internal_parameters(void) { return _singleton?(_singleton->_options & ALLOW_SET_INTERNAL_PARM)!=0:false;