summaryrefslogtreecommitdiff
path: root/flash.c
diff options
context:
space:
mode:
Diffstat (limited to 'flash.c')
-rw-r--r--flash.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/flash.c b/flash.c
index 9aaef45..d371c39 100644
--- a/flash.c
+++ b/flash.c
@@ -307,6 +307,19 @@ hdrlengthok:
}
+
+void remount_root_as_writeable ()
+{
+ system("/usr/bin/mount -o remount,rw /dev/mmcblk03 /");
+}
+
+
+void remount_root_as_not_writeable ()
+{
+ system("/usr/bin/mount -o remount,ro /dev/mmcblk03 /");
+}
+
+
static int readUserBlock(FlashStruct *mem)
{
@@ -329,8 +342,12 @@ static int readUserBlock(FlashStruct *mem)
// if the backup was good overwrite the main file
if (!globals.Sys.shutdown_started) {
globals.Sys.flash_write_in_progress = TRUE;
+ remount_root_as_writeable ();
+
persistence_copyfile(BACKUPFILE, MAINFILE);
+
globals.Sys.flash_write_in_progress = FALSE;
+ remount_root_as_not_writeable ();
}
return sizeof(*mem);
}
@@ -359,11 +376,17 @@ void writeUserBlockNow(FlashStruct *mem, int addr, int numbytes)
if (!globals.Sys.shutdown_started) {
globals.Sys.flash_write_in_progress = TRUE;
+ remount_root_as_writeable ();
+
bool backup_ok = persistence_copyfile(MAINFILE, BACKUPFILE);
+
globals.Sys.flash_write_in_progress = FALSE;
+ remount_root_as_not_writeable ();
if (backup_ok && !globals.Sys.shutdown_started) {
+
globals.Sys.flash_write_in_progress = TRUE;
+ remount_root_as_writeable ();
if (!persistence_freeze(MAINFILE, mem, addr, numbytes, sizeof(*mem), 0)) {
if (errno != PERSIST_ERR_COULDNTWRITE) {
@@ -373,6 +396,7 @@ void writeUserBlockNow(FlashStruct *mem, int addr, int numbytes)
}
}
globals.Sys.flash_write_in_progress = FALSE;
+ remount_root_as_not_writeable ();
} else {
printf("Could not backup current file. **Write did not happen!!!**\n");
}