From patchwork Wed Jun 23 15:16:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 56676 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B9587B7092 for ; Wed, 23 Jun 2010 23:18:04 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1ORPog-0007kg-J0; Wed, 23 Jun 2010 13:16:34 +0000 Received: from [77.75.72.43] (helo=smtp.seznam.cz) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1ORPod-0007a7-AQ for linux-mtd@lists.infradead.org; Wed, 23 Jun 2010 13:16:33 +0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=seznam.cz; h=Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent:X-Smtpd:X-Seznam-User:X-QM-Mark; b=WTaG+ld6RvS2T19SX7C7F1SW/4a8kwjzyiK61e9RF6jQvL2tBiefWjXhFq2M8Ii0N gr10nAGxSIHJj9FsHezJvhWV9YRN2g+FFXNL125+YGpW9bWeu2Ilw3+5iJXTW5P2KOP OdTPtZCsXGduJlnxUcjnQCKOZe+vUhLWVE1jEdE= Received: from debian (34.24.broadband3.iol.cz [85.70.24.34]) by email-relay1.go.seznam.cz (Seznam SMTPD 1.1.7@13984) with ESMTP; Wed, 23 Jun 2010 15:16:23 +0200 (CEST) Received: by debian (sSMTP sendmail emulation); Wed, 23 Jun 2010 17:16:22 +0200 Date: Wed, 23 Jun 2010 17:16:22 +0200 From: Ladislav Michl To: "Stanley.Miao" Subject: Re: [PATCH v3] Fix mtd-utils bugs Message-ID: <20100623151622.GA2771@localhost.localdomain> References: <1277036580-3501-1-git-send-email-stanley.miao@windriver.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1277036580-3501-1-git-send-email-stanley.miao@windriver.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Smtpd: 1.1.7@13984 X-Seznam-User: ladislav.michl@seznam.cz X-QM-Mark: email-qm1<560095665> X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100623_091631_694068_DCF6687D X-CRM114-Status: GOOD ( 25.46 ) X-Spam-Score: 1.2 (+) X-Spam-Report: SpamAssassin version 3.3.1 on bombadil.infradead.org summary: Content analysis details: (1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, low trust [77.75.72.43 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is freemail (ladislav.michl[at]seznam.cz) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS Cc: Artem.Bityutskiy@nokia.com, linux-mtd@lists.infradead.org, joakim.tjernlund@transmode.se X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Ladislav Michl 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 On Sun, Jun 20, 2010 at 08:22:57PM +0800, Stanley.Miao wrote: > Changes from V2: > 1, Get the linux version via uname() according to Joakim Tjernlund. > 2, Set the default version the latest version according to Joakim Tjernlund. > > The "struct nand_oobinfo" is able to record only 32 ECC code positions,which > is not enough for many big NAND chips. Therefore, this structure is replaced > by "struct nand_ecclayout" in linux kernel from the version 2.6.17. > Consequently, the ioctl command changed from MEMGETOOBSEL to ECCGETLAYOUT. > > Now update nandwrite to use the new ioctl command ECCGETLAYOUT. In order to > keep compatible with the old linux kernel, a linux version detection function > is added. > > YAFFS and JFFS2 has updated and we don't need the arguments "forcelegacy", > "forcejffs2", "forceyaffs" anymore. Now clean them up. Tested with linux-2.6.32 (flash_eraseall -j finaly works now) Tested-by: Ladislav Michl As a special bonus, here is simple patch on top of your patchset making flash_eraseall smaller: From: Ladislav Michl Returning from main() instead of using exit() makes code more readable and smaller (ARM EABI binary sizes) text data bss dec hex filename 10345 372 44 10761 2a09 flash_eraseall 10286 368 44 10698 29ca flash_eraseall.noexit Signed-off-by: Ladislav Michl --- flash_eraseall.c | 197 ++++++++++++++++++++++++------------------------------- 1 file changed, 89 insertions(+), 108 deletions(-) --- a/flash_eraseall.c 2010-06-23 13:10:00.000000000 +0200 +++ b/flash_eraseall.c 2010-06-23 13:30:31.000000000 +0200 @@ -49,15 +49,45 @@ static const char *exe_name; static const char *mtd_device; static int quiet; /* true -- don't output progress */ -static int jffs2; // format for jffs2 usage - -static void process_options (int argc, char *argv[]); -void show_progress (mtd_info_t *meminfo, erase_info_t *erase); -static void display_help (void); -static void display_version (void); +static int jffs2; /* format for jffs2 usage */ static struct jffs2_unknown_node cleanmarker; int target_endian = __BYTE_ORDER; +static void show_progress(mtd_info_t *meminfo, erase_info_t *erase) +{ + printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.", + meminfo->erasesize / 1024, erase->start, + (unsigned long long) erase->start * 100 / meminfo->size); + fflush(stdout); +} + +static void display_help(void) +{ + printf("Usage: %s [OPTION] MTD_DEVICE\n" + "Erases all of the specified MTD device.\n" + "\n" + " -j, --jffs2 format the device for jffs2\n" + " -q, --quiet don't display progress messages\n" + " --silent same as --quiet\n" + " --help display this help and exit\n" + " --version output version information and exit\n", + exe_name); +} + +static void display_version(void) +{ + printf(PROGRAM " " VERSION "\n" + "\n" + "Copyright (C) 2000 Arcom Control Systems Ltd\n" + "\n" + PROGRAM " comes with NO WARRANTY\n" + "to the extent permitted by law.\n" + "\n" + "You may redistribute copies of " PROGRAM "\n" + "under the terms of the GNU General Public Licence.\n" + "See the file `COPYING' for more information.\n"); +} + static int get_linux_version(void) { int a, b, c, ret, err = 0; @@ -80,23 +110,73 @@ return LINUX_VERSION(a, b, c); } -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { mtd_info_t meminfo; int fd; erase_info_t erase; int isNAND, bbtest = 1; + int error = 0; unsigned char oobbuf[128]; memset(oobbuf, 0xFF, 128); - process_options(argc, argv); + exe_name = argv[0]; + for (;;) { + int option_index = 0; + static const char *short_options = "jq"; + static const struct option long_options[] = { + {"help", no_argument, 0, 0}, + {"version", no_argument, 0, 0}, + {"jffs2", no_argument, 0, 'j'}, + {"quiet", no_argument, 0, 'q'}, + {"silent", no_argument, 0, 'q'}, + + {0, 0, 0, 0}, + }; + + int c = getopt_long(argc, argv, short_options, + long_options, &option_index); + if (c == EOF) + break; + + switch (c) { + case 0: + switch (option_index) { + case 0: + display_help(); + return 0; + case 1: + display_version(); + return 0; + } + break; + case 'q': + quiet = 1; + break; + case 'j': + jffs2 = 1; + break; + case '?': + error = 1; + break; + } + } + if (optind == argc) { + fprintf(stderr, "%s: no MTD device specified\n", exe_name); + error = 1; + } + if (error) { + fprintf(stderr, "Try `%s --help' for more information.\n", + exe_name); + return 1; + } + mtd_device = argv[optind]; if ((fd = open(mtd_device, O_RDWR)) < 0) { fprintf(stderr, "%s: %s: %s\n", exe_name, mtd_device, strerror(errno)); return 1; } - if (ioctl(fd, MEMGETINFO, &meminfo) != 0) { fprintf(stderr, "%s: %s: unable to get MTD device info\n", exe_name, mtd_device); return 1; @@ -213,102 +293,3 @@ return 0; } - - -void process_options (int argc, char *argv[]) -{ - int error = 0; - - exe_name = argv[0]; - - for (;;) { - int option_index = 0; - static const char *short_options = "jq"; - static const struct option long_options[] = { - {"help", no_argument, 0, 0}, - {"version", no_argument, 0, 0}, - {"jffs2", no_argument, 0, 'j'}, - {"quiet", no_argument, 0, 'q'}, - {"silent", no_argument, 0, 'q'}, - - {0, 0, 0, 0}, - }; - - int c = getopt_long(argc, argv, short_options, - long_options, &option_index); - if (c == EOF) { - break; - } - - switch (c) { - case 0: - switch (option_index) { - case 0: - display_help(); - break; - case 1: - display_version(); - break; - } - break; - case 'q': - quiet = 1; - break; - case 'j': - jffs2 = 1; - break; - case '?': - error = 1; - break; - } - } - if (optind == argc) { - fprintf(stderr, "%s: no MTD device specified\n", exe_name); - error = 1; - } - if (error) { - fprintf(stderr, "Try `%s --help' for more information.\n", - exe_name); - exit(1); - } - - mtd_device = argv[optind]; -} - -void show_progress (mtd_info_t *meminfo, erase_info_t *erase) -{ - printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.", - meminfo->erasesize / 1024, erase->start, - (unsigned long long) erase->start * 100 / meminfo->size); - fflush(stdout); -} - -void display_help (void) -{ - printf("Usage: %s [OPTION] MTD_DEVICE\n" - "Erases all of the specified MTD device.\n" - "\n" - " -j, --jffs2 format the device for jffs2\n" - " -q, --quiet don't display progress messages\n" - " --silent same as --quiet\n" - " --help display this help and exit\n" - " --version output version information and exit\n", - exe_name); - exit(0); -} - - -void display_version (void) -{ - printf(PROGRAM " " VERSION "\n" - "\n" - "Copyright (C) 2000 Arcom Control Systems Ltd\n" - "\n" - PROGRAM " comes with NO WARRANTY\n" - "to the extent permitted by law.\n" - "\n" - "You may redistribute copies of " PROGRAM "\n" - "under the terms of the GNU General Public Licence.\n" - "See the file `COPYING' for more information.\n"); - exit(0); -}