@@ -66,7 +66,9 @@ static boot_info_t boot_info;
66
66
static uint32_t boot_info_offset ;
67
67
68
68
static uint8_t buf [SPI_FLASH_SEC_SIZE ];
69
- #define IMG_UPDATE1_OFFSET_OLD 0x1a0000
69
+ #define IMG_UPDATE1_OFFSET_OLD (0x1a0000)
70
+ #define OTA_DATA_ADDRESS_OLD (0x190000)
71
+ #define BOOTLOADER_ADDRESS (0x1000)
70
72
71
73
/******************************************************************************
72
74
DECLARE PRIVATE FUNCTIONS
@@ -109,6 +111,7 @@ bool updater_check_path (void *path) {
109
111
return false;
110
112
}
111
113
114
+ // This function basically simulates an OTA update, the new firmware comes from OTA_0 partition and not from a server
112
115
bool update_to_factory_partition (void ) {
113
116
114
117
// Size of the image used in 1.18.2r7 version
@@ -159,11 +162,11 @@ bool updater_start (void) {
159
162
// Only update bootloader, otadata and partition table if coming from older version (e.g. 1.18.2) and this is not a downgrade
160
163
// In case of upgrade the boot_info located under 0x190000 address
161
164
// In case of a downgrade, the boot info located somewhere else than 0x190000 because of the updated partition table
162
- if (boot_info_offset_local == (uint32_t )0x190000 ){
165
+ if (boot_info_offset_local == (uint32_t )OTA_DATA_ADDRESS_OLD ){
163
166
164
167
// Erasing address space of bootloader in 4 KB chunks, it is from 0x1000-0x9000 = 32KB (SPI_FLASH_SEC_SIZE = 4KB)
165
168
for (int i = 0 ; i < 8 ; i ++ ){
166
- ret = spi_flash_erase_sector ((0x1000 + (i * SPI_FLASH_SEC_SIZE )) / SPI_FLASH_SEC_SIZE );
169
+ ret = spi_flash_erase_sector ((BOOTLOADER_ADDRESS + (i * SPI_FLASH_SEC_SIZE )) / SPI_FLASH_SEC_SIZE );
167
170
if (ESP_OK != ret ) {
168
171
ESP_LOGE (TAG , "Erasing sectors of bootloader failed, error code: %d!\n" , ret );
169
172
// TODO: try again ???
@@ -172,7 +175,7 @@ bool updater_start (void) {
172
175
}
173
176
174
177
// Update bootloader
175
- ret = spi_flash_write ( 0x1000 , (void * )bootloader_bin , sizeof (bootloader_bin ));
178
+ ret = updater_spi_flash_write ( BOOTLOADER_ADDRESS , (void * )bootloader_bin , sizeof (bootloader_bin ), true );
176
179
if (ESP_OK != ret ) {
177
180
ESP_LOGE (TAG , "Updating bootloader failed, error code: %d\n" , ret );
178
181
//TODO: try again ???
@@ -219,10 +222,10 @@ bool updater_start (void) {
219
222
220
223
// Writing the new partition table
221
224
if (esp32_get_chip_rev () > 0 ) {
222
- ret = spi_flash_write (ESP_PARTITION_TABLE_ADDR , (void * )partitions_bin_8MB , sizeof (partitions_bin_8MB ));
225
+ ret = updater_spi_flash_write (ESP_PARTITION_TABLE_ADDR , (void * )partitions_bin_8MB , sizeof (partitions_bin_8MB ), true );
223
226
}
224
227
else {
225
- ret = spi_flash_write (ESP_PARTITION_TABLE_ADDR , (void * )partitions_bin_4MB , sizeof (partitions_bin_4MB ));
228
+ ret = updater_spi_flash_write (ESP_PARTITION_TABLE_ADDR , (void * )partitions_bin_4MB , sizeof (partitions_bin_4MB ), true );
226
229
}
227
230
if (ESP_OK != ret ) {
228
231
ESP_LOGE (TAG , "Writing new partition table failed, error code: %d\n" , ret );
0 commit comments