AP_BoardConfig: add options for write protecting bootloader and main flash

add option to completely remove protection on flash banks
This commit is contained in:
Andy Piper 2022-02-18 21:32:17 +00:00 committed by Peter Barker
parent f199f8be10
commit c01b1801c8
2 changed files with 19 additions and 1 deletions

View File

@ -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),

View File

@ -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;