From patchwork Fri Feb 15 20:35:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick O'Grady X-Patchwork-Id: 220847 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 459162C0080 for ; Sat, 16 Feb 2013 07:37:02 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U6S0e-0005Lj-Ui; Fri, 15 Feb 2013 20:35:52 +0000 Received: from mail-ob0-f169.google.com ([209.85.214.169]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U6S0b-0005LC-6E for linux-mtd@lists.infradead.org; Fri, 15 Feb 2013 20:35:50 +0000 Received: by mail-ob0-f169.google.com with SMTP id ta14so3993259obb.28 for ; Fri, 15 Feb 2013 12:35:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to:cc :content-type:x-gm-message-state; bh=DsFiQtOmUy+BRM37VciPi8N2C2cWq/WzqB6YeND/+aQ=; b=SnMSlGfCe1orIhL+GFa8NdvIngMGbJaLD/eyLck4Z9xaRaJkHEH+WX/lJ8w9C/w/uC 5ev7mt1wT73ALDuHwFflzXy/gBHqHAoCDRVaAxLspp4myuVIjpwapTZPmU50v1HnqyJM x2BF0iC1DLDL8NboJpfd3wrYq5K1mzrx9SmHgAnkyMKNcxy81nD8WUIxcGH+LItCJoX8 cAiNxLu3LtuqpSkK6rg8zqfuZOf2jUzc1psw9ozyH2PD7LfYEHUvsoIzTeNq20Ea87cY AGVaoSmuKk82Z4rsrxO9MRwJ49tPVWuVgCkCfwrSbUx3AqWzLvVi/oGERckQc5FyalJE C+rw== MIME-Version: 1.0 X-Received: by 10.182.54.46 with SMTP id g14mr2665284obp.55.1360960546775; Fri, 15 Feb 2013 12:35:46 -0800 (PST) Received: by 10.60.169.139 with HTTP; Fri, 15 Feb 2013 12:35:46 -0800 (PST) Date: Fri, 15 Feb 2013 12:35:46 -0800 Message-ID: Subject: [PATCH] phram: Allow the user to set the erase page size. From: "Patrick O'Grady" To: Joern Engel , David Woodhouse X-Gm-Message-State: ALoCoQnF9eVJtdvRBK3Oe39Bv5Qi2O1FbTySQk4NIUv3NF8KnGgaDtGo9e0dP2e3hdBR50+MGq0+ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130215_153549_267052_FEFC86B4 X-CRM114-Status: GOOD ( 10.87 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.214.169 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 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 From: Patrick O'Grady Permit the user to specify the erase page size as a parameter. This solves two problems: - phram can access images made by mkfs.jffs2. mkfs.jffs2 won't create images with erase sizes less than 8KiB; many architectures define PAGE_SIZE as 4KiB. - Allows more effective use of small capacity devices. JFFS2 needs somewhere between 2 and 5 empty pages for garbage collection; and for an NVRAM part with only 32KiB of space, a smaller erase page allows much better utilization in applications where garbage collection is important. Signed-off-by: Patrick O'Grady Reviewed-by: Joern Engel --- ret = -EAGAIN; @@ -207,21 +209,22 @@ static inline void kill_final_newline(char *str) /* * This shall contain the module parameter if any. It is of the form: - * - phram=,
, for module case - * - phram.phram=,
, for built-in case - * We leave 64 bytes for the device name, 12 for the address and 12 for the - * size. - * Example: phram.phram=rootfs,0xa0000000,512Mi + * - phram=,
,[,] for module case + * - phram.phram=,
,[,] for built-in case + * We leave 64 bytes for the device name, 12 for the address, 12 for the + * size, and 12 for the erasesize. + * Example: phram.phram=rootfs,0xa0000000,512Mi,65536 */ static __initdata char phram_paramline[64+12+12]; static int __init phram_setup(const char *val) { - char buf[64+12+12], *str = buf; + char buf[64+12+12+12], *str = buf; char *token[3]; char *name; uint32_t start; uint32_t len; + uint32_t erasesize = PAGE_SIZE ; int i, ret; if (strnlen(val, sizeof(buf)) >= sizeof(buf)) @@ -230,7 +233,7 @@ static int __init phram_setup(const char *val) strcpy(str, val); kill_final_newline(str); - for (i=0; i<3; i++) + for (i = 0; i < 4; i++) token[i] = strsep(&str, ","); if (str) @@ -255,7 +258,15 @@ static int __init phram_setup(const char *val) parse_err("illegal device length\n"); } - ret = register_device(name, start, len); + if (token[3]) { + ret = parse_num32(&erasesize, token[3]); + if (ret) { + kfree(name); + parse_err("illegal erase size\n"); + } + } + + ret = register_device(name, start, len, erasesize); if (!ret) pr_info("%s device: %#x at %#x\n", name, len, start); else @@ -278,7 +289,7 @@ static int __init phram_param_call(const char *val, struct kernel_param *kp) } module_param_call(phram, phram_param_call, NULL, NULL, 000); -MODULE_PARM_DESC(phram, "Memory region to map. \"phram=,,\""); +MODULE_PARM_DESC(phram, "Memory region to map. \"phram=,,[,]\""); static int __init init_phram(void) diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c index 67823de..5eee2a6 100644 --- a/drivers/mtd/devices/phram.c +++ b/drivers/mtd/devices/phram.c @@ -5,14 +5,15 @@ * Usage: * * one commend line parameter per device, each in the form: - * phram=,, + * phram=,,[,] * may be up to 63 characters. - * and can be octal, decimal or hexadecimal. If followed - * by "ki", "Mi" or "Gi", the numbers will be interpreted as kilo, mega or - * gigabytes. + * , , and can be octal, decimal or + * hexadecimal. If followed by "ki", "Mi" or "Gi", the numbers + * will be interpreted as kilo, mega or gigabytes. + * is optional and defaults to PAGE_SIZE. * * Example: - * phram=swap,64Mi,128Mi phram=test,900Mi,1Mi + * phram=swap,64Mi,128Mi phram=test,900Mi,1Mi,64Ki */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt @@ -94,7 +95,8 @@ static void unregister_devices(void) } } -static int register_device(char *name, unsigned long start, unsigned long len) +static int register_device(char *name, unsigned long start, + unsigned long len, unsigned long erasesize) { struct phram_mtd_list *new; int ret = -ENOMEM; @@ -121,7 +123,7 @@ static int register_device(char *name, unsigned long start, unsigned long len) new->mtd._write = phram_write; new->mtd.owner = THIS_MODULE; new->mtd.type = MTD_RAM; - new->mtd.erasesize = PAGE_SIZE; + new->mtd.erasesize = erasesize; new->mtd.writesize = 1;