Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 583a875

Browse files
committed
feat(bootloader): Bootloader check and loader target application
1 parent cb0c5ee commit 583a875

File tree

3 files changed

+28
-43
lines changed

3 files changed

+28
-43
lines changed

components/bootloader_support/src/bootloader_utility.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ static void set_cache_and_start_app(
491491

492492
#include "esp_flash_partitions.h"
493493

494+
#define ESP_CACHE1_ADDR_MAX 0x100000
495+
#define ESP_CACHE2_ADDR_MAX 0x200000
496+
494497
static const char* TAG = "boot";
495498

496499
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)
814817
copy loaded segments to RAM, set up caches for mapped segments, and start application
815818
unpack_load_app(image_data);
816819
#else
817-
Cache_Read_Enable(0, 0, 0);
820+
size_t map;
821+
822+
if (image_data->start_addr < ESP_CACHE1_ADDR_MAX
823+
&& image_data->start_addr + image_data->image_len < ESP_CACHE1_ADDR_MAX) {
824+
map = 0;
825+
} else if (image_data->start_addr >= ESP_CACHE1_ADDR_MAX
826+
&& image_data->start_addr < ESP_CACHE2_ADDR_MAX
827+
&& image_data->start_addr + image_data->image_len < ESP_CACHE2_ADDR_MAX) {
828+
map = 1;
829+
} else {
830+
ESP_LOGE(TAG, "ERROR: app bin error, start_addr %x image_len %d\n", image_data->start_addr, image_data->image_len);
831+
/* Blocking here to let user judge. */
832+
while (1);
833+
}
834+
835+
Cache_Read_Enable(map, 0, 0);
818836

819-
void (*user_start)(void);
837+
void (*user_start)(size_t start_addr, size_t map);
820838

821839
user_start = (void *)image_data->image.entry_addr;
822-
user_start();
840+
user_start(image_data->start_addr, map);
823841
#endif /* BOOTLOADER_UNPACK_APP */
824842
}
825843

components/esp8266/source/chip_boot.c

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,11 @@ static const char *TAG = "chip_boot";
5858
* @brief initialize the chip including flash I/O and chip cache according to
5959
* boot parameters which are stored at the flash
6060
*/
61-
void chip_boot(void)
61+
void chip_boot(size_t start_addr, size_t map)
6262
{
6363
int ret;
64-
int usebin;
6564
uint32_t freqdiv, flash_size, sect_size;
6665
uint32_t freqbits;
67-
uint32_t cache_map;
6866
flash_hdr_t fhdr;
6967
boot_hdr_t bhdr;
7068

@@ -86,7 +84,7 @@ void chip_boot(void)
8684

8785
SET_PERI_REG_MASK(PERIPHS_SPI_FLASH_USRREG, BIT5);
8886

89-
ret = spi_flash_read(CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET, &fhdr, sizeof(flash_hdr_t));
87+
ret = spi_flash_read(start_addr, &fhdr, sizeof(flash_hdr_t));
9088
if (ret) {
9189
ESP_LOGE(TAG, "SPI flash read result %d\n", ret);
9290
}
@@ -122,38 +120,7 @@ void chip_boot(void)
122120
ESP_LOGE(TAG, "Get boot parameters %d\n", ret);
123121
}
124122

125-
if (bhdr.user_bin == 1) {
126-
if (bhdr.boot_status == 1)
127-
usebin = 1;
128-
else
129-
usebin = 0;
130-
} else {
131-
if (bhdr.boot_status == 1)
132-
usebin = 0;
133-
else {
134-
if (bhdr.version == 4) {
135-
bhdr.boot_status = 1;
136-
usebin = 0;
137-
} else
138-
usebin = 1;
139-
}
140-
}
141-
142-
cache_map = 0;
143-
if (fhdr.spi_size_map == FLASH_SIZE_16M_MAP_1024_1024
144-
|| fhdr.spi_size_map == FLASH_SIZE_32M_MAP_1024_1024
145-
|| fhdr.spi_size_map == FLASH_SIZE_64M_MAP_1024_1024
146-
|| fhdr.spi_size_map == FLASH_SIZE_128M_MAP_1024_1024) {
147-
if (bhdr.version >= 4
148-
&& bhdr.version <= 0x1f) {
149-
if (usebin == 1)
150-
cache_map = 1;
151-
} else {
152-
ESP_LOGE(TAG, "Need boot 1.4+\n");
153-
}
154-
}
155-
156-
cache_init(cache_map, 0, 0);
123+
cache_init(map, 0, 0);
157124

158125
if (bhdr.to_qio == 0)
159126
user_spi_flash_dio_to_qio_pre_init();

components/esp8266/source/startup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#define FLASH_MAP_ADDR 0x40200000
3131

32-
extern void chip_boot(void);
32+
extern void chip_boot(size_t start_addr, size_t map);
3333
extern int rtc_init(void);
3434
extern int mac_init(void);
3535
extern int base_gpio_init(void);
@@ -66,7 +66,7 @@ static void user_init_entry(void *param)
6666
wifi_task_delete(NULL);
6767
}
6868

69-
void call_user_start(void)
69+
void call_user_start(size_t start_addr, size_t map)
7070
{
7171
int i;
7272
int *p;
@@ -91,6 +91,8 @@ void call_user_start(void)
9191
for (p = &_bss_start; p < &_bss_end; p++)
9292
*p = 0;
9393

94+
chip_boot(start_addr, map);
95+
9496
__asm__ __volatile__(
9597
"rsil a2, 2\n"
9698
"movi a1, _chip_interrupt_tmp\n"
@@ -99,8 +101,6 @@ void call_user_start(void)
99101
"movi a2, 0x40100000\n"
100102
"wsr a2, vecbase\n");
101103

102-
chip_boot();
103-
104104
wifi_os_init();
105105

106106
assert(wifi_task_create(user_init_entry, "uiT", 2048, NULL, wifi_task_get_max_priority()) != NULL);

0 commit comments

Comments
 (0)