* The hardware is mostly uninitialized, flash cache is down and the app CPU is in reset.
* We do have a stack, so we can do the initialization in C.
*/
-void call_start_cpu0()
+void __attribute__((noreturn)) call_start_cpu0()
{
// 1. Hardware initialization
if (bootloader_init() != ESP_OK) {
- return;
+ bootloader_reset();
}
// 2. Select the number of boot partition
bootloader_state_t bs = { 0 };
int boot_index = select_partition_number(&bs);
if (boot_index == INVALID_INDEX) {
- return;
+ bootloader_reset();
}
// 3. Load the app image for booting
* @param[in] start_index The index from which the search for images begins.
*/
__attribute__((noreturn)) void bootloader_utility_load_boot_image(const bootloader_state_t *bs, int start_index);
+
+
+/**
+ * @brief Software reset the ESP32
+ *
+ * Bootloader code should call this in the case that it cannot proceed.
+ *
+ * It is not recommended to call this function from an app (if called, the app will abort).
+ */
+__attribute__((noreturn)) void bootloader_reset(void);
#include "bootloader_random.h"
#include "bootloader_config.h"
#include "bootloader_common.h"
+#include "bootloader_utility.h"
static const char* TAG = "boot";
load_image(&image_data);
} else {
ESP_LOGE(TAG, "No bootable test partition in the partition table");
- return;
+ bootloader_reset();
}
}
ESP_LOGE(TAG, "No bootable app partitions in the partition table");
bzero(&image_data, sizeof(esp_image_metadata_t));
+ bootloader_reset();
}
// Copy loaded segments to RAM, set up caches for mapped segments, and start application.
so issue a system reset to ensure flash encryption
cache resets properly */
ESP_LOGI(TAG, "Resetting with flash encryption enabled...");
- REG_WRITE(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_SYS_RST);
- return;
+ bootloader_reset();
}
#endif
// use "movsp" instruction to reset stack back to where ROM stack starts.
(*entry)();
}
+
+
+void bootloader_reset(void)
+{
+#ifdef BOOTLOADER_BUILD
+ uart_tx_flush(0); /* Ensure any buffered log output is displayed */
+ uart_tx_flush(1);
+ ets_delay_us(1000); /* Allow last byte to leave FIFO */
+ REG_WRITE(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_SYS_RST);
+ while (1) { } /* This line will never be reached, used to keep gcc happy */
+#else
+ abort(); /* This function should really not be called from application code */
+#endif
+}