forked from arduino-libraries/Arduino_CloudUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC33FlashFormatter.cpp
74 lines (60 loc) · 1.5 KB
/
C33FlashFormatter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
Copyright (c) 2025 Arduino SA
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#if defined(ARDUINO_PORTENTA_C33)
#include "C33FlashFormatter.h"
#define BD_ERROR_OK 0
C33FlashFormatter::C33FlashFormatter():
_root(BlockDevice::get_default_instance()),
_sys_bd(_root, 1),
_sys_fs("sys"),
_user_bd(_root, 2),
_kvStore_bd(_root, 3) {
}
bool C33FlashFormatter::checkPartition()
{
if (_root->init() != BD_ERROR_OK)
{
return false;
}
if (_sys_bd.init() != BD_ERROR_OK || _sys_fs.mount(&_sys_bd) != FR_OK)
{
return false;
}
_sys_fs.unmount();
_sys_bd.deinit();
if (_user_bd.init() != BD_ERROR_OK)
{
return false;
}
_user_bd.deinit();
if (_kvStore_bd.init() != BD_ERROR_OK)
{
return false;
}
_kvStore_bd.deinit();
_root->deinit();
return true;
}
bool C33FlashFormatter::formatPartition() {
MBRBlockDevice::partition(_root, 1, 0x0B, 0, 5 * 1024 * 1024);
MBRBlockDevice::partition(_root, 2, 0x0B, 5 * 1024 * 1024, 15 * 1024 * 1024);
MBRBlockDevice::partition(_root, 3, 0x0B, 15 * 1024 * 1024, 16 * 1024 * 1024);
int err = _sys_fs.reformat(&_sys_bd);
if (err) {
return false;
}
_sys_fs.unmount();
_user_data_fs = new LittleFileSystem("user");
err = _user_data_fs->reformat(&_user_bd);
if (err) {
return false;
}
_user_data_fs->unmount();
_root->deinit();
return true;
}
#endif