Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit edeaf3d

Browse filesBrowse files
committed
QSPIFormat: add option to restore WiFi firmware and certificates
1 parent 236ea5c commit edeaf3d
Copy full SHA for edeaf3d

File tree

2 files changed

+70
-1
lines changed
Filter options

2 files changed

+70
-1
lines changed

‎libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino

Copy file name to clipboardExpand all lines: libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino
+69-1Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "MBRBlockDevice.h"
33
#include "LittleFileSystem.h"
44
#include "FATFileSystem.h"
5+
#include "wiced_resource.h"
6+
#include "certificates.h"
57

68
#ifndef CORE_CM7
79
#error Format QSPI flash by uploading the sketch to the M7 core instead of the M4 core.
@@ -41,6 +43,20 @@ bool waitResponse() {
4143
}
4244
}
4345

46+
void printProgress(uint32_t offset, uint32_t size, uint32_t threshold, bool reset) {
47+
static int percent_done = 0;
48+
if (reset == true) {
49+
percent_done = 0;
50+
Serial.println("Flashed " + String(percent_done) + "%");
51+
} else {
52+
uint32_t percent_done_new = offset * 100 / size;
53+
if (percent_done_new >= percent_done + threshold) {
54+
percent_done = percent_done_new;
55+
Serial.println("Flashed " + String(percent_done) + "%");
56+
}
57+
}
58+
}
59+
4460
void setup() {
4561

4662
Serial.begin(115200);
@@ -68,7 +84,6 @@ void setup() {
6884
// use space from 15.5MB to 16 MB for another fw, memory mapped
6985

7086
bool reformat = true;
71-
7287
if(!wifi_data_fs.mount(&wifi_data)) {
7388
Serial.println("\nPartition 1 already contains a filesystem, do you want to reformat it? Y/[n]");
7489
wifi_data_fs.unmount();
@@ -81,6 +96,16 @@ void setup() {
8196
return;
8297
}
8398

99+
bool restore = true;
100+
if (reformat) {
101+
Serial.println("\nDo you want to restore the WiFi firmware and certificates? Y/[n]");
102+
restore = waitResponse();
103+
}
104+
105+
if (reformat && restore) {
106+
flashWiFiFirmwareAndCertificates();
107+
}
108+
84109
reformat = true;
85110
if(!ota_data_fs.mount(&ota_data)) {
86111
Serial.println("\nPartition 2 already contains a filesystem, do you want to reformat it? Y/[n]");
@@ -124,6 +149,49 @@ void setup() {
124149
Serial.println("It's now safe to reboot or disconnect your board.");
125150
}
126151

152+
void flashWiFiFirmwareAndCertificates() {
153+
extern const unsigned char wifi_firmware_image_data[];
154+
extern const resource_hnd_t wifi_firmware_image;
155+
FILE* fp = fopen("/wlan/4343WA1.BIN", "wb");
156+
const int file_size = 421098;
157+
int chunck_size = 1024;
158+
int byte_count = 0;
159+
160+
Serial.println("Flashing WiFi firmware");
161+
printProgress(byte_count, file_size, 10, true);
162+
while (byte_count < file_size) {
163+
if(byte_count + chunck_size > file_size)
164+
chunck_size = file_size - byte_count;
165+
int ret = fwrite(&wifi_firmware_image_data[byte_count], chunck_size, 1, fp);
166+
if (ret != 1) {
167+
Serial.println("Error writing firmware data");
168+
break;
169+
}
170+
byte_count += chunck_size;
171+
printProgress(byte_count, file_size, 10, false);
172+
}
173+
fclose(fp);
174+
175+
fp = fopen("/wlan/cacert.pem", "wb");
176+
177+
Serial.println("Flashing certificates");
178+
chunck_size = 128;
179+
byte_count = 0;
180+
printProgress(byte_count, cacert_pem_len, 10, true);
181+
while (byte_count < cacert_pem_len) {
182+
if(byte_count + chunck_size > cacert_pem_len)
183+
chunck_size = cacert_pem_len - byte_count;
184+
int ret = fwrite(&cacert_pem[byte_count], chunck_size, 1 ,fp);
185+
if (ret != 1) {
186+
Serial.println("Error writing certificates");
187+
break;
188+
}
189+
byte_count += chunck_size;
190+
printProgress(byte_count, cacert_pem_len, 10, false);
191+
}
192+
fclose(fp);
193+
}
194+
127195
void loop() {
128196

129197
}
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../WiFiFirmwareUpdater/certificates.h

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.