From patchwork Fri Nov 24 15:07:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Torben Hohn X-Patchwork-Id: 841092 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::239; helo=mail-wm0-x239.google.com; envelope-from=swupdate+bncbdkzrn4i4elrbvxl4diakgqegjun3zi@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="ik1E1f/k"; dkim-atps=neutral Received: from mail-wm0-x239.google.com (mail-wm0-x239.google.com [IPv6:2a00:1450:400c:c09::239]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yk0266DWWz9s71 for ; Sat, 25 Nov 2017 02:08:11 +1100 (AEDT) Received: by mail-wm0-x239.google.com with SMTP id c82sf3332805wme.8 for ; Fri, 24 Nov 2017 07:08:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511536086; cv=pass; d=google.com; s=arc-20160816; b=npjO8Irqf+dz9lcU2v/XEjN5WGxSkqN00Vt1eDjpCsNZ4gBOgbYQ/rxhHhv8d2C4Wa oF6J5JiSX9wDz9vacNLGE/nbiR1yHYtLDBgW8qKWJzyo+TVXJTkum8aNUz9y4Kw6BGBt Bwm7DJk+7ekxhjieg1PVKsFH7P87ci7gRkjS+KXBomPdKqBudo2UUrFo69bAQOOQ/1Hx XsqIYv06UFTX+jicGgbvd1jbJBHMMok58e+ZUYqIPPUHmXXcqmtFBkKd0eHf+QlGXvll /9TR1iBrfErBMPHpbxJHMrUR9l3g/S8Wx2R3bdM2LfQnpWazrbAZMVfu9fxZSpOzt7YY +Kgg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=Pwuq4etEf2ymESRQniBeTQ8x77JBP3Xx2CCzA0S1PQE=; b=jpRB7ogD2qgxRB+yQibmajbZ5M0h+aO06D9wRxOK3vVU1j6c9XGdHGPYyrir3SANjq tbuNafYlAHEggZOy5vK6JzQg8+ZMdERu+OrXjtAXs4NmMTnEq+ygtcKL102RG9YzJdXu xazdxkiV+YLPI5J38QCNJDEHs0RYb2o9cRM4iNQHU4QMudK20omN+fG9b/QXT9yOQssM dK1QkJ3Xbm1n//BMq7hm39knOo4V2GsWPcPmxyYd7Cvh69I6lxr5TQa4kwWPxaMaq6Kv UNb7E5SNnVwUkmp6ztmBEUkZgEQL7qkppDIVpSTRvpNJw4C+i+e1gSgbTLlroEW2iXP5 7nVg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: best guess record for domain of torbenh@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=torbenh@linutronix.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=Pwuq4etEf2ymESRQniBeTQ8x77JBP3Xx2CCzA0S1PQE=; b=ik1E1f/k8wtsTom40JrkOKbZkdkihzjO9f0u0cSu5aNEzHE/vssCCVqWS6z/7YD49T ISIB2pSz3yHs2OujUq3Bmgk9dbfzF1Ao5pN9TwNPxLg9wQ/E2CtbTEnghZWqB/nwvsBp WUNQ/KeuvykLoHqbtOcAo/TV2UPCPlLSxiynp51SLOSxejdNQVhjh9otG8CEb52Ngchb tMF5ulvzR8r8tScWsIdKtecDMjCAElyBr/a1RH7TZgtGhFwm+TrNZU3ursJt2ZT59Xmr 5sT8AJUag4d0grX68tlwp+Zh/ZCsdMup57kgBRiXiqvUxKqQkZU92PzOcUgfPWcQpU7Z SB8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=Pwuq4etEf2ymESRQniBeTQ8x77JBP3Xx2CCzA0S1PQE=; b=Nj0vvBlQjVs5SYgKkcc+R2VWOIIRWaV1RK19ysnxbYgC37igNNTsKIma0q4+xIyvcc S3kBa/tE+VsxjHVHglm0Wsu8TlqTlZuOVanAfL5RasacSLxKk4bMKJobwDoFC8UOksCo aM6n4i7VFmIgte9n5tSlXz31VpPESZmr6MN0TQZkMA8Sre0P62h3ZJC3NjIFZSuaDu9N 9CmjksIIUfsJwWu6KslUKQyP6vKswxQeIhC4up1blEdyTSEy3Cbed40VfTErPtSY7ynB WfQVvlBLkCbt9uW9/preVvu0D7uS1F3NT5/LmVpgMjpvfgooIvAn3z7+PR/TG4+aW4IJ zX5w== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX4zvQSIfzmpzLdOaJxSUJyOdV0yx5XamSLQaiKawz15L1qvklYx kHbSyR0jRo57MpWsefj2amY= X-Google-Smtp-Source: AGs4zMbsf8RxveV9nEuqzWQZMWNhBPeQ5cBBQp7BLS9t/jx5wd4nVCYH/IBoS8j946TlaO/IViqzOw== X-Received: by 10.28.184.72 with SMTP id i69mr135007wmf.3.1511536086234; Fri, 24 Nov 2017 07:08:06 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.144.196 with SMTP id d4ls4615889eda.4.gmail; Fri, 24 Nov 2017 07:08:05 -0800 (PST) X-Received: by 10.80.201.7 with SMTP id o7mr280144edh.3.1511536085719; Fri, 24 Nov 2017 07:08:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511536085; cv=none; d=google.com; s=arc-20160816; b=q1xXbqJINwPx5QmNKXslhjlgAHXyPrAOKm9D4UtRMsCHAg9M4K8zGgHZw/FDB4mUyf q8W0kB1eTyNiPMQWXgr4Wz/cCNa1TXnwL3gnWUOsnZNGr0tuwlKf3BBARnz67kGz4n/l 3eWtGbOOwAKLDYrDkZmF4afxa7AQ6wHaCm1CfBcTd/KS0d7M7aFqphkijGINSYV7TFxg XXuMTtnpDUl+JBG4qgJuUPb0b5zvo+Ao0cJ4h058Pl+JDDgCg/xoKAKmsc+QHta2H7ut p3hYfm35isO9AOeJ1jaXMlMYZaOdrUaOWULlOHkpZJ5+KPM0VCicbbq3PS3ZxVEPufoH lX8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=F2nzhWY4YpFF6fQ1MLSrOxAND3TsBoPrSAZeH/PdivY=; b=Bztjb0n0dwwDdqKe7krXWkBBkbeWNlZ05/NoSXJg8BS0l+b1TwXneT60XWzHoe218N Oj3cHDUUbWTKNliZQ2dHrveIj2mGdD6RA6Nc/nEAtee4+0h1VXbXBp8z1dz7ymvHSLG5 3ZEJyc9hGy6ulyBeZ6aZqLQ6kHNG/CGOl/SxdxAJHD8IEtlY3FjnGX/zE0Qm/x9OX+ua q4tNNZcSLGpmv9bZxj/+7gX7PIjN6R0CVV81CJE27QFknsJAObuEjq8wVq/Ug/u3EWYx AWUTzaNXjllzmRnL2MoJcYuf7xHKqjKZFxag7CHwyehRKK/BLuvkvQa1J0KjRxTAs+Hf IQog== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: best guess record for domain of torbenh@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=torbenh@linutronix.de Received: from Galois.linutronix.de (Galois.linutronix.de. [2a01:7a0:2:106d:700::1]) by gmr-mx.google.com with ESMTPS id q7si1545058edd.0.2017.11.24.07.08.05 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 24 Nov 2017 07:08:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of torbenh@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) client-ip=2a01:7a0:2:106d:700::1; Received: from torbenh by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1eIFZH-0007hJ-3V; Fri, 24 Nov 2017 16:07:03 +0100 From: Torben Hohn To: swupdate@googlegroups.com Cc: ilu@linutronix.de, Torben Hohn Subject: [swupdate] [PATCH] flash_handler: skip writing to 0xff filled pages on nand Date: Fri, 24 Nov 2017 16:07:52 +0100 Message-Id: <20171124150752.3999-1-torben.hohn@linutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <7fc7ea91-ade8-d84b-8ad7-9cfa8ef0eb71@denx.de> References: <7fc7ea91-ade8-d84b-8ad7-9cfa8ef0eb71@denx.de> X-Original-Sender: torbenh@linutronix.de X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of torbenh@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=torbenh@linutronix.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , This is necessary when flashing an ubi image. A block filled with 0ff does not have an ECC made of 0xff on certein hardware ECC alorithms, So this already flips some bits, when written. However, ubi treats a page full of 0xff as empty, which is not true here. And the result is that data written to such an empty page yields ECC Errors. This is basically Code taken from nand-utils/nandwrite.c from git://git.infradead.org/mtd-utils.git See http://lists.infradead.org/pipermail/linux-mtd/2016-December/070793.html for the patch that starts the discussion and the mtd ML. The relevant Commits in mtd-utils are the following ones: --------------------------------------------------------------------------- commit 15c21334b201dc54870cfd3e9697307c95f7e4dc Author: Kees Trommel Date: Tue Dec 6 09:21:19 2016 +0100 nandwrite: add skip-all-ff-pages-option Signed-off-by: Kees Trommel Signed-off-by: David Oberhollenzer commit f5b47ef5112326b06fd875982379769c55a71703 Author: Marek Vasut Date: Fri Dec 9 02:47:41 2016 +0100 nandwrite: Factor out buffer checking code Pull the buffer content checking code into separate function and simplify the code invoking it slightly. Signed-off-by: Marek Vasut Reviewed-by: Boris Brezillon Signed-off-by: David Oberhollenzer --------------------------------------------------------------------------- Signed-off-by: Torben Hohn Acked-by: Stefano Babic --- handlers/flash_handler.c | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/handlers/flash_handler.c b/handlers/flash_handler.c index 081c2a4..10ea0f7 100644 --- a/handlers/flash_handler.c +++ b/handlers/flash_handler.c @@ -49,6 +49,32 @@ void flash_handler(void); +/* Check whether buffer is filled with character 'pattern' */ +static inline int buffer_check_pattern(unsigned char *buffer, size_t size, + unsigned char pattern) +{ + /* Invalid input */ + if (!buffer || (size == 0)) + return 0; + + /* No match on first byte */ + if (*buffer != pattern) + return 0; + + /* First byte matched and buffer is 1 byte long, OK. */ + if (size == 1) + return 1; + + /* + * Check buffer longer than 1 byte. We already know that buffer[0] + * matches the pattern, so the test below only checks whether the + * buffer[0...size-2] == buffer[1...size-1] , which is a test for + * whether the buffer is filled with constant value. + */ + return !memcmp(buffer, buffer + 1, size - 1); +} + + /* * Writing to the NAND must take into account ECC errors * and BAD sectors. @@ -204,14 +230,17 @@ static int flash_write_nand(int mtdnum, struct img_type *img) } - /* Write out data */ - ret = mtd_write(flash->libmtd, mtd, fd, mtdoffset / mtd->eb_size, - mtdoffset % mtd->eb_size, - writebuf, - mtd->min_io_size, - NULL, - 0, - MTD_OPS_PLACE_OOB); + ret =0; + if (!buffer_check_pattern(writebuf, mtd->min_io_size, 0xff)) { + /* Write out data */ + ret = mtd_write(flash->libmtd, mtd, fd, mtdoffset / mtd->eb_size, + mtdoffset % mtd->eb_size, + writebuf, + mtd->min_io_size, + NULL, + 0, + MTD_OPS_PLACE_OOB); + } if (ret) { long long i; if (errno != EIO) {