@@ -79,8 +79,12 @@ void setup() {
79
79
}
80
80
81
81
Serial.println (" Do you want to perform a full erase of the QSPI flash before proceeding? Y/[n]" );
82
- if (true == waitResponse ()) {
82
+ Serial.println (" Note: Full flash erase can take up to one minute." );
83
+ bool fullErase = waitResponse ();
84
+ if (fullErase == true ) {
85
+ Serial.println (" Full erase started, please wait..." );
83
86
root->erase (0x0 , root->size ());
87
+ Serial.println (" Full erase completed." );
84
88
} else {
85
89
// Erase only the first sector containing the MBR
86
90
root->erase (0x0 , root->get_erase_size ());
@@ -93,7 +97,7 @@ void setup() {
93
97
// use space from 15.5MB to 16 MB for another fw, memory mapped
94
98
95
99
bool reformat = true ;
96
- if (!wifi_data_fs.mount (&wifi_data)) {
100
+ if (!wifi_data_fs.mount (&wifi_data)) {
97
101
Serial.println (" \n Partition 1 already contains a filesystem, do you want to reformat it? Y/[n]" );
98
102
wifi_data_fs.unmount ();
99
103
@@ -106,7 +110,7 @@ void setup() {
106
110
}
107
111
108
112
bool restore = true ;
109
- if (reformat) {
113
+ if (reformat || fullErase ) {
110
114
Serial.println (" \n Do you want to restore the WiFi firmware and certificates? Y/[n]" );
111
115
restore = waitResponse ();
112
116
}
@@ -115,8 +119,12 @@ void setup() {
115
119
flashWiFiFirmwareAndCertificates ();
116
120
}
117
121
122
+ if (fullErase && restore) {
123
+ flashWiFiFirmwareMapped ();
124
+ }
125
+
118
126
reformat = true ;
119
- if (!ota_data_fs.mount (&ota_data)) {
127
+ if (!ota_data_fs.mount (&ota_data)) {
120
128
Serial.println (" \n Partition 2 already contains a filesystem, do you want to reformat it? Y/[n]" );
121
129
ota_data_fs.unmount ();
122
130
@@ -140,7 +148,7 @@ void setup() {
140
148
}
141
149
142
150
reformat = true ;
143
- if (!user_data_fs->mount (&user_data)) {
151
+ if (!user_data_fs->mount (&user_data)) {
144
152
Serial.println (" \n Partition 4 already contains a filesystem, do you want to reformat it? Y/[n]" );
145
153
user_data_fs->unmount ();
146
154
@@ -158,10 +166,11 @@ void setup() {
158
166
Serial.println (" It's now safe to reboot or disconnect your board." );
159
167
}
160
168
169
+ const uint32_t file_size = 421098 ;
170
+ extern const unsigned char wifi_firmware_image_data[];
171
+
161
172
void flashWiFiFirmwareAndCertificates () {
162
- extern const unsigned char wifi_firmware_image_data[];
163
173
FILE* fp = fopen (" /wlan/4343WA1.BIN" , " wb" );
164
- const uint32_t file_size = 421098 ;
165
174
uint32_t chunck_size = 1024 ;
166
175
uint32_t byte_count = 0 ;
167
176
@@ -200,6 +209,26 @@ void flashWiFiFirmwareAndCertificates() {
200
209
fclose (fp);
201
210
}
202
211
212
+ void flashWiFiFirmwareMapped () {
213
+ uint32_t chunck_size = 1024 ;
214
+ uint32_t byte_count = 0 ;
215
+ const uint32_t offset = 15 * 1024 * 1024 + 1024 * 512 ;
216
+
217
+ Serial.println (" Flashing memory mapped WiFi firmware" );
218
+ printProgress (byte_count, file_size, 10 , true );
219
+ while (byte_count < file_size) {
220
+ if (byte_count + chunck_size > file_size)
221
+ chunck_size = file_size - byte_count;
222
+ int ret = root->program (wifi_firmware_image_data, offset + byte_count, chunck_size);
223
+ if (ret != 0 ) {
224
+ Serial.println (" Error writing memory mapped firmware" );
225
+ break ;
226
+ }
227
+ byte_count += chunck_size;
228
+ printProgress (byte_count, file_size, 10 , false );
229
+ }
230
+ }
231
+
203
232
void loop () {
204
233
205
234
}
0 commit comments