All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dirk Behme <dirk.behme@de.bosch.com>
To: <linux-mtd@lists.infradead.org>, Richard Weinberger <richard@nod.at>
Cc: <manfred@colorfullife.com>, <dirk.behme@de.bosch.com>,
	Manfred Spraul <manfred.spraul@de.bosch.com>
Subject: [PATCH 5/5] mtdram flight recorder: Add checksums.
Date: Wed, 6 Dec 2017 09:50:39 +0100	[thread overview]
Message-ID: <20171206085039.27164-6-dirk.behme@de.bosch.com> (raw)
In-Reply-To: <20171206085039.27164-1-dirk.behme@de.bosch.com>

From: Manfred Spraul <manfred@colorfullife.com>

Add checksums, to ensure that corruptions can be detected.
To allow userspace to detect the new fields, use new IDs
for WRITE/ERASE commands.

Signed-off-by: Manfred Spraul <manfred.spraul@de.bosch.com>
Cc: Manfred Spraul <manfred@colorfullife.com>
---
 drivers/mtd/devices/mtdram.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index 202696bc92ef..cdf5ae90943b 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -190,6 +190,11 @@ static const struct file_operations fr_fops = {
 
 #define FUNC_WRITE	1UL
 #define FUNC_ERASE	2UL
+#define FUNC_WRITE_CHK	3UL
+#define FUNC_ERASE_CHK	4UL
+#define CHECK_VAL1	7ULL
+#define CHECK_VAL2	(2*76777ULL)
+#define CHECK_VAL3	104677ULL
 
 static void write_u32(u32 data)
 {
@@ -348,9 +353,10 @@ static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
 
 #ifdef CONFIG_MTDRAM_FLIGHTRECORDER
 	start_write(3*8);
-	write_u32(FUNC_ERASE);
+	write_u32(FUNC_ERASE_CHK);
 	write_u64(instr->addr);
 	write_u64(instr->len);
+	write_u64(CHECK_VAL1*(u64)instr->len + CHECK_VAL2*(u64)instr->addr);
 	end_write();
 #endif
 
@@ -407,12 +413,23 @@ static int ram_write(struct mtd_info *mtd, loff_t to, size_t len,
 	memcpy((char *)mtd->priv + to, buf, len);
 
 #ifdef CONFIG_MTDRAM_FLIGHTRECORDER
-	start_write(3*8 + len);
-	write_u32(FUNC_WRITE);
-	write_u64(to);
-	write_u64(len);
-	write_blob(buf, len);
-	end_write();
+	start_write(4*8 + len);
+	{
+		u64 i;
+		u64 chk;
+
+		write_u32(FUNC_WRITE_CHK);
+
+		chk = CHECK_VAL1*(u64)to + CHECK_VAL2*(u64)len;
+		for (i = 0; i < len; i++)
+			chk += (i + buf[i])*CHECK_VAL3;
+
+		write_u64(to);
+		write_u64(len);
+		write_blob(buf, len);
+		write_u64(chk);
+		end_write();
+	}
 #endif
 
 	*retlen = len;
-- 
2.14.1

  parent reply	other threads:[~2017-12-06  8:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-06  8:50 [PATCH 0/5] Add flight recorder to MTDRAM Dirk Behme
2017-12-06  8:50 ` [PATCH 1/5] mtdram: expose write size and writebuf size as module parameters Dirk Behme
2017-12-06  8:50 ` [PATCH 2/5] mtdram: Add flight recorder Dirk Behme
2017-12-06  8:50 ` [PATCH 3/5] mtdram: Allow to enable/disable flight recorder mode at runtime Dirk Behme
2017-12-06  8:50 ` [PATCH 4/5] mtdram: Convert the flight recorder to a ring buffer Dirk Behme
2017-12-06  8:50 ` Dirk Behme [this message]
2017-12-06 10:41 ` [PATCH 0/5] Add flight recorder to MTDRAM Richard Weinberger
2017-12-06 19:44   ` Manfred Spraul
2017-12-06 19:59     ` Richard Weinberger
2017-12-06 20:57       ` Richard Weinberger
2017-12-07 16:06         ` Manfred Spraul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171206085039.27164-6-dirk.behme@de.bosch.com \
    --to=dirk.behme@de.bosch.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=manfred.spraul@de.bosch.com \
    --cc=manfred@colorfullife.com \
    --cc=richard@nod.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.