From patchwork Fri Nov 24 12:32:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Torben Hohn X-Patchwork-Id: 841021 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:4010:c07::23a; helo=mail-lf0-x23a.google.com; envelope-from=swupdate+bncbdkzrn4i4elrbunc4diakgqejotit2q@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="EXr3ANwF"; dkim-atps=neutral Received: from mail-lf0-x23a.google.com (mail-lf0-x23a.google.com [IPv6:2a00:1450:4010:c07::23a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yjwYz1qR5z9sNr for ; Fri, 24 Nov 2017 23:32:22 +1100 (AEDT) Received: by mail-lf0-x23a.google.com with SMTP id g35sf5382513lfi.0 for ; Fri, 24 Nov 2017 04:32:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511526737; cv=pass; d=google.com; s=arc-20160816; b=0qVV7GIJ3NmLIIicVyc3fVA8s7DpdfEyxbYHUWgCG4r5gZrLIsxHI2gindIR1BFqHd im1aA+1Zwn758FgYAVg/daOmTFvbXXTp0AvO9/CadegAYR7oUf5r6acIU5uu4RvV3aVC vZcCoChoGPFQfG1xBcByOfzPzZPt2zNQYgFzRvMlAGUaGoZyMbb2mJ+l9ofy0O6hyYUC RWRJQIyXb/GLt1m7pJ3jIwDhicNStsIFi2WnuosdcnBobyE1pYku7a5SVVn9+9aahGkN QfmkATCT8wvS19guJYEl9AWR1LGAZ1ZtQL2fkm8j1u9flfUWBM800EKxu3C2VhMWv/i5 KOVQ== 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:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=iMfFXfkSe8hM3IjT1MRycac/UMM29prriBGqLKz5Zbw=; b=eSNnzxgfRjZiTvGXArrLa06ULWLvpVNPSMq5cZqTxXyXdUW2qr1eS/4ey0nn/RWYyP clhGj+cNWBvqGaP4IZH/UL/773HVkrsR/gFanXLVGvnQd8wNsv9ZShIS+07F9Vgq2k04 rpjxyzsnAF/YeZFrm+jazPb+JELgUY2hKry6eaWS4nKq7/nr0t1C1ktmN/9QTaMTig+b A+V0iMS0EcLX9wXVDew9DkM83e2b6yDeqrWfoqeh5iU20GNZ5o6uhBB4Fz5A/QjXQVZw 0dv31m9sZS8xkF1icXURH/+OPssPUT7uLAjLtGNvXdPoWTPcMz+V2pQHXv1ym020nT6T LH1w== 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 :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=iMfFXfkSe8hM3IjT1MRycac/UMM29prriBGqLKz5Zbw=; b=EXr3ANwFLsCXt0Wa+n9T9rp8434WxhqjQLXVNAyLrt4vtqX/CLSO8dO8bEcaGkX26y XzFZO3z0et6P18OT1+t5f4LdmKFS6AveR3N29x+VZoZGoQs00/9inv0srJm70Ik9WD6m U9+laz3T9Zt7/q/tsoalUhiAOrJXmkB36sY0fICEpQgMuazghcMuad6EHWp3b8NhCbvi 1BhwXNm35gNgHOT6/4N/u1eXca2nnmnm0gy4X1K6Tch4r92ur4wq8fOj72Vpt4jDqED3 O4yKdtxZbDiFr6ER6Tb0dSA1/DEK2h01aZPFevVN0pCFlRB8hpvT2aVpN13zEtTN3ktU xlCQ== 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: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=iMfFXfkSe8hM3IjT1MRycac/UMM29prriBGqLKz5Zbw=; b=MzscR6fOsSJxOGzImn8pIe8EJB1rRICp22Z4RNCzHt1VfCKm70GLREjhfpF+PK9uMZ +rTYIydOCn0P1uNv7ahTs/eFO22+Bycf9f6WgK7XW804YcVi12l08wSh335SI3snndbN 8rNX0YOnVvaejNVGYD6Ad0gufx+hYuGjy4cLkaxZ1yKgDniIw3TAUQw1IHSB8ctz6jq9 6dmm6G5/U5LOkilFVNCzVCcfIwhj3pjF65r3QEr5GXVDUVJsyqM3l3AJvcdNNXQo4CCt UClO/c0iVXfvK963vtIFUDSZeb7/YShZ/ZprL4TZkLywaNle8AnoJ52SfggIAJKl389F 2Bqw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX5qW69IdwO1C65D6btz+K2sCWfSWrORxRLBZ0FXL3Gt9kqeWZZq QliZ/WiG7Y7cATn50sOjFno= X-Google-Smtp-Source: AGs4zMYR8tmehZUCMoY6nw1p8WdlgNZV6w9890Id3/8vOXsSEgkkg2hGbLIY7iDjOxBeZ9GrG9KJBw== X-Received: by 10.46.95.76 with SMTP id t73mr83015ljb.12.1511526737628; Fri, 24 Nov 2017 04:32:17 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.68.140 with SMTP id b12ls932531ljf.1.gmail; Fri, 24 Nov 2017 04:32:17 -0800 (PST) X-Received: by 10.46.2.155 with SMTP id y27mr890799lje.18.1511526736985; Fri, 24 Nov 2017 04:32:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511526736; cv=none; d=google.com; s=arc-20160816; b=BEISt/AG+ehCs1XLcK+PVJNKDAgqaaviHvLsypmzU5uAAPNJhs8A5RfXZmcLFkHVbZ xCWcxvGAUnxX928LWe4ix84W1sFq5t9eH/TOXbwEMd04FPiAdjGZ+DcOCJqE8PyJHCsG CjK7RQ40Bim1INFMvEEHlqo4Uc7vYjh8K+Qd+/pfwRB2zBi0n8YySrK54e1firdacI5O pT3BEpvAJLg1yFZ6cCv5krsikXiHy8zUBY3tBJn0/zX824Utsn6b8GQ/z8shtBlDk+Vx uLMA2A3V2eKeSdar/iDocMWctXj7bgKC+OS2eI1KJxY0fZqioorbFU4mABVoOAr7vDt0 xzhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=UJg8cKyA1Id8dojwsj3ZoHWu2wrTv46m2HRZqJvBY7s=; b=Tc0vUGZSlqbOrpigbc0Vm56Fm+6nQP0J/BEoGD9MIuzy4Itwblnxi/aaDtTP2QHEeg yXmYLRKc3/RC9X2sl0VLilDkNMmvMInl7/HLF+5sPBX3k4KXya5fzRtARw9aN0xAMoKJ OYlvGdE8z4EmBVY5hoTjiW9pVOc+0C+8slwzM49S9pZ6U7oAH55WIULb5MWbXgk+MMHs pkU3f4N11NXpS19BsZF5L8FukdyY7/HAtOZyS8D33arJL3qFJ1aXj4v92dVHW6U2CQ7T V5cxFyIlpZQiffggFEX3Ml5bo7GtPUiZ+XP5q31GgJWhgITnAKPsw4qA8wIv9DXrnISz iLKg== 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 64si1578177ljz.5.2017.11.24.04.32.16 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 24 Nov 2017 04:32:16 -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 1eID8U-0003HD-2x; Fri, 24 Nov 2017 13:31:14 +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 13:32:03 +0100 Message-Id: <20171124123203.29892-1-torben.hohn@linutronix.de> X-Mailer: git-send-email 2.11.0 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. 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. --- 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) {