mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-22 01:27:11 +08:00
feat(bootloader): Bootloader check and loader target application
This commit is contained in:
@ -491,6 +491,9 @@ static void set_cache_and_start_app(
|
|||||||
|
|
||||||
#include "esp_flash_partitions.h"
|
#include "esp_flash_partitions.h"
|
||||||
|
|
||||||
|
#define ESP_CACHE1_ADDR_MAX 0x100000
|
||||||
|
#define ESP_CACHE2_ADDR_MAX 0x200000
|
||||||
|
|
||||||
static const char* TAG = "boot";
|
static const char* TAG = "boot";
|
||||||
|
|
||||||
bool bootloader_utility_load_partition_table(bootloader_state_t* bs)
|
bool bootloader_utility_load_partition_table(bootloader_state_t* bs)
|
||||||
@ -814,12 +817,27 @@ void bootloader_utility_load_image(const esp_image_metadata_t* image_data)
|
|||||||
copy loaded segments to RAM, set up caches for mapped segments, and start application
|
copy loaded segments to RAM, set up caches for mapped segments, and start application
|
||||||
unpack_load_app(image_data);
|
unpack_load_app(image_data);
|
||||||
#else
|
#else
|
||||||
Cache_Read_Enable(0, 0, 0);
|
size_t map;
|
||||||
|
|
||||||
void (*user_start)(void);
|
if (image_data->start_addr < ESP_CACHE1_ADDR_MAX
|
||||||
|
&& image_data->start_addr + image_data->image_len < ESP_CACHE1_ADDR_MAX) {
|
||||||
|
map = 0;
|
||||||
|
} else if (image_data->start_addr >= ESP_CACHE1_ADDR_MAX
|
||||||
|
&& image_data->start_addr < ESP_CACHE2_ADDR_MAX
|
||||||
|
&& image_data->start_addr + image_data->image_len < ESP_CACHE2_ADDR_MAX) {
|
||||||
|
map = 1;
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "ERROR: app bin error, start_addr %x image_len %d\n", image_data->start_addr, image_data->image_len);
|
||||||
|
/* Blocking here to let user judge. */
|
||||||
|
while (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Cache_Read_Enable(map, 0, 0);
|
||||||
|
|
||||||
|
void (*user_start)(size_t start_addr, size_t map);
|
||||||
|
|
||||||
user_start = (void *)image_data->image.entry_addr;
|
user_start = (void *)image_data->image.entry_addr;
|
||||||
user_start();
|
user_start(image_data->start_addr, map);
|
||||||
#endif /* BOOTLOADER_UNPACK_APP */
|
#endif /* BOOTLOADER_UNPACK_APP */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,13 +58,11 @@ static const char *TAG = "chip_boot";
|
|||||||
* @brief initialize the chip including flash I/O and chip cache according to
|
* @brief initialize the chip including flash I/O and chip cache according to
|
||||||
* boot parameters which are stored at the flash
|
* boot parameters which are stored at the flash
|
||||||
*/
|
*/
|
||||||
void chip_boot(void)
|
void chip_boot(size_t start_addr, size_t map)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int usebin;
|
|
||||||
uint32_t freqdiv, flash_size, sect_size;
|
uint32_t freqdiv, flash_size, sect_size;
|
||||||
uint32_t freqbits;
|
uint32_t freqbits;
|
||||||
uint32_t cache_map;
|
|
||||||
flash_hdr_t fhdr;
|
flash_hdr_t fhdr;
|
||||||
boot_hdr_t bhdr;
|
boot_hdr_t bhdr;
|
||||||
|
|
||||||
@ -86,7 +84,7 @@ void chip_boot(void)
|
|||||||
|
|
||||||
SET_PERI_REG_MASK(PERIPHS_SPI_FLASH_USRREG, BIT5);
|
SET_PERI_REG_MASK(PERIPHS_SPI_FLASH_USRREG, BIT5);
|
||||||
|
|
||||||
ret = spi_flash_read(CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET, &fhdr, sizeof(flash_hdr_t));
|
ret = spi_flash_read(start_addr, &fhdr, sizeof(flash_hdr_t));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ESP_LOGE(TAG, "SPI flash read result %d\n", ret);
|
ESP_LOGE(TAG, "SPI flash read result %d\n", ret);
|
||||||
}
|
}
|
||||||
@ -122,38 +120,7 @@ void chip_boot(void)
|
|||||||
ESP_LOGE(TAG, "Get boot parameters %d\n", ret);
|
ESP_LOGE(TAG, "Get boot parameters %d\n", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bhdr.user_bin == 1) {
|
cache_init(map, 0, 0);
|
||||||
if (bhdr.boot_status == 1)
|
|
||||||
usebin = 1;
|
|
||||||
else
|
|
||||||
usebin = 0;
|
|
||||||
} else {
|
|
||||||
if (bhdr.boot_status == 1)
|
|
||||||
usebin = 0;
|
|
||||||
else {
|
|
||||||
if (bhdr.version == 4) {
|
|
||||||
bhdr.boot_status = 1;
|
|
||||||
usebin = 0;
|
|
||||||
} else
|
|
||||||
usebin = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cache_map = 0;
|
|
||||||
if (fhdr.spi_size_map == FLASH_SIZE_16M_MAP_1024_1024
|
|
||||||
|| fhdr.spi_size_map == FLASH_SIZE_32M_MAP_1024_1024
|
|
||||||
|| fhdr.spi_size_map == FLASH_SIZE_64M_MAP_1024_1024
|
|
||||||
|| fhdr.spi_size_map == FLASH_SIZE_128M_MAP_1024_1024) {
|
|
||||||
if (bhdr.version >= 4
|
|
||||||
&& bhdr.version <= 0x1f) {
|
|
||||||
if (usebin == 1)
|
|
||||||
cache_map = 1;
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "Need boot 1.4+\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cache_init(cache_map, 0, 0);
|
|
||||||
|
|
||||||
if (bhdr.to_qio == 0)
|
if (bhdr.to_qio == 0)
|
||||||
user_spi_flash_dio_to_qio_pre_init();
|
user_spi_flash_dio_to_qio_pre_init();
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#define FLASH_MAP_ADDR 0x40200000
|
#define FLASH_MAP_ADDR 0x40200000
|
||||||
|
|
||||||
extern void chip_boot(void);
|
extern void chip_boot(size_t start_addr, size_t map);
|
||||||
extern int rtc_init(void);
|
extern int rtc_init(void);
|
||||||
extern int mac_init(void);
|
extern int mac_init(void);
|
||||||
extern int base_gpio_init(void);
|
extern int base_gpio_init(void);
|
||||||
@ -66,7 +66,7 @@ static void user_init_entry(void *param)
|
|||||||
wifi_task_delete(NULL);
|
wifi_task_delete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void call_user_start(void)
|
void call_user_start(size_t start_addr, size_t map)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int *p;
|
int *p;
|
||||||
@ -91,6 +91,8 @@ void call_user_start(void)
|
|||||||
for (p = &_bss_start; p < &_bss_end; p++)
|
for (p = &_bss_start; p < &_bss_end; p++)
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
|
||||||
|
chip_boot(start_addr, map);
|
||||||
|
|
||||||
__asm__ __volatile__(
|
__asm__ __volatile__(
|
||||||
"rsil a2, 2\n"
|
"rsil a2, 2\n"
|
||||||
"movi a1, _chip_interrupt_tmp\n"
|
"movi a1, _chip_interrupt_tmp\n"
|
||||||
@ -99,8 +101,6 @@ void call_user_start(void)
|
|||||||
"movi a2, 0x40100000\n"
|
"movi a2, 0x40100000\n"
|
||||||
"wsr a2, vecbase\n");
|
"wsr a2, vecbase\n");
|
||||||
|
|
||||||
chip_boot();
|
|
||||||
|
|
||||||
wifi_os_init();
|
wifi_os_init();
|
||||||
|
|
||||||
assert(wifi_task_create(user_init_entry, "uiT", 2048, NULL, wifi_task_get_max_priority()) != NULL);
|
assert(wifi_task_create(user_init_entry, "uiT", 2048, NULL, wifi_task_get_max_priority()) != NULL);
|
||||||
|
Reference in New Issue
Block a user