Skip to content

Flash formatter fix #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions examples/flashFormatter/flashFormatter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,59 @@ void setup() {
Serial.begin(9600);
while(!Serial);

if(!flashFormatter.checkandFormatPartition()){
Serial.println("Failed to format partition");
} else {
Serial.println("Partition formatted successfully");
/* WARNING! Running this sketch all the content of the QSPI flash may be erased.
* The sketch will check if the QSPI flash is formatted with an ArduinoCloud
* compatible partitioning. Otherwise, it will format the QSPI flash with the
* default scheme.
*
* If you want to keep the content of the QSPI flash, do not run this sketch.
*
* ArduinoCloud compatible partitioning consist of:
* - 1st partition: WiFi firmware and certificates
* - 2nd partition: OTA data. Minimum size 5MB.
* - 3rd partition: Key Value Store data. Minimum size 1MB.
*/

Serial.println("\nWARNING! Running this sketch all the content of the QSPI flash may be erased.");
Serial.println("Do you want to proceed? Y/[n]");

if (true == waitResponse()) {
if(!flashFormatter.checkAndFormatPartition()){
Serial.println("Failed to check / format flash");
} else {
Serial.println("Flash checked / formatted successfully");
}
}
else {
Serial.println("Operation canceled");
}

Serial.println("It's now safe to reboot or disconnect your board.");
}

void loop() { }

bool waitResponse() {
bool confirmation = false;
bool proceed = false;
while (confirmation == false) {
if (Serial.available()) {
char choice = Serial.read();
switch (choice) {
case 'y':
case 'Y':
confirmation = true;
proceed = true;
break;
case 'n':
case 'N':
confirmation = true;
proceed = false;
break;
default:
continue;
}
}
}
return proceed;
}
2 changes: 1 addition & 1 deletion src/flashFormatter/FlashFormatterBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class FlashFormatterClass {
public:
virtual ~FlashFormatterClass() = default;
virtual bool checkandFormatPartition() {
virtual bool checkAndFormatPartition() {
if(checkPartition()){
return true;
}
Expand Down
10 changes: 10 additions & 0 deletions src/flashFormatter/H7FlashFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,19 @@ bool MBEDH7FlashFormatter::checkPartition()

bool MBEDH7FlashFormatter::formatPartition() {
_root->erase(0x0, _root->get_erase_size());
/* Default partitioning of OPTA boards includes a 4th partition for PLC ide runtime
* This partition is not used in the context of ArduinoCloud and is not needed,
* but we try to preserve the default partitioning for compatibility.
*/
#if defined(ARDUINO_OPTA)
mbed::MBRBlockDevice::partition(_root, 1, 0x0B, 0, 1024 * 1024);
mbed::MBRBlockDevice::partition(_root, 2, 0x0B, 1024 * 1024, 6 * 1024 * 1024);
mbed::MBRBlockDevice::partition(_root, 3, 0x0B, 6 * 1024 * 1024, 7 * 1024 * 1024);
#else
mbed::MBRBlockDevice::partition(_root, 1, 0x0B, 0, 1024 * 1024);
mbed::MBRBlockDevice::partition(_root, 2, 0x0B, 1024 * 1024, 13 * 1024 * 1024);
mbed::MBRBlockDevice::partition(_root, 3, 0x0B, 13 * 1024 * 1024, 14 * 1024 * 1024);
#endif

if(_ota_data_fs.mount(&_ota_data) != 0) {
if(_ota_data_fs.reformat(&_ota_data) != 0) {
Expand Down
Loading