From patchwork Wed Dec 6 08:50:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Behme Dirk (CM/ESO2)" X-Patchwork-Id: 845070 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MQ4gzOOC"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=de.bosch.com header.i=@de.bosch.com header.b="iEPFbEus"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ysCHN4kfkz9s4s for ; Wed, 6 Dec 2017 20:00:00 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4dCeJcriMZp+4PJ7rQEA2ebm7+FN0aOoHKS/NTD+AAg=; b=MQ4gzOOCsm3wbB uZmmgcWy5P6iQXegRl8xsvrbljFybvoGSU8yXWPCkMqHJ/JWBNO+qGcEFdl7tMyUjrdAlrwR2xusl 8BxTBa8qKn1tNEtbYotYF6cmcfc1mDwS4XKX0VA5Ohsw1lvQgZv/5qd6HFnxA1kPysKiJsZxy/49x 4sAO2eR4M+7UifhX52SIGmTLlk8L6J+nxomPkC6J7ozWG9NcOKyW9Oc1yGI3NJZVPVMOWxNuCYDQN X+gBNL0x+eetTUQeKKq6lKtrJ6ar++bXKZPWHsl3LtkRdpeW4Z3DAlGvTpJfjCsoz+cdL48IdofQx VFD9EOnTI8d6h052VEsA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMVYV-0006v5-Ef; Wed, 06 Dec 2017 08:59:51 +0000 Received: from imta21.fe.bosch.de ([139.15.243.226]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMVXs-00068k-5I for linux-mtd@lists.infradead.org; Wed, 06 Dec 2017 08:59:19 +0000 Received: from smtp6-v.fe.bosch.de (imta23.fe.bosch.de [139.15.243.227]) by imta21.fe.bosch.de (Postfix) with ESMTP id E3EE5C09B2 for ; Wed, 6 Dec 2017 09:49:18 +0100 (CET) Received: from vsmta12.fe.internet.bosch.com (unknown [10.4.98.52]) by imta23.fe.bosch.de (Postfix) with ESMTP id 69D76158022D; Wed, 6 Dec 2017 09:48:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1512550090; bh=eQksyDOgK9eUOo6EfpSEeZh5Z0StvM2J6rFWqp5v52Y=; l=10; h=From:From:Reply-To:Sender; b=iEPFbEusdtX6wu9B5Jn1625io7e4oEIi3MDQG19be08JmeuWqR6TTtbiwfRvuqGs9 vqOmJgrjzCJOPoV9ZAfp7wzqI/bmBZPd+KGdofTXXdPu+q/CUUDcxdcjqOSg6w9Rue mTr1aHCCjpJN04EG3Lz5Tt/kBNlodR0kDITpiTtk= Received: from SI-HUB1001.de.bosch.com (vsgw23.fe.internet.bosch.com [10.4.98.23]) by vsmta12.fe.internet.bosch.com (Postfix) with ESMTP id 67A151B8074E; Wed, 6 Dec 2017 09:50:43 +0100 (CET) Received: from HI-Z0EVG.hi.de.bosch.com (10.34.218.219) by SI-HUB1001.de.bosch.com (10.4.103.108) with Microsoft SMTP Server id 14.3.319.2; Wed, 6 Dec 2017 09:50:42 +0100 From: Dirk Behme To: , Richard Weinberger Subject: [PATCH 5/5] mtdram flight recorder: Add checksums. Date: Wed, 6 Dec 2017 09:50:39 +0100 Message-ID: <20171206085039.27164-6-dirk.behme@de.bosch.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171206085039.27164-1-dirk.behme@de.bosch.com> References: <20171206085039.27164-1-dirk.behme@de.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.34.218.219] X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-23510.005 X-TMASE-MatchedRID: yvDAzrttxFXxoFpSGnAM9Y6MisxJraxHwx0jRRxcQfP4JyR+b5tvoGyC j7kGFS5bMMYy8ayOMupVF51vxLbfWZCoy9iDotiwSHCU59h5KrH+rFFXesuqjblmMfLNiukaFWo Asts4LpU6hUOcTonr9IAy6p60ZV62fJ5/bZ6npdjGVuWouVipcoquDTfUyfQi+FMBUyufmG+yhj kYN0Ww/yztPf2SGXatwtmDEcPlSS3LgSGp3SZac8CFsem4o9u2oxShiDBjN/T1EJ4DVpFBEIISr dkIFqeuO4Y2dUBhL/BTBYT7RGXoWxJAEJH0NuHT9aAnbWsWzHc= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171206_005912_723737_1FD0782C X-CRM114-Status: UNSURE ( 9.18 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -7.0 (-------) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-7.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [139.15.243.226 listed in wl.mailspike.net] -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [139.15.243.226 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dirk.behme@de.bosch.com, manfred@colorfullife.com, Manfred Spraul Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Manfred Spraul 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 Cc: Manfred Spraul --- 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;