@@ -15,16 +15,31 @@ _wifiData(_root, 1),
15
15
_wifiFS(" wlan" ),
16
16
_otaData(_root, 2 ),
17
17
_otaFS(" fs" ),
18
- _kvstoreData(_root, 3 )
18
+ _kvstoreData(_root, 3 ),
19
+ _runtimeData(_root, 4 ),
20
+ _runtimeFS(" opt" ),
21
+ _runtimeFormat(false )
19
22
{
20
23
}
21
24
22
25
bool FlashFormatterQSPI::checkPartition ()
23
26
{
24
27
if (_root->init () != BD_ERROR_OK) {
28
+ _runtimeFormat = true ;
25
29
return false ;
26
30
}
27
31
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 */
28
43
if (_wifiData.init () != BD_ERROR_OK || _wifiFS.mount (&_wifiData) != 0 ) {
29
44
return false ;
30
45
}
@@ -36,6 +51,7 @@ bool FlashFormatterQSPI::checkPartition()
36
51
_wifiFS.unmount ();
37
52
_wifiData.deinit ();
38
53
54
+ /* check OTA partition */
39
55
if (_otaData.init () != BD_ERROR_OK || _otaFS.mount (&_otaData) != 0 ) {
40
56
return false ;
41
57
}
@@ -47,39 +63,56 @@ bool FlashFormatterQSPI::checkPartition()
47
63
_otaFS.unmount ();
48
64
_otaData.deinit ();
49
65
66
+ /* check KVStore partition */
50
67
if (_kvstoreData.init () != BD_ERROR_OK) {
51
68
return false ;
52
69
}
53
70
54
71
if (_kvstoreData.size () < 1 * 1024 * 1024 ) {
55
72
return false ;
56
73
}
57
-
58
74
_kvstoreData.deinit ();
75
+
59
76
_root->deinit ();
60
77
return true ;
61
78
}
62
79
63
80
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 );
68
81
69
- if (_wifiFS. reformat (&_wifiData ) != 0 ) {
82
+ if (_root-> init ( ) != BD_ERROR_OK ) {
70
83
return false ;
71
84
}
72
85
73
- if (_otaFS. reformat (&_otaData) != 0 ) {
86
+ if (_root-> erase ( 0x0 , _root-> get_erase_size ()) != BD_ERROR_OK ) {
74
87
return false ;
75
88
}
76
89
77
- if (!restoreWifiData ()) {
90
+ MBRBlockDevice::partition (_root, 1 , 0x0B , 0 , 1 * 1024 * 1024 );
91
+ if (_wifiFS.reformat (&_wifiData) != 0 ) {
78
92
return false ;
79
93
}
80
94
95
+ if (!restoreWifiData ()) {
96
+ return false ;
97
+ }
81
98
_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
+ }
82
104
_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
+
83
116
_root->deinit ();
84
117
85
118
return true ;
0 commit comments