79
79
80
80
81
81
#include "lteppp.h"
82
+ #include "esp32chipinfo.h"
82
83
/******************************************************************************
83
84
DECLARE EXTERNAL FUNCTIONS
84
85
******************************************************************************/
@@ -90,6 +91,8 @@ extern void modpycom_init0(void);
90
91
#define GC_POOL_SIZE_BYTES (67 * 1024)
91
92
#define GC_POOL_SIZE_BYTES_PSRAM ((2048 + 512) * 1024)
92
93
94
+ #define OTA_DATA_ADDRESS_OLD (0x190000)
95
+
93
96
/******************************************************************************
94
97
DECLARE PRIVATE FUNCTIONS
95
98
******************************************************************************/
@@ -116,6 +119,8 @@ static uint8_t *gc_pool_upy;
116
119
static char fresh_main_py [] = "# main.py -- put your code here!\r\n" ;
117
120
static char fresh_boot_py [] = "# boot.py -- run on boot-up\r\n" ;
118
121
122
+ extern bool update_to_factory_partition (void );
123
+
119
124
/******************************************************************************
120
125
DEFINE PUBLIC FUNCTIONS
121
126
******************************************************************************/
@@ -125,16 +130,37 @@ void TASK_Micropython (void *pvParameters) {
125
130
uint32_t gc_pool_size ;
126
131
bool soft_reset = false;
127
132
bool wifi_on_boot ;
128
- esp_chip_info_t chip_info ;
129
133
uint32_t stack_len ;
134
+ uint8_t chip_rev = esp32_get_chip_rev ();
130
135
131
- esp_chip_info (& chip_info );
132
- if (chip_info .revision > 0 ) {
136
+ if (chip_rev > 0 ) {
133
137
stack_len = (MICROPY_TASK_STACK_SIZE_PSRAM / sizeof (StackType_t ));
134
138
} else {
135
139
stack_len = (MICROPY_TASK_STACK_SIZE / sizeof (StackType_t ));
136
140
}
137
141
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
+
138
164
// configure the antenna select switch here
139
165
antenna_init0 ();
140
166
config_init0 ();
@@ -157,7 +183,7 @@ void TASK_Micropython (void *pvParameters) {
157
183
// to recover from hiting the limit (the limit is measured in bytes)
158
184
mp_stack_set_limit (stack_len - 1024 );
159
185
160
- if (esp_get_revision () > 0 ) {
186
+ if (esp32_get_chip_rev () > 0 ) {
161
187
gc_pool_size = GC_POOL_SIZE_BYTES_PSRAM ;
162
188
gc_pool_upy = heap_caps_malloc (GC_POOL_SIZE_BYTES_PSRAM , MALLOC_CAP_SPIRAM );
163
189
} else {
0 commit comments