Newer
Older
Tardis / src / FlashErase.cpp
@Jookia Jookia 22 days ago 954 bytes Bump copyright year
/*
SPDX-License-Identifier: MIT
Copyright (c) 2024 Casey Reeves and the LuminaSensum contributors
*/

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

#include "mbed-trace/mbed_trace.h"
#define TRACE_GROUP "FLER"

// function to erase the flash
int doErase(mbed::BlockDevice &bd) {
	tr_info("Initializing the block device... ");
	fflush(stdout);
	int err = bd.init();
	tr_info("%s", (err ? "Fail :(" : "OK"));
	if (err) {
		tr_err("error: %s (%d)", strerror(-err), err);
		return err;
	}

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

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