Skip to content

Commit aa641a2

Browse files
jmeurinmiquelraynal
authored andcommitted
mtd: mtdoops: Add a timestamp to the mtdoops header.
On some systems, the oops only has relative time from boot. Signed-off-by: Jean-Marc Eurin <jmeurin@google.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20220425160927.3823016-1-jmeurin@google.com
1 parent 0bd359e commit aa641a2

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

drivers/mtd/mtdoops.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/wait.h>
1717
#include <linux/delay.h>
1818
#include <linux/interrupt.h>
19+
#include <linux/timekeeping.h>
1920
#include <linux/mtd/mtd.h>
2021
#include <linux/kmsg_dump.h>
2122

@@ -37,11 +38,13 @@ module_param(dump_oops, int, 0600);
3738
MODULE_PARM_DESC(dump_oops,
3839
"set to 1 to dump oopses, 0 to only dump panics (default 1)");
3940

40-
#define MTDOOPS_KERNMSG_MAGIC 0x5d005d00
41+
#define MTDOOPS_KERNMSG_MAGIC_v1 0x5d005d00 /* Original */
42+
#define MTDOOPS_KERNMSG_MAGIC_v2 0x5d005e00 /* Adds the timestamp */
4143

4244
struct mtdoops_hdr {
4345
u32 seq;
4446
u32 magic;
47+
ktime_t timestamp;
4548
} __packed;
4649

4750
static struct mtdoops_context {
@@ -191,7 +194,8 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic)
191194
/* Add mtdoops header to the buffer */
192195
hdr = (struct mtdoops_hdr *)cxt->oops_buf;
193196
hdr->seq = cxt->nextcount;
194-
hdr->magic = MTDOOPS_KERNMSG_MAGIC;
197+
hdr->magic = MTDOOPS_KERNMSG_MAGIC_v2;
198+
hdr->timestamp = ktime_get_real();
195199

196200
if (panic) {
197201
ret = mtd_panic_write(mtd, cxt->nextpage * record_size,
@@ -247,7 +251,9 @@ static void find_next_position(struct mtdoops_context *cxt)
247251

248252
if (hdr.seq == 0xffffffff && hdr.magic == 0xffffffff)
249253
mark_page_unused(cxt, page);
250-
if (hdr.seq == 0xffffffff || hdr.magic != MTDOOPS_KERNMSG_MAGIC)
254+
if (hdr.seq == 0xffffffff ||
255+
(hdr.magic != MTDOOPS_KERNMSG_MAGIC_v1 &&
256+
hdr.magic != MTDOOPS_KERNMSG_MAGIC_v2))
251257
continue;
252258
if (maxcount == 0xffffffff) {
253259
maxcount = hdr.seq;

0 commit comments

Comments
 (0)