2121//#define LOG_LOCAL_LEVEL ESP_LOG_INFO
2222#include "esp_log.h"
2323#include "rom/crc.h"
24+ #include "esp32chipinfo.h"
2425
2526#include "ff.h"
2627
@@ -78,11 +79,13 @@ static esp_err_t updater_spi_flash_write(size_t dest_addr, void *src, size_t siz
7879 ******************************************************************************/
7980
8081bool updater_read_boot_info (boot_info_t * boot_info , uint32_t * boot_info_offset ) {
81- esp_partition_info_t partition_info [PARTITIONS_COUNT ];
82+ esp_partition_info_t partition_info [PARTITIONS_COUNT_4MB ];
83+
84+ uint8_t part_count = (esp32_get_chip_rev () > 0 ? PARTITIONS_COUNT_8MB : PARTITIONS_COUNT_4MB );
8285
8386 ESP_LOGV (TAG , "Reading boot info\n" );
8487
85- if (ESP_OK != updater_spi_flash_read (ESP_PARTITION_TABLE_ADDR , (void * )partition_info , sizeof (partition_info ), true)) {
88+ if (ESP_OK != updater_spi_flash_read (ESP_PARTITION_TABLE_ADDR , (void * )partition_info , ( sizeof (esp_partition_info_t ) * part_count ), true)) {
8689 ESP_LOGE (TAG , "err1\n" );
8790 return false;
8891 }
@@ -175,15 +178,27 @@ bool updater_start (void) {
175178 * The new location of otadata is 0x1BE000 or 0x1FF000 as per updated partition table and has size of
176179 * 4096 bytes which is size of a sector
177180 */
178- ret = spi_flash_erase_sector (OTA_DATA_ADDRESS / SPI_FLASH_SEC_SIZE );
181+ if (esp32_get_chip_rev () > 0 ) {
182+ ret = spi_flash_erase_sector (OTA_DATA_ADDRESS_8MB / SPI_FLASH_SEC_SIZE );
183+ }
184+ else {
185+ ret = spi_flash_erase_sector (OTA_DATA_ADDRESS_4MB / SPI_FLASH_SEC_SIZE );
186+ }
179187 if (ESP_OK != ret ) {
180188 ESP_LOGE (TAG , "Erasing new sector of boot info failed, error code: %d!\n" , ret );
181189 // TODO: try again ???
182190 return false;
183191 }
184192
185193 // Updating the NEW otadata partition with the OLD information
186- if (true != updater_write_boot_info (& boot_info_local , OTA_DATA_ADDRESS )) {
194+ bool updater_ret = false;
195+ if (esp32_get_chip_rev () > 0 ) {
196+ updater_ret = updater_write_boot_info (& boot_info_local , OTA_DATA_ADDRESS_8MB );
197+ }
198+ else {
199+ updater_ret = updater_write_boot_info (& boot_info_local , OTA_DATA_ADDRESS_4MB );
200+ }
201+ if (true != updater_ret ) {
187202 ESP_LOGE (TAG , "Writing new sector of boot info failed!\n" );
188203 //TODO: try again ???
189204 return false;
@@ -198,7 +213,7 @@ bool updater_start (void) {
198213 }
199214
200215 // Writing the new partition table
201- if (esp_get_revision () > 0 ) {
216+ if (esp32_get_chip_rev () > 0 ) {
202217 ret = spi_flash_write (ESP_PARTITION_TABLE_ADDR , (void * )partitions_bin_8MB , sizeof (partitions_bin_8MB ));
203218 }
204219 else {
@@ -210,7 +225,7 @@ bool updater_start (void) {
210225 return false;
211226 }
212227
213- updater_data .size = IMG_SIZE ;
228+ updater_data .size = ( esp32_get_chip_rev () > 0 ? IMG_SIZE_8MB : IMG_SIZE_4MB ) ;
214229 // check which one should be the next active image
215230 updater_data .offset = updater_ota_next_slot_address ();
216231
@@ -356,7 +371,7 @@ bool updater_write_boot_info(boot_info_t *boot_info, uint32_t boot_info_offset)
356371
357372int updater_ota_next_slot_address () {
358373
359- int ota_offset = IMG_UPDATE1_OFFSET ;
374+ int ota_offset = ( esp32_get_chip_rev () > 0 ? IMG_UPDATE1_OFFSET_8MB : IMG_UPDATE1_OFFSET_4MB ); ;
360375
361376 // check which one should be the next active image
362377 if (updater_read_boot_info (& boot_info , & boot_info_offset )) {
0 commit comments