fix(ram_app): Fixed issue ram_app can't use the SPI Flash

1st bootloader won't help to initialize the MSPI & cache properly as it
usually do when loading from flash. And the ram app doesn't have valid
headers.

Since there is no enough space in 2nd bootloader, we replace the
`bootloader_init_spi_flash` in the ram_app (!pure_ram_app), with an
customized alternative of it for the ram_app.

This alternative helps to initialize the MSPI & cache properly, without
the help of 1st bootloader or image headers.
This commit is contained in:
Xiao Xufeng
2023-08-26 22:08:23 +08:00
parent 10401d95d0
commit 28f19cf0e6
20 changed files with 615 additions and 54 deletions
@@ -23,7 +23,9 @@
static const char *TAG = "boot";
#if !CONFIG_APP_BUILD_TYPE_RAM
esp_image_header_t WORD_ALIGNED_ATTR bootloader_image_hdr;
#endif
void bootloader_clear_bss_section(void)
{
@@ -39,7 +39,7 @@
static const char *TAG = "boot.esp32";
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#if !CONFIG_APP_BUILD_TYPE_RAM
static void bootloader_reset_mmu(void)
{
/* completely reset MMU in case serial bootloader was running */
@@ -208,7 +208,7 @@ esp_err_t bootloader_init(void)
/* print 2nd bootloader banner */
bootloader_print_banner();
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#if !CONFIG_APP_BUILD_TYPE_RAM
// reset MMU
bootloader_reset_mmu();
// update flash ID
@@ -218,7 +218,6 @@ esp_err_t bootloader_init(void)
ESP_LOGE(TAG, "failed when running XMC startup flow, reboot!");
return ret;
}
#if !CONFIG_APP_BUILD_TYPE_RAM
// read bootloader header
if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
return ret;
@@ -227,12 +226,11 @@ esp_err_t bootloader_init(void)
if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
return ret;
}
#endif // #if !CONFIG_APP_BUILD_TYPE_RAM
// initialize spi flash
if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
return ret;
}
#endif //#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#endif // #if !CONFIG_APP_BUILD_TYPE_RAM
// check whether a WDT reset happend
bootloader_check_wdt_reset();
@@ -120,14 +120,13 @@ esp_err_t bootloader_init(void)
/* print 2nd bootloader banner */
bootloader_print_banner();
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#if !CONFIG_APP_BUILD_TYPE_RAM
//init cache hal
cache_hal_init();
//init mmu
mmu_hal_init();
// update flash ID
bootloader_flash_update_id();
#if !CONFIG_APP_BUILD_TYPE_RAM
// read bootloader header
if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
return ret;
@@ -136,12 +135,11 @@ esp_err_t bootloader_init(void)
if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
return ret;
}
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// initialize spi flash
if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
return ret;
}
#endif //#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// check whether a WDT reset happend
bootloader_check_wdt_reset();
@@ -159,7 +159,7 @@ esp_err_t bootloader_init(void)
/* print 2nd bootloader banner */
bootloader_print_banner();
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#if !CONFIG_APP_BUILD_TYPE_RAM
//init cache hal
cache_hal_init();
//init mmu
@@ -171,7 +171,6 @@ esp_err_t bootloader_init(void)
ESP_LOGE(TAG, "failed when running XMC startup flow, reboot!");
return ret;
}
#if !CONFIG_APP_BUILD_TYPE_RAM
// read bootloader header
if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
return ret;
@@ -180,12 +179,11 @@ esp_err_t bootloader_init(void)
if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
return ret;
}
#endif //#if !CONFIG_APP_BUILD_TYPE_RAM
// initialize spi flash
if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
return ret;
}
#endif // !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#endif //#if !CONFIG_APP_BUILD_TYPE_RAM
// check whether a WDT reset happend
bootloader_check_wdt_reset();
@@ -143,7 +143,7 @@ esp_err_t bootloader_init(void)
/* print 2nd bootloader banner */
bootloader_print_banner();
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#if !CONFIG_APP_BUILD_TYPE_RAM
//init cache hal
cache_hal_init();
//init mmu
@@ -155,7 +155,6 @@ esp_err_t bootloader_init(void)
ESP_LOGE(TAG, "failed when running XMC startup flow, reboot!");
return ret;
}
#if !CONFIG_APP_BUILD_TYPE_RAM
// read bootloader header
if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
return ret;
@@ -164,12 +163,11 @@ esp_err_t bootloader_init(void)
if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
return ret;
}
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// initialize spi flash
if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
return ret;
}
#endif // #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// check whether a WDT reset happend
bootloader_check_wdt_reset();
@@ -132,7 +132,7 @@ esp_err_t bootloader_init(void)
/* print 2nd bootloader banner */
bootloader_print_banner();
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#if !CONFIG_APP_BUILD_TYPE_RAM
//init cache hal
cache_hal_init();
//init mmu
@@ -144,7 +144,6 @@ esp_err_t bootloader_init(void)
ESP_LOGE(TAG, "failed when running XMC startup flow, reboot!");
return ret;
}
#if !CONFIG_APP_BUILD_TYPE_RAM
// read bootloader header
if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
return ret;
@@ -153,12 +152,11 @@ esp_err_t bootloader_init(void)
if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
return ret;
}
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// initialize spi flash
if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
return ret;
}
#endif //#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// check whether a WDT reset happend
bootloader_check_wdt_reset();
@@ -136,7 +136,7 @@ esp_err_t bootloader_init(void)
/* print 2nd bootloader banner */
bootloader_print_banner();
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#if !CONFIG_APP_BUILD_TYPE_RAM
//init cache hal
cache_hal_init();
//reset mmu
@@ -148,7 +148,6 @@ esp_err_t bootloader_init(void)
ESP_LOGE(TAG, "failed when running XMC startup flow, reboot!");
return ret;
}
#if !CONFIG_APP_BUILD_TYPE_RAM
// read bootloader header
if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
return ret;
@@ -157,12 +156,11 @@ esp_err_t bootloader_init(void)
if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
return ret;
}
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// initialize spi flash
if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
return ret;
}
#endif // #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// check whether a WDT reset happend
bootloader_check_wdt_reset();
@@ -139,7 +139,7 @@ esp_err_t bootloader_init(void)
/* print 2nd bootloader banner */
bootloader_print_banner();
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#if !CONFIG_APP_BUILD_TYPE_RAM
// init cache hal
cache_hal_init();
//init mmu
@@ -153,7 +153,6 @@ esp_err_t bootloader_init(void)
ESP_LOGE(TAG, "failed when running XMC startup flow, reboot!");
return ret;
}
#if !CONFIG_APP_BUILD_TYPE_RAM
// read bootloader header
if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
return ret;
@@ -162,12 +161,11 @@ esp_err_t bootloader_init(void)
if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
return ret;
}
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// initialize spi flash
if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
return ret;
}
#endif // #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// check whether a WDT reset happend
bootloader_check_wdt_reset();
@@ -178,7 +178,7 @@ esp_err_t bootloader_init(void)
/* print 2nd bootloader banner */
bootloader_print_banner();
#if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#if !CONFIG_APP_BUILD_TYPE_RAM
//init cache hal
cache_hal_init();
//init mmu
@@ -190,7 +190,6 @@ esp_err_t bootloader_init(void)
ESP_LOGE(TAG, "failed when running XMC startup flow, reboot!");
return ret;
}
#if !CONFIG_APP_BUILD_TYPE_RAM
// read bootloader header
if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
return ret;
@@ -199,12 +198,11 @@ esp_err_t bootloader_init(void)
if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
return ret;
}
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// initialize spi flash
if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
return ret;
}
#endif // #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP
#endif // !CONFIG_APP_BUILD_TYPE_RAM
// check whether a WDT reset happend
bootloader_check_wdt_reset();