@@ -66,7 +66,9 @@ static boot_info_t boot_info;
6666static uint32_t boot_info_offset ;
6767
6868static 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)
7072
7173/******************************************************************************
7274 DECLARE PRIVATE FUNCTIONS
@@ -109,6 +111,7 @@ bool updater_check_path (void *path) {
109111 return false;
110112}
111113
114+ // This function basically simulates an OTA update, the new firmware comes from OTA_0 partition and not from a server
112115bool update_to_factory_partition (void ) {
113116
114117 // Size of the image used in 1.18.2r7 version
@@ -159,11 +162,11 @@ bool updater_start (void) {
159162 // Only update bootloader, otadata and partition table if coming from older version (e.g. 1.18.2) and this is not a downgrade
160163 // In case of upgrade the boot_info located under 0x190000 address
161164 // 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 ){
163166
164167 // Erasing address space of bootloader in 4 KB chunks, it is from 0x1000-0x9000 = 32KB (SPI_FLASH_SEC_SIZE = 4KB)
165168 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 );
167170 if (ESP_OK != ret ) {
168171 ESP_LOGE (TAG , "Erasing sectors of bootloader failed, error code: %d!\n" , ret );
169172 // TODO: try again ???
@@ -172,7 +175,7 @@ bool updater_start (void) {
172175 }
173176
174177 // 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 );
176179 if (ESP_OK != ret ) {
177180 ESP_LOGE (TAG , "Updating bootloader failed, error code: %d\n" , ret );
178181 //TODO: try again ???
@@ -219,10 +222,10 @@ bool updater_start (void) {
219222
220223 // Writing the new partition table
221224 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 );
223226 }
224227 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 );
226229 }
227230 if (ESP_OK != ret ) {
228231 ESP_LOGE (TAG , "Writing new partition table failed, error code: %d\n" , ret );
0 commit comments