Commit f0482ee3 authored by Richard Purdie's avatar Richard Purdie Committed by David Woodhouse

[MTD] mtdoops: Add a magic number to logged kernel oops

Add a magic number to logged kernel oops messages so that they
can be more accurately detected rather than just having to rely
on the sequence number. This also allows easier detection of
saved crashes by userspace.
Signed-off-by: default avatarRichard Purdie <rpurdie@rpsys.net>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent ecd5b310
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/mtd/mtd.h> #include <linux/mtd/mtd.h>
#define MTDOOPS_KERNMSG_MAGIC 0x5d005d00
#define OOPS_PAGE_SIZE 4096 #define OOPS_PAGE_SIZE 4096
static struct mtdoops_context { static struct mtdoops_context {
...@@ -224,31 +225,33 @@ static void find_next_position(struct mtdoops_context *cxt) ...@@ -224,31 +225,33 @@ static void find_next_position(struct mtdoops_context *cxt)
{ {
struct mtd_info *mtd = cxt->mtd; struct mtd_info *mtd = cxt->mtd;
int ret, page, maxpos = 0; int ret, page, maxpos = 0;
u32 count, maxcount = 0xffffffff; u32 count[2], maxcount = 0xffffffff;
size_t retlen; size_t retlen;
for (page = 0; page < cxt->oops_pages; page++) { for (page = 0; page < cxt->oops_pages; page++) {
ret = mtd->read(mtd, page * OOPS_PAGE_SIZE, 4, &retlen, (u_char *) &count); ret = mtd->read(mtd, page * OOPS_PAGE_SIZE, 8, &retlen, (u_char *) &count[0]);
if ((retlen != 4) || ((ret < 0) && (ret != -EUCLEAN))) { if ((retlen != 8) || ((ret < 0) && (ret != -EUCLEAN))) {
printk(KERN_ERR "mtdoops: Read failure at %d (%td of 4 read)" printk(KERN_ERR "mtdoops: Read failure at %d (%td of 8 read)"
", err %d.\n", page * OOPS_PAGE_SIZE, retlen, ret); ", err %d.\n", page * OOPS_PAGE_SIZE, retlen, ret);
continue; continue;
} }
if (count == 0xffffffff) if (count[1] != MTDOOPS_KERNMSG_MAGIC)
continue;
if (count[0] == 0xffffffff)
continue; continue;
if (maxcount == 0xffffffff) { if (maxcount == 0xffffffff) {
maxcount = count; maxcount = count[0];
maxpos = page; maxpos = page;
} else if ((count < 0x40000000) && (maxcount > 0xc0000000)) { } else if ((count[0] < 0x40000000) && (maxcount > 0xc0000000)) {
maxcount = count; maxcount = count[0];
maxpos = page; maxpos = page;
} else if ((count > maxcount) && (count < 0xc0000000)) { } else if ((count[0] > maxcount) && (count[0] < 0xc0000000)) {
maxcount = count; maxcount = count[0];
maxpos = page; maxpos = page;
} else if ((count > maxcount) && (count > 0xc0000000) } else if ((count[0] > maxcount) && (count[0] > 0xc0000000)
&& (maxcount > 0x80000000)) { && (maxcount > 0x80000000)) {
maxcount = count; maxcount = count[0];
maxpos = page; maxpos = page;
} }
} }
...@@ -358,8 +361,9 @@ mtdoops_console_write(struct console *co, const char *s, unsigned int count) ...@@ -358,8 +361,9 @@ mtdoops_console_write(struct console *co, const char *s, unsigned int count)
if (cxt->writecount == 0) { if (cxt->writecount == 0) {
u32 *stamp = cxt->oops_buf; u32 *stamp = cxt->oops_buf;
*stamp = cxt->nextcount; *stamp++ = cxt->nextcount;
cxt->writecount = 4; *stamp = MTDOOPS_KERNMSG_MAGIC;
cxt->writecount = 8;
} }
if ((count + cxt->writecount) > OOPS_PAGE_SIZE) if ((count + cxt->writecount) > OOPS_PAGE_SIZE)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment