Skip to content

Commit 91b81cc

Browse files
committed
SSLClient: CertificateUploader, store certificates in system partition
Former-commit-id: a45bc59
1 parent cc8fdd6 commit 91b81cc

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

libraries/SSLClient/examples/CertificateUploader/CertificateUploader.ino

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
#include "QSPIFlashBlockDevice.h"
1+
/*
2+
Portenta C33 - Certificate uploader
3+
4+
The sketch uploads and saves network certificates on the system
5+
partition of the QSPI flash
6+
7+
This example code is in the public domain.
8+
*/
9+
10+
#include "BlockDevice.h"
11+
#include "MBRBlockDevice.h"
212
#include "FATFileSystem.h"
313
#include "certificates.h"
414

5-
QSPIFlashBlockDevice root(PIN_QSPI_CLK, PIN_QSPI_SS, PIN_QSPI_D0, PIN_QSPI_D1, PIN_QSPI_D2, PIN_QSPI_D3);
6-
FATFileSystem root_fs("wlan");
15+
BlockDevice* root = BlockDevice::get_default_instance();
16+
MBRBlockDevice sys_bd(root, 1);
17+
FATFileSystem sys_fs("sys");
718

819
long getFileSize(FILE *fp) {
920
fseek(fp, 0, SEEK_END);
@@ -32,33 +43,33 @@ void setup() {
3243
Serial.begin(115200);
3344
while (!Serial);
3445

35-
int err = root_fs.mount(&root);
46+
int err = sys_fs.mount(&sys_bd);
3647
if (err) {
3748
// Reformat if we can't mount the filesystem
3849
// this should only happen on the first boot
3950
Serial.println("No filesystem containing the WiFi firmware was found.");
4051
Serial.println("Usually that means that the WiFi firmware has not been installed yet"
4152
" or was overwritten with another firmware.\n");
4253
Serial.println("Formatting the filsystem to install the firmware and certificates...\n");
43-
err = root_fs.reformat(&root);
54+
err = sys_fs.reformat(&sys_bd);
4455
}
4556

4657
DIR *dir;
4758
struct dirent *ent;
4859

49-
if ((dir = opendir("/wlan")) != NULL) {
60+
if ((dir = opendir("/sys")) != NULL) {
5061
/* print all the files and directories within directory */
5162
while ((ent = readdir (dir)) != NULL) {
5263
Serial.println("Searching for WiFi firmware file " + String(ent->d_name) + " ...");
53-
String fullname = "/wlan/" + String(ent->d_name);
54-
if (fullname == "/wlan/cacert.pem") {
64+
String fullname = "/sys/" + String(ent->d_name);
65+
if (fullname == "/sys/cacert.pem") {
5566
Serial.println("A WiFi firmware is already installed. "
5667
"Do you want to install the firmware anyway? Y/[n]");
5768
while (1) {
5869
if (Serial.available()) {
5970
int c = Serial.read();
6071
if (c == 'Y' || c == 'y') {
61-
root_fs.reformat(&root);
72+
sys_fs.reformat(&sys_bd);
6273
break;
6374
}
6475
if (c == 'N' || c == 'n') {
@@ -76,7 +87,7 @@ void setup() {
7687

7788
int chunck_size = 128;
7889
int byte_count = 0;
79-
FILE* fp = fopen("/wlan/cacert.pem", "wb");
90+
FILE* fp = fopen("/sys/cacert.pem", "wb");
8091

8192
Serial.println("Flashing certificates");
8293
printProgress(byte_count, cacert_pem_len, 10, true);
@@ -93,7 +104,7 @@ void setup() {
93104
}
94105
fclose(fp);
95106

96-
fp = fopen("/wlan/cacert.pem", "rb");
107+
fp = fopen("/sys/cacert.pem", "rb");
97108
char buffer[128];
98109
int ret = fread(buffer, 1, 128, fp);
99110
Serial.write(buffer, ret);

0 commit comments

Comments
 (0)