From patchwork Fri Oct 15 07:44:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 67891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from canuck.infradead.org (canuck.infradead.org [134.117.69.58]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 02E99B70D5 for ; Fri, 15 Oct 2010 18:47:36 +1100 (EST) Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1P6eyL-0007AX-0u; Fri, 15 Oct 2010 07:45:01 +0000 Received: from mms2.broadcom.com ([216.31.210.18]) by canuck.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1P6ey9-000799-4K for linux-mtd@lists.infradead.org; Fri, 15 Oct 2010 07:44:50 +0000 Received: from [10.9.200.131] by mms2.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.3.2)); Fri, 15 Oct 2010 00:44:36 -0700 X-Server-Uuid: D3C04415-6FA8-4F2C-93C1-920E106A2031 Received: from mail-irva-12.broadcom.com (10.11.16.101) by IRVEXCHHUB01.corp.ad.broadcom.com (10.9.200.131) with Microsoft SMTP Server id 8.2.247.2; Fri, 15 Oct 2010 00:44:36 -0700 Received: from localhost.localdomain (ld-irv-0074.broadcom.com [10.12.160.50]) by mail-irva-12.broadcom.com (Postfix) with ESMTP id 7A24769CAA; Fri, 15 Oct 2010 00:44:36 -0700 (PDT) From: "Brian Norris" To: linux-mtd@lists.infradead.org Subject: [PATCH 3/3] mtd-utils: nandwrite: Large page+oob support Date: Fri, 15 Oct 2010 00:44:25 -0700 Message-ID: <1287128665-6573-3-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1287128665-6573-1-git-send-email-computersforpeace@gmail.com> References: <1287128665-6573-1-git-send-email-computersforpeace@gmail.com> MIME-Version: 1.0 X-WSS-ID: 60A6D9EE3N013230307-01-01 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20101015_034449_516091_30F9EBCC X-CRM114-Status: GOOD ( 16.74 ) X-Spam-Score: 1.2 (+) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is freemail (computersforpeace[at]gmail.com) 0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is CUSTOM_MED 1.2 NML_ADSP_CUSTOM_MED ADSP custom_med hit, and not from a mailing list 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL Cc: Brian Norris , David Woodhouse , Artem Bityutskiy X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Dynamic allocation of the oob buffer provides the necessary support for removing the oob size check. Now, new unknown OOB sizes can be handled correctly (for example, 8KB page + 448B OOB). Signed-off-by: Brian Norris --- nandwrite.c | 33 +++++++++++++-------------------- 1 files changed, 13 insertions(+), 20 deletions(-) diff --git a/nandwrite.c b/nandwrite.c index e0f5f44..2341694 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -42,9 +42,6 @@ #include #include "mtd/mtd-user.h" -#define MAX_PAGE_SIZE 4096 -#define MAX_OOB_SIZE 128 - // oob layouts to pass into the kernel as default static struct nand_oobinfo none_oobinfo = { .useecc = MTD_NANDECC_OFF, @@ -276,12 +273,10 @@ int main(int argc, char * const argv[]) unsigned char *writebuf = NULL; // points to the OOB for the current page in filebuf unsigned char *oobreadbuf = NULL; - unsigned char oobbuf[MAX_OOB_SIZE]; + unsigned char *oobbuf = NULL; process_options(argc, argv); - erase_buffer(oobbuf, sizeof(oobbuf)); - if (pad && writeoob) { fprintf(stderr, "Can't pad when oob data is present.\n"); exit(EXIT_FAILURE); @@ -304,17 +299,6 @@ int main(int argc, char * const argv[]) * (virtual) block size */ meminfo.erasesize *= blockalign; - /* Make sure device page sizes are valid */ - if (!(meminfo.oobsize == 16 && meminfo.writesize == 512) && - !(meminfo.oobsize == 8 && meminfo.writesize == 256) && - !(meminfo.oobsize == 64 && meminfo.writesize == 2048) && - !(meminfo.oobsize == 64 && meminfo.writesize == 4096) && - !(meminfo.oobsize == 128 && meminfo.writesize == 4096)) { - fprintf(stderr, "Unknown flash (not normal NAND)\n"); - close(fd); - exit(EXIT_FAILURE); - } - if (mtdoffset & (meminfo.writesize - 1)) { fprintf(stderr, "The start address is not page-aligned !\n" "The pagesize of this NAND Flash is 0x%x.\n", @@ -455,11 +439,19 @@ int main(int argc, char * const argv[]) filebuf = (unsigned char *)malloc(filebuf_max); if (!filebuf) { fprintf(stderr, "Failed to allocate memory for file buffer (%d bytes)\n", - pagelen * meminfo.erasesize / meminfo.writesize); + filebuf_max); goto closeall; } erase_buffer(filebuf, filebuf_max); + oobbuf = (unsigned char *)malloc(meminfo.oobsize); + if (!oobbuf) { + fprintf(stderr, "Failed to allocate memory for oob buffer (%d bytes)\n", + meminfo.oobsize); + goto closeall; + } + erase_buffer(oobbuf, meminfo.oobsize); + /* * Get data from input and write to the device while there is * still input to read and we are still within the device @@ -688,9 +680,10 @@ int main(int argc, char * const argv[]) failed = false; closeall: - if (filebuf) { + if (filebuf) free(filebuf); - } + if (oobbuf) + free(oobbuf); close(ifd);