7979
8080
8181#include "lteppp.h"
82+ #include "esp32chipinfo.h"
8283/******************************************************************************
8384 DECLARE EXTERNAL FUNCTIONS
8485 ******************************************************************************/
@@ -90,6 +91,8 @@ extern void modpycom_init0(void);
9091#define GC_POOL_SIZE_BYTES (67 * 1024)
9192#define GC_POOL_SIZE_BYTES_PSRAM ((2048 + 512) * 1024)
9293
94+ #define OTA_DATA_ADDRESS_OLD (0x190000)
95+
9396/******************************************************************************
9497 DECLARE PRIVATE FUNCTIONS
9598 ******************************************************************************/
@@ -116,6 +119,8 @@ static uint8_t *gc_pool_upy;
116119static char fresh_main_py [] = "# main.py -- put your code here!\r\n" ;
117120static char fresh_boot_py [] = "# boot.py -- run on boot-up\r\n" ;
118121
122+ extern bool update_to_factory_partition (void );
123+
119124/******************************************************************************
120125 DEFINE PUBLIC FUNCTIONS
121126 ******************************************************************************/
@@ -125,16 +130,37 @@ void TASK_Micropython (void *pvParameters) {
125130 uint32_t gc_pool_size ;
126131 bool soft_reset = false;
127132 bool wifi_on_boot ;
128- esp_chip_info_t chip_info ;
129133 uint32_t stack_len ;
134+ uint8_t chip_rev = esp32_get_chip_rev ();
130135
131- esp_chip_info (& chip_info );
132- if (chip_info .revision > 0 ) {
136+ if (chip_rev > 0 ) {
133137 stack_len = (MICROPY_TASK_STACK_SIZE_PSRAM / sizeof (StackType_t ));
134138 } else {
135139 stack_len = (MICROPY_TASK_STACK_SIZE / sizeof (StackType_t ));
136140 }
137141
142+ boot_info_t boot_info_local ;
143+ uint32_t boot_info_offset_local ;
144+ bool ret = false;
145+ while (false == ret ) {
146+ ret = updater_read_boot_info (& boot_info_local , & boot_info_offset_local );
147+ }
148+ if (boot_info_local .ActiveImg != IMG_ACT_FACTORY ) {
149+ // Only copy if coming from older version (1.18.2) and this is not a downgrade
150+ // In case of upgrade the boot_info located under 0x190000 address
151+ // In case of a downgrade, the boot info located somewhere else than 0x190000 because of the updated partition table
152+ if (boot_info_offset_local == (uint32_t )OTA_DATA_ADDRESS_OLD ){
153+ printf ("Copying image from OTA_0 partition to Factory partition, please wait...\n" );
154+ if (true == update_to_factory_partition ()) {
155+ printf ("Image copy finished successfully!\n" );
156+ }
157+
158+ //Restart the system
159+ machine_wdt_start (100 );
160+ for ( ; ; );
161+ }
162+ }
163+
138164 // configure the antenna select switch here
139165 antenna_init0 ();
140166 config_init0 ();
@@ -157,7 +183,7 @@ void TASK_Micropython (void *pvParameters) {
157183 // to recover from hiting the limit (the limit is measured in bytes)
158184 mp_stack_set_limit (stack_len - 1024 );
159185
160- if (esp_get_revision () > 0 ) {
186+ if (esp32_get_chip_rev () > 0 ) {
161187 gc_pool_size = GC_POOL_SIZE_BYTES_PSRAM ;
162188 gc_pool_upy = heap_caps_malloc (GC_POOL_SIZE_BYTES_PSRAM , MALLOC_CAP_SPIRAM );
163189 } else {
0 commit comments