Newer
Older
Tardis / src / FlashErase.cpp
/*
SPDX-License-Identifier: MIT
Copyright (c) 2023 Casey Reeves and the LuminaSensum contributors
*/

#include "FlashErase.h"
#include "mbed.h"
#include <errno.h>
#include <functional>

// function to erase the flash
void doErase(mbed::BlockDevice &bd, LittleFileSystem2 &fs) {
	// Try to unmount the filesystem
	unmountFilesystem(bd, fs);
	printf("Initializing the block device... ");
	fflush(stdout);
	int err = bd.init();
	printf("%s\n", (err ? "Fail :(" : "OK"));
	if (err) {
		error("error: %s (%d)\n", strerror(-err), err);
	}

	printf("Erasing the block device... ");
	fflush(stdout);
	err = bd.erase(0, bd.size());
	printf("%s\n", (err ? "Fail :(" : "OK"));
	if (err) {
		error("error: %s (%d)\n", strerror(-err), err);
	}

	printf("Deinitializing the block device... ");
	fflush(stdout);
	err = bd.deinit();
	printf("%s\n", (err ? "Fail :(" : "OK"));
	if (err) {
		error("error: %s (%d)\n", strerror(-err), err);
	}
}