diff --git a/optiboot/bootloaders/optiboot/Makefile b/optiboot/bootloaders/optiboot/Makefile index 8bec2913d..720a4c2c5 100644 --- a/optiboot/bootloaders/optiboot/Makefile +++ b/optiboot/bootloaders/optiboot/Makefile @@ -173,6 +173,12 @@ else BAUD_RATE_CMD = -DBAUD_RATE=115200 endif +ifdef ALWAYS_USE_BOOTLOADER +ALWAYS_USE_BOOTLOADER_CMD = -DALWAYS_USE_BOOTLOADER=$(ALWAYS_USE_BOOTLOADER) +else +ALWAYS_USE_BOOTLOADER_CMD = +endif + HELPTEXT += "Option LED=B3 - set LED pin to particular port/bit\n" ifdef LED LED_CMD = -DLED=$(LED) @@ -299,7 +305,7 @@ COMMON_OPTIONS = $(BAUD_RATE_CMD) $(LED_START_FLASHES_CMD) $(BIGBOOT_CMD) COMMON_OPTIONS += $(SOFT_UART_CMD) $(LED_DATA_FLASH_CMD) $(LED_CMD) $(SS_CMD) COMMON_OPTIONS += $(SUPPORT_EEPROM_CMD) $(LED_START_ON_CMD) $(APPSPM_CMD) COMMON_OPTIONS += $(OSCCAL_VALUE_CMD) $(VERSION_CMD) $(TIMEOUT_CMD) -COMMON_OPTIONS += $(POR_CMD) $(EXTR_CMD) $(RS485_CMD) +COMMON_OPTIONS += $(POR_CMD) $(EXTR_CMD) $(RS485_CMD) $(ALWAYS_USE_BOOTLOADER_CMD) #UART is handled separately and only passed for devices with more than one. HELPTEXT += "Option UART=n - use UARTn for communications\n" diff --git a/optiboot/bootloaders/optiboot/optiboot.c b/optiboot/bootloaders/optiboot/optiboot.c index dec9c45ed..41bf1a9c3 100644 --- a/optiboot/bootloaders/optiboot/optiboot.c +++ b/optiboot/bootloaders/optiboot/optiboot.c @@ -781,12 +781,21 @@ int main(void) { # warning "START_APP_ON_EXTR is defined and NO_START_APP_ON_POR isn't" # define APP_START_REASONS 1 /* Always start rge App. */ # define WDRF_CLR_REASONS 0 /* Never clear WDRF */ +#endif + +#if ALWAYS_USE_BOOTLOADER +#define _ALWAYS_USE_BOOTLOADR 1 +#else +#define _ALWAYS_USE_BOOTLOADR 0 #endif ch = MCUSR; // Skip all logic and run bootloader if MCUSR is cleared (application request) - if (ch != 0) { + if (_ALWAYS_USE_BOOTLOADR || ch != 0) { + +#undef _ALWAYS_USE_BOOTLOADR + /* * To run the boot loader, External Reset Flag must be set. * If not, we could make shortcut and jump directly to application code.