[PATCH] mtdoops : don't erase flash at each boot

Matthieu CASTET matthieu.castet at parrot.com
Tue Nov 13 04:56:41 EST 2012

Artem Bityutskiy a écrit :
> On Fri, 2012-10-19 at 17:29 +0200, Matthieu CASTET wrote:
>> If there is no oops stored (flash is erased), find_next_position will
>> exit with maxcount == 0xffffffff and erase the first page.
>> Only erase it if mark_is_used.
>> Signed-off-by: Matthieu Castet <matthieu.castet at parrot@com>
> The code of mtdoops is really hard to read. Could you please provide a
> better commit message with better description about what you do:
> 1. what problem you fix exactly, and why is it a problem
> 2. how the code currently works
> 3. how you change it to make the problem go away
> Thanks!

Is the following changelog ok ?

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

More information about the linux-mtd mailing list