aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/mtdoops.c
diff options
context:
space:
mode:
authorMatthieu CASTET <matthieu.castet@parrot.com>2012-10-19 11:29:33 -0400
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-11-15 08:37:51 -0500
commitcd409c61287b81d432024c1dbfad292304bf5df3 (patch)
treea6d6abff1ddcb4b2a03b85dcb10d889d8e75d80c /drivers/mtd/mtdoops.c
parent7c8f680e96edbd9896b13b5e6ff39bc5852dce2a (diff)
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>
Diffstat (limited to 'drivers/mtd/mtdoops.c')
-rw-r--r--drivers/mtd/mtdoops.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index f5b3f91fa1cc..97bb8f6304d4 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -271,7 +271,7 @@ static void find_next_position(struct mtdoops_context *cxt)
271 271
272 if (count[0] == 0xffffffff && count[1] == 0xffffffff) 272 if (count[0] == 0xffffffff && count[1] == 0xffffffff)
273 mark_page_unused(cxt, page); 273 mark_page_unused(cxt, page);
274 if (count[0] == 0xffffffff) 274 if (count[0] == 0xffffffff || count[1] != MTDOOPS_KERNMSG_MAGIC)
275 continue; 275 continue;
276 if (maxcount == 0xffffffff) { 276 if (maxcount == 0xffffffff) {
277 maxcount = count[0]; 277 maxcount = count[0];
@@ -289,14 +289,13 @@ static void find_next_position(struct mtdoops_context *cxt)
289 } 289 }
290 } 290 }
291 if (maxcount == 0xffffffff) { 291 if (maxcount == 0xffffffff) {
292 cxt->nextpage = 0; 292 cxt->nextpage = cxt->oops_pages - 1;
293 cxt->nextcount = 1; 293 cxt->nextcount = 0;
294 schedule_work(&cxt->work_erase); 294 }
295 return; 295 else {
296 cxt->nextpage = maxpos;
297 cxt->nextcount = maxcount;
296 } 298 }
297
298 cxt->nextpage = maxpos;
299 cxt->nextcount = maxcount;
300 299
301 mtdoops_inc_counter(cxt); 300 mtdoops_inc_counter(cxt);
302} 301}