Skip to content

Commit cd409c6

Browse files
Matthieu CASTETdedekind
authored andcommitted
mtdoops: don't erase flash at each boot
The current version on mtdoops erase first block of mtdoops partition at each boot if there is no oops stored in flash. This can wear the flash. When mtdoops start, find_next_position is called to find the next free entry in the circular buffer. But if the flash is erased, find_next_position don't find anything (maxcount == 0xffffffff) and start with the first entry after erasing it. The scanning that is done in find_next_position already track free/used entries. So if at the end of the scanning we don't find anything, we can start at the first entry and erased the entry only if it is marked as used. Most of this is implemented in mtdoops_inc_counter, so to avoid duplicating code, if we don't find anything we set position to -1. mtdoops_inc_counter with increment it, erase the entry if needed and start as before with nextpage = 0 and nextcount = 1). Also during the scan phase, we use the MTDOOPS_KERNMSG_MAGIC to detect corruped entries. Signed-off-by: Matthieu Castet <matthieu.castet@parrot@com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
1 parent 7c8f680 commit cd409c6

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

‎drivers/mtd/mtdoops.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static void find_next_position(struct mtdoops_context *cxt)
271271

272272
if (count[0] == 0xffffffff && count[1] == 0xffffffff)
273273
mark_page_unused(cxt, page);
274-
if (count[0] == 0xffffffff)
274+
if (count[0] == 0xffffffff || count[1] != MTDOOPS_KERNMSG_MAGIC)
275275
continue;
276276
if (maxcount == 0xffffffff) {
277277
maxcount = count[0];
@@ -289,14 +289,13 @@ static void find_next_position(struct mtdoops_context *cxt)
289289
}
290290
}
291291
if (maxcount == 0xffffffff) {
292-
cxt->nextpage = 0;
293-
cxt->nextcount = 1;
294-
schedule_work(&cxt->work_erase);
295-
return;
292+
cxt->nextpage = cxt->oops_pages - 1;
293+
cxt->nextcount = 0;
294+
}
295+
else {
296+
cxt->nextpage = maxpos;
297+
cxt->nextcount = maxcount;
296298
}
297-
298-
cxt->nextpage = maxpos;
299-
cxt->nextcount = maxcount;
300299

301300
mtdoops_inc_counter(cxt);
302301
}

0 commit comments

Comments
 (0)