Skip to content

Commit fc6faff

Browse files
committed
Add check on PLC runtime partition
1 parent a54137b commit fc6faff

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/flashFormatter/FlashFormatterQSPI.cpp

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ _wifiData(_root, 1),
1515
_wifiFS("wlan"),
1616
_otaData(_root, 2),
1717
_otaFS("fs"),
18-
_kvstoreData(_root, 3)
18+
_kvstoreData(_root, 3),
19+
_runtimeData(_root, 4),
20+
_runtimeFS("opt"),
21+
_runtimeFormat(false)
1922
{
2023
}
2124

@@ -25,6 +28,7 @@ bool FlashFormatterQSPI::checkPartition()
2528
return false;
2629
}
2730

31+
/* check WiFi partition */
2832
if (_wifiData.init() != BD_ERROR_OK || _wifiFS.mount(&_wifiData) != 0) {
2933
return false;
3034
}
@@ -36,6 +40,7 @@ bool FlashFormatterQSPI::checkPartition()
3640
_wifiFS.unmount();
3741
_wifiData.deinit();
3842

43+
/* check OTA partition */
3944
if (_otaData.init() != BD_ERROR_OK || _otaFS.mount(&_otaData) != 0) {
4045
return false;
4146
}
@@ -47,39 +52,63 @@ bool FlashFormatterQSPI::checkPartition()
4752
_otaFS.unmount();
4853
_otaData.deinit();
4954

55+
/* check KVStore partition */
5056
if (_kvstoreData.init() != BD_ERROR_OK) {
5157
return false;
5258
}
5359

5460
if (_kvstoreData.size() < 1 * 1024 * 1024) {
5561
return false;
5662
}
57-
5863
_kvstoreData.deinit();
64+
65+
/* check PLC runtime partition */
66+
if (_runtimeData.init() != BD_ERROR_OK) {
67+
_runtimeFormat = true;
68+
return false;
69+
}
70+
_runtimeData.deinit();
71+
5972
_root->deinit();
6073
return true;
6174
}
6275

6376
bool FlashFormatterQSPI::formatPartition() {
64-
_root->erase(0x0, _root->get_erase_size());
65-
MBRBlockDevice::partition(_root, 1, 0x0B, 0, 1 * 1024 * 1024);
66-
MBRBlockDevice::partition(_root, 2, 0x0B, 1 * 1024 * 1024, 6 * 1024 * 1024);
67-
MBRBlockDevice::partition(_root, 3, 0x0B, 6 * 1024 * 1024, 7 * 1024 * 1024);
6877

69-
if (_wifiFS.reformat(&_wifiData) != 0) {
78+
if (_root->init() != BD_ERROR_OK) {
7079
return false;
7180
}
7281

73-
if (_otaFS.reformat(&_otaData) != 0) {
82+
if (_root->erase(0x0, _root->get_erase_size()) != BD_ERROR_OK) {
7483
return false;
7584
}
7685

77-
if (!restoreWifiData()) {
86+
MBRBlockDevice::partition(_root, 1, 0x0B, 0, 1 * 1024 * 1024);
87+
if (_wifiFS.reformat(&_wifiData) != 0) {
7888
return false;
7989
}
8090

91+
if (!restoreWifiData()) {
92+
return false;
93+
}
8194
_wifiFS.unmount();
95+
96+
MBRBlockDevice::partition(_root, 2, 0x0B, 1 * 1024 * 1024, 6 * 1024 * 1024);
97+
if (_otaFS.reformat(&_otaData) != 0) {
98+
return false;
99+
}
82100
_otaFS.unmount();
101+
102+
MBRBlockDevice::partition(_root, 3, 0x0B, 6 * 1024 * 1024, 7 * 1024 * 1024);
103+
104+
if (_runtimeFormat) {
105+
MBRBlockDevice::partition(_root, 4, 0x0B, 7 * 1024 * 1024, 14 * 1024 * 1024);
106+
if (_runtimeFS.reformat(&_runtimeData) != 0) {
107+
return false;
108+
}
109+
_runtimeFS.unmount();
110+
}
111+
83112
_root->deinit();
84113

85114
return true;

src/flashFormatter/FlashFormatterQSPI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@ class FlashFormatterQSPI : public FlashFormatterBase {
3636
MBRBlockDevice _otaData;
3737
FATFileSystem _otaFS;
3838
MBRBlockDevice _kvstoreData;
39+
MBRBlockDevice _runtimeData;
40+
FATFileSystem _runtimeFS;
41+
bool _runtimeFormat;
3942
};
4043

0 commit comments

Comments
 (0)