From patchwork Thu Sep 3 11:15:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Korhonen X-Patchwork-Id: 32880 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 066D9B6F1E for ; Thu, 3 Sep 2009 21:21:25 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1MjAKA-00062U-LZ; Thu, 03 Sep 2009 11:17:54 +0000 Received: from smtp.nokia.com ([192.100.122.230] helo=mgw-mx03.nokia.com) by bombadil.infradead.org with esmtps (Exim 4.69 #1 (Red Hat Linux)) id 1MjAIa-0005mz-EE for linux-mtd@lists.infradead.org; Thu, 03 Sep 2009 11:16:22 +0000 Received: from vaebh105.NOE.Nokia.com (vaebh105.europe.nokia.com [10.160.244.31]) by mgw-mx03.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id n83BG1TT008502 for ; Thu, 3 Sep 2009 14:16:06 +0300 Received: from esebh102.NOE.Nokia.com ([172.21.138.183]) by vaebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 3 Sep 2009 14:15:55 +0300 Received: from mgw-da02.ext.nokia.com ([147.243.128.26]) by esebh102.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Thu, 3 Sep 2009 14:15:54 +0300 Received: from localhost.localdomain (ouped119140.nmp.nokia.com [172.23.119.140]) by mgw-da02.ext.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id n83BFjrA032193; Thu, 3 Sep 2009 14:15:46 +0300 From: Mika Korhonen To: linux-mtd@lists.infradead.org Subject: [PATCH] MTD OneNAND OMAP2/3: allow giving partition layout as module parameter Date: Thu, 3 Sep 2009 14:15:58 +0300 Message-Id: <1251976558-13463-1-git-send-email-ext-mika.2.korhonen@nokia.com> X-Mailer: git-send-email 1.6.0.4 X-OriginalArrivalTime: 03 Sep 2009 11:15:54.0916 (UTC) FILETIME=[E7791640:01CA2C87] X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.5 (LGPL) ) MR-646709E3 X-CRM114-CacheID: sfid-20090903_071616_827990_86A12EF1 X-CRM114-Status: GOOD ( 17.74 ) X-Spam-Score: -6.5 (------) X-Spam-Report: SpamAssassin version 3.2.5 on bombadil.infradead.org summary: Content analysis details: (-6.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -4.0 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [192.100.122.230 listed in list.dnswl.org] 0.2 SUBJECT_FUZZY_TION Attempt to obfuscate words in Subject: -2.6 BAYES_00 BODY: Bayesian spam probability is 0 to 1% [score: 0.0000] -0.1 AWL AWL: From: address is in the auto white-list Cc: Mika Korhonen 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: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add module parameter "parts" to omap2-onenand driver. Parameter format is the same as for cmdlinepart except mtd-id must not be specified - it gets prepended by the driver, i.e.: parts=[,]* This allows one to repartition the OneNAND chip and is useful for flashing applications that do the partitioning from scratch or want to backup and update the partitioning. Signed-off-by: Mika Korhonen --- drivers/mtd/cmdlinepart.c | 35 +++++++++++++++++++++++++++++------ drivers/mtd/onenand/omap2.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c index 1479da6..77fa7b7 100644 --- a/drivers/mtd/cmdlinepart.c +++ b/drivers/mtd/cmdlinepart.c @@ -5,7 +5,7 @@ * * The format for the command line is as follows: * - * mtdparts=[;[;] * := :[,] * where is the name from the "cat /proc/mtd" command * := [@offset][][ro][lk] @@ -54,7 +54,7 @@ struct cmdline_mtd_partition { /* mtdpart_setup() parses into here */ static struct cmdline_mtd_partition *partitions; -/* the command line passed to mtdpart_setupd() */ +/* the command line passed to mtdpart_setup() */ static char *cmdline; static int cmdline_parsed = 0; @@ -219,9 +219,8 @@ static int mtdpart_setup_real(char *s) { cmdline_parsed = 1; - for( ; s != NULL; ) - { - struct cmdline_mtd_partition *this_mtd; + for ( ; s != NULL; ) { + struct cmdline_mtd_partition *this_mtd, *mtd, *mtd_prev; struct mtd_partition *parts; int mtd_id_len; int num_parts; @@ -270,6 +269,27 @@ static int mtdpart_setup_real(char *s) this_mtd->mtd_id = (char*)(this_mtd + 1); strlcpy(this_mtd->mtd_id, mtd_id, mtd_id_len + 1); + /* remove existing ones with the same id */ + mtd_prev = NULL; + for (mtd = partitions; mtd;) { + if (strcmp(this_mtd->mtd_id, mtd->mtd_id) == 0) { + printk(KERN_INFO "old entry for mtd id %s " + "exists, removing\n", mtd->mtd_id); + if (mtd_prev) { + mtd_prev->next = mtd->next; + kfree(mtd); + mtd = mtd_prev->next; + } else { + partitions = mtd->next; + kfree(mtd); + mtd = partitions; + } + } else { + mtd_prev = mtd; + mtd = mtd->next; + } + } + /* link into chain */ this_mtd->next = partitions; partitions = this_mtd; @@ -354,12 +374,15 @@ static int parse_cmdline_partitions(struct mtd_info *master, * * This function needs to be visible for bootloaders. */ -static int mtdpart_setup(char *s) +int mtdpart_setup(char *s) { cmdline = s; + cmdline_parsed = 0; return 1; } +EXPORT_SYMBOL(mtdpart_setup); + __setup("mtdparts=", mtdpart_setup); static struct mtd_part_parser cmdline_parser = { diff --git a/drivers/mtd/onenand/omap2.c b/drivers/mtd/onenand/omap2.c index 0108ed4..b216a92 100644 --- a/drivers/mtd/onenand/omap2.c +++ b/drivers/mtd/onenand/omap2.c @@ -45,6 +45,7 @@ #include #define DRIVER_NAME "omap2-onenand" +#define DRIVER_NAME_SIZE sizeof(DRIVER_NAME) #define ONENAND_IO_SIZE SZ_128K #define ONENAND_BUFRAM_SIZE (1024 * 5) @@ -64,6 +65,17 @@ struct omap2_onenand { int (*setup)(void __iomem *base, int freq); }; + +#ifdef CONFIG_MTD_CMDLINE_PARTS +extern int mtdpart_setup(char *); + +static const char *part_probes[] = { "cmdlinepart", NULL }; +static char parts[256] = DRIVER_NAME ":"; + +module_param_string(parts, parts + DRIVER_NAME_SIZE, 256 - DRIVER_NAME_SIZE, 0); +#endif + + static void omap2_onenand_dma_cb(int lch, u16 ch_status, void *data) { struct omap2_onenand *c = data; @@ -709,6 +721,23 @@ static int __devinit omap2_onenand_probe(struct platform_device *pdev) } #ifdef CONFIG_MTD_PARTITIONS +#ifdef CONFIG_MTD_CMDLINE_PARTS + printk(KERN_INFO "parts=%s\n", parts); + /* check module parameter */ + if (parts[DRIVER_NAME_SIZE] != '\0') { + /* check parts string */ + if (strchr(parts, ';') || strchr(parts + DRIVER_NAME_SIZE, ':')) { + printk(KERN_ERR "onenand_probe: invalid partition parameter\n"); + } else { + mtdpart_setup(parts); + } + } + r = parse_mtd_partitions(&c->mtd, part_probes, &c->parts, 0); + if (r > 0) { + /* module param or kernel command line arg */ + r = add_mtd_partitions(&c->mtd, c->parts, r); + } else +#endif if (pdata->parts != NULL) r = add_mtd_partitions(&c->mtd, pdata->parts, pdata->nr_parts);