Skip to content

Commit 2d0c08f

Browse files
committed
Add check on PLC runtime partition
1 parent 0209caa commit 2d0c08f

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

src/flashFormatter/FlashFormatterQSPI.cpp

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,31 @@ _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

2225
bool FlashFormatterQSPI::checkPartition()
2326
{
2427
if (_root->init() != BD_ERROR_OK) {
28+
_runtimeFormat = true;
2529
return false;
2630
}
2731

32+
/* check PLC runtime partition. This should be performed as first check to
33+
* correctly set the _runtimeFormat flag.
34+
*/
35+
_runtimeFormat = false;
36+
if (_runtimeData.init() != BD_ERROR_OK) {
37+
_runtimeFormat = true;
38+
return false;
39+
}
40+
_runtimeData.deinit();
41+
42+
/* check WiFi partition */
2843
if (_wifiData.init() != BD_ERROR_OK || _wifiFS.mount(&_wifiData) != 0) {
2944
return false;
3045
}
@@ -36,6 +51,7 @@ bool FlashFormatterQSPI::checkPartition()
3651
_wifiFS.unmount();
3752
_wifiData.deinit();
3853

54+
/* check OTA partition */
3955
if (_otaData.init() != BD_ERROR_OK || _otaFS.mount(&_otaData) != 0) {
4056
return false;
4157
}
@@ -47,39 +63,56 @@ bool FlashFormatterQSPI::checkPartition()
4763
_otaFS.unmount();
4864
_otaData.deinit();
4965

66+
/* check KVStore partition */
5067
if (_kvstoreData.init() != BD_ERROR_OK) {
5168
return false;
5269
}
5370

5471
if (_kvstoreData.size() < 1 * 1024 * 1024) {
5572
return false;
5673
}
57-
5874
_kvstoreData.deinit();
75+
5976
_root->deinit();
6077
return true;
6178
}
6279

6380
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);
6881

69-
if (_wifiFS.reformat(&_wifiData) != 0) {
82+
if (_root->init() != BD_ERROR_OK) {
7083
return false;
7184
}
7285

73-
if (_otaFS.reformat(&_otaData) != 0) {
86+
if (_root->erase(0x0, _root->get_erase_size()) != BD_ERROR_OK) {
7487
return false;
7588
}
7689

77-
if (!restoreWifiData()) {
90+
MBRBlockDevice::partition(_root, 1, 0x0B, 0, 1 * 1024 * 1024);
91+
if (_wifiFS.reformat(&_wifiData) != 0) {
7892
return false;
7993
}
8094

95+
if (!restoreWifiData()) {
96+
return false;
97+
}
8198
_wifiFS.unmount();
99+
100+
MBRBlockDevice::partition(_root, 2, 0x0B, 1 * 1024 * 1024, 6 * 1024 * 1024);
101+
if (_otaFS.reformat(&_otaData) != 0) {
102+
return false;
103+
}
82104
_otaFS.unmount();
105+
106+
MBRBlockDevice::partition(_root, 3, 0x0B, 6 * 1024 * 1024, 7 * 1024 * 1024);
107+
108+
if (_runtimeFormat) {
109+
MBRBlockDevice::partition(_root, 4, 0x0B, 7 * 1024 * 1024, 14 * 1024 * 1024);
110+
if (_runtimeFS.reformat(&_runtimeData) != 0) {
111+
return false;
112+
}
113+
_runtimeFS.unmount();
114+
}
115+
83116
_root->deinit();
84117

85118
return true;

src/flashFormatter/FlashFormatterQSPI.h

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

0 commit comments

Comments
 (0)