diff --git a/comm/commands.c b/comm/commands.c index e69a93a327..753fd16eae 100644 --- a/comm/commands.c +++ b/comm/commands.c @@ -321,7 +321,13 @@ void commands_process_packet(unsigned char *data, unsigned int len, if (nrf_driver_ext_nrf_running()) { nrf_driver_pause(6000); } - uint16_t flash_res = flash_helper_erase_new_app(buffer_get_uint32(data, &ind)); + uint16_t flash_res = 100; + if (!REJECT_FLASH_LOADING) { + flash_res = flash_helper_erase_new_app(buffer_get_uint32(data, &ind)); + } + else { + commands_printf("Firmware loading rejected by the controller."); + } ind = 0; uint8_t send_buffer[50]; diff --git a/hwconf/Ubox/100v/hw_ubox_100_core.c b/hwconf/Ubox/100v/hw_ubox_100_core.c index a87744a6fc..30ab8d6e95 100755 --- a/hwconf/Ubox/100v/hw_ubox_100_core.c +++ b/hwconf/Ubox/100v/hw_ubox_100_core.c @@ -336,6 +336,16 @@ static enPOWER_KEY_TYPE power_key_type = power_key_type_undecided; static uint32_t power_key_pressed_ms = 0; static bool power_key_pressed_when_power_on = false; +bool hw_reject_flash_loading(void) +{ + bool do_reject = power_key_type == power_key_type_momentary; + if (do_reject) + commands_printf("%s: Momentary button detected, firmware loading is not permitted!", HW_NAME); + + // Don't allow loading firmware if the power button behaves like a momentary one + return do_reject; +} + static THD_FUNCTION(shutdown_thread, arg) { (void)arg; chRegSetThreadName("Shutdown_ubox"); diff --git a/hwconf/Ubox/100v/hw_ubox_100_core.h b/hwconf/Ubox/100v/hw_ubox_100_core.h index 9cd2886552..3658c74a89 100755 --- a/hwconf/Ubox/100v/hw_ubox_100_core.h +++ b/hwconf/Ubox/100v/hw_ubox_100_core.h @@ -36,6 +36,8 @@ #error "Must define hardware type" #endif +#define REJECT_FLASH_LOADING hw_reject_flash_loading() + // HW properties #define HW_HAS_3_SHUNTS #define INVERTED_SHUNT_POLARITY @@ -295,5 +297,6 @@ // HW-specific functions float hw100_250_get_temp(void); +bool hw_reject_flash_loading(void); #endif /* HW_UBOX_V2_100_CORE_H_ */ diff --git a/hwconf/Ubox/126v/hw_ubox_126_core.c b/hwconf/Ubox/126v/hw_ubox_126_core.c index 82801b21a3..22da4349f0 100644 --- a/hwconf/Ubox/126v/hw_ubox_126_core.c +++ b/hwconf/Ubox/126v/hw_ubox_126_core.c @@ -336,6 +336,16 @@ static enPOWER_KEY_TYPE power_key_type = power_key_type_undecided; static uint32_t power_key_pressed_ms = 0; static bool power_key_pressed_when_power_on = false; +bool hw_reject_flash_loading(void) +{ + bool do_reject = power_key_type == power_key_type_momentary; + if (do_reject) + commands_printf("%s: Momentary button detected, firmware loading is not permitted!", HW_NAME); + + // Don't allow loading firmware if the power button behaves like a momentary one + return do_reject; +} + static THD_FUNCTION(shutdown_thread, arg) { (void)arg; chRegSetThreadName("Shutdown_ubox"); diff --git a/hwconf/Ubox/126v/hw_ubox_126_core.h b/hwconf/Ubox/126v/hw_ubox_126_core.h index 87c3864f1e..f7d7534c67 100644 --- a/hwconf/Ubox/126v/hw_ubox_126_core.h +++ b/hwconf/Ubox/126v/hw_ubox_126_core.h @@ -32,6 +32,8 @@ #error "Must define hardware type" #endif +#define REJECT_FLASH_LOADING hw_reject_flash_loading() + // HW properties #define HW_HAS_3_SHUNTS #define INVERTED_SHUNT_POLARITY @@ -280,5 +282,6 @@ // HW-specific functions float hw100_250_get_temp(void); +bool hw_reject_flash_loading(void); #endif /* HW_UBOX_126_CORE_H_ */ diff --git a/hwconf/hw.h b/hwconf/hw.h index e69b9e2ac0..a9a01fc58e 100644 --- a/hwconf/hw.h +++ b/hwconf/hw.h @@ -547,6 +547,10 @@ #define HW_PERMANENT_NRF_FAILED_HOOK() #endif +#ifndef REJECT_FLASH_LOADING +#define REJECT_FLASH_LOADING false +#endif + #ifndef HW_EARLY_INIT #define HW_EARLY_INIT() #endif