* [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)
@ 2006-07-07 12:22 Ville Herva
2006-07-10 22:31 ` Ville Herva
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Ville Herva @ 2006-07-07 12:22 UTC (permalink / raw)
To: linux-mtd
Trying to pass kernel command line arguments to block2mtd at boot-time does
not work currently. block2mtd_setup() is called so early that kmalloc()
fails nevermind being able to do open_bdev_excl() (which requires rootfs to
be mounted. This patch only saves the option string at the early boot stage,
and parses them later when block2mtd_init() is called. If open_bdev_excl()
fails, open_by_devnum(name_to_dev_t()) is tried instead, which makes it
possible to initialize the driver before rootfs has been mounted. Also gets
rid of the superfluous parse_name() that only checks if name is longer than
80 chars and copies it to a string that is not kfreed.
With this patch, I can boot statically compiled block2mtd, and mount jffs2
as rootfs (without modules or initrd), with lilo config like this:
root=/dev/mtdblock0
append="rootfstype=jffs2 block2mtd.block2mtd=/dev/hdc2,65536"
(Note that rootfstype=jffs2 is required, since the kernel only tries
filesystems without "nodev" attribute by default, and jffs is "nodev").
Compared to first version of this patch, this one does not copy the
parameters to the global buffer if init has already been called, and the
global array is marked as __initdata.
Compared to the second version of this patch, module build is fixed.
From: Ville Herva <vherva@vianova.fi>
Signed-off-by: Ville Herva <vherva@vianova.fi>
--- linux-mtd-GIT/drivers/mtd/devices/block2mtd.c 2006-07-05 23:06:10.000000000 +0300
+++ linux-2.6.17.3.NEW3/drivers/mtd/devices/block2mtd.c 2006-07-07 15:04:48.000000000 +0300
@@ -18,6 +18,7 @@
#include <linux/mtd/mtd.h>
#include <linux/buffer_head.h>
#include <linux/mutex.h>
+#include <linux/mount.h>
#define VERSION "$Revision: 1.30 $"
@@ -236,6 +237,8 @@ static int _block2mtd_write(struct block
}
return 0;
}
+
+
static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
size_t *retlen, const u_char *buf)
{
@@ -299,6 +302,19 @@ static struct block2mtd_dev *add_device(
/* Get a handle on the device */
bdev = open_bdev_excl(devname, O_RDWR, NULL);
+#ifndef MODULE
+ if (IS_ERR(bdev)) {
+
+ /* We might not have rootfs mounted at this point. Try
+ to resolve the device name by other means. */
+
+ dev_t dev = name_to_dev_t(devname);
+ if (dev != 0) {
+ bdev = open_by_devnum(dev, FMODE_WRITE | FMODE_READ);
+ }
+ }
+#endif
+
if (IS_ERR(bdev)) {
ERROR("error: cannot open device %s", devname);
goto devinit_err;
@@ -393,26 +409,6 @@ static int parse_num(size_t *num, const
}
-static int parse_name(char **pname, const char *token, size_t limit)
-{
- size_t len;
- char *name;
-
- len = strlen(token) + 1;
- if (len > limit)
- return -ENOSPC;
-
- name = kmalloc(len, GFP_KERNEL);
- if (!name)
- return -ENOMEM;
-
- strcpy(name, token);
-
- *pname = name;
- return 0;
-}
-
-
static inline void kill_final_newline(char *str)
{
char *newline = strrchr(str, '\n');
@@ -426,9 +422,15 @@ static inline void kill_final_newline(ch
return 0; \
} while (0)
-static int block2mtd_setup(const char *val, struct kernel_param *kp)
+#ifndef MODULE
+static int block2mtd_init_called = 0;
+static __initdata char block2mtd_paramline[80 + 12]; /* 80 for device, 12 for erase size */
+#endif
+
+
+static int block2mtd_setup2(const char *val)
{
- char buf[80+12]; /* 80 for device, 12 for erase size */
+ char buf[80 + 12]; /* 80 for device, 12 for erase size */
char *str = buf;
char *token[2];
char *name;
@@ -450,13 +452,9 @@ static int block2mtd_setup(const char *v
if (!token[0])
parse_err("no argument");
- ret = parse_name(&name, token[0], 80);
- if (ret == -ENOMEM)
- parse_err("out of memory");
- if (ret == -ENOSPC)
- parse_err("name too long");
- if (ret)
- return 0;
+ name = token[0];
+ if (strlen(name) + 1 > 80)
+ parse_err("device name too long");
if (token[1]) {
ret = parse_num(&erase_size, token[1]);
@@ -472,13 +470,47 @@ static int block2mtd_setup(const char *v
}
+static int block2mtd_setup(const char *val, struct kernel_param *kp)
+{
+#ifdef MODULE
+ return block2mtd_setup2(val);
+#else
+ /* If more parameters are later passed in via
+ /sys/module/block2mtd/parameters/block2mtd
+ and block2mtd_init() has already been called,
+ we can parse the argument now. */
+
+ if (block2mtd_init_called)
+ return block2mtd_setup2(val);
+
+ /* During early boot stage, we only save the parameters
+ here. We must parse them later: if the param passed
+ from kernel boot command line, block2mtd_setup() is
+ called so early that it is not possible to resolve
+ the device (even kmalloc() fails). Deter that work to
+ block2mtd_setup2(). */
+
+ strlcpy(block2mtd_paramline, val, sizeof(block2mtd_paramline));
+
+ return 0;
+#endif
+}
+
+
module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200);
MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=<dev>[,<erasesize>]\"");
static int __init block2mtd_init(void)
{
+ int ret = 0;
INFO("version " VERSION);
- return 0;
+
+#ifndef MODULE
+ ret = block2mtd_setup2(block2mtd_paramline);
+ block2mtd_init_called = 1;
+#endif
+
+ return ret;
}
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)
2006-07-07 12:22 [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3) Ville Herva
@ 2006-07-10 22:31 ` Ville Herva
2006-07-11 6:23 ` Ville Herva
2006-07-12 9:50 ` [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3) Jörn Engel
2 siblings, 0 replies; 12+ messages in thread
From: Ville Herva @ 2006-07-10 22:31 UTC (permalink / raw)
To: linux-mtd
On Fri, Jul 07, 2006 at 03:22:21PM +0300, you [Ville Herva] wrote:
>
> --- linux-mtd-GIT/drivers/mtd/devices/block2mtd.c 2006-07-05 23:06:10.000000000 +0300
> +++ linux-2.6.17.3.NEW3/drivers/mtd/devices/block2mtd.c 2006-07-07 15:04:48.000000000 +0300
For the record: I tested this variant of the patch in the following ways:
- block2mtd compiled in statically, no block2mtd.block2mtd kernel parameter
- block2mtd compiled in statically, block2mtd.block2mtd=/dev/hda2 kernel parameter
- block2mtd compiled as a module, no block2mtd.block2mtd kernel parameter
- insert block2mtd.ko with no arguments, later
echo /dev/hda2 > /sys/module/block2mtd/parameters/block2mtd
- insert block2mtd.ko with block2mtd=/dev/hda2 argument
- block2mtd compiled in statically, block2mtd.block2mtd=/dev/hda2 kernel parameter
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)
2006-07-07 12:22 [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3) Ville Herva
2006-07-10 22:31 ` Ville Herva
@ 2006-07-11 6:23 ` Ville Herva
2006-07-12 9:50 ` Jörn Engel
2006-07-12 9:50 ` [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3) Jörn Engel
2 siblings, 1 reply; 12+ messages in thread
From: Ville Herva @ 2006-07-11 6:23 UTC (permalink / raw)
To: linux-mtd
Few notes about the admittedly ugly #ifndef MODULE chunks:
On Fri, Jul 07, 2006 at 03:22:21PM +0300, you [Ville Herva] wrote:
>
> --- linux-mtd-GIT/drivers/mtd/devices/block2mtd.c 2006-07-05 23:06:10.000000000 +0300
> +++ linux-2.6.17.3.NEW3/drivers/mtd/devices/block2mtd.c 2006-07-07 15:04:48.000000000 +0300
> bdev = open_bdev_excl(devname, O_RDWR, NULL);
> +#ifndef MODULE
> + dev_t dev = name_to_dev_t(devname);
> +#endif
Apparently, name_to_dev_t() is not exported to use in modules (which kind of
makes sense - there shouldn't be need as rootfs should already be available
when a module is being loaded.) So I had to #ifdef it. And on the other
hand, open_bdev_excl() should be enough for modules anyway.
> +#ifndef MODULE
> +static int block2mtd_init_called = 0;
> +static __initdata char block2mtd_paramline[80 + 12]; /* 80 for device, 12 for erase size */
> +#endif
The __initdata variable gave warnings when compiling with -DMODULE (it was
referred, but not on a possible call path.) I decided to #ifdef it away, and
take block2mtd_init_called away as well. At least this saves some memory.
> +{
> +#ifdef MODULE
> + return block2mtd_setup2(val);
> +#else
> + if (block2mtd_init_called)
> + return block2mtd_setup2(val);
> + strlcpy(block2mtd_paramline, val, sizeof(block2mtd_paramline));
> + return 0;
> +#endif
This should make sure that the behaviour is exactly the same as before in
-DMODULE and echo XX > /sys/module/block2mtd/parameters/block2mtd cases.
Specifically, static char block2mtd_paramline[80 + 12]; instruduced an
additional 92 char upper limit for the device name len. With the new patch,
this limit is only introduced for the kernel boot param (kernel internal
name_to_dev_t() probably won't accept anything longer anyway, but
open_bdev_excl() might, as it takes paths to the filesystem.)
Jörn, the #ifdef MODULE do clutter up the code, so I leave it to you as the
maintainer to decide if they are worth it.
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)
2006-07-11 6:23 ` Ville Herva
@ 2006-07-12 9:50 ` Jörn Engel
2006-07-12 17:24 ` Ville Herva
0 siblings, 1 reply; 12+ messages in thread
From: Jörn Engel @ 2006-07-12 9:50 UTC (permalink / raw)
To: Ville Herva; +Cc: linux-mtd
On Tue, 11 July 2006 09:23:42 +0300, Ville Herva wrote:
>
> Jörn, the #ifdef MODULE do clutter up the code, so I leave it to you as the
> maintainer to decide if they are worth it.
Good enough for now. If the klibc discussion ever settles, the early
initialization code could get moved to userspace.
Jörn
--
Schrödinger's cat is <BLINK>not</BLINK> dead.
-- Illiad
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)
2006-07-12 9:50 ` Jörn Engel
@ 2006-07-12 17:24 ` Ville Herva
2006-07-13 13:39 ` Jörn Engel
0 siblings, 1 reply; 12+ messages in thread
From: Ville Herva @ 2006-07-12 17:24 UTC (permalink / raw)
To: Jörn Engel; +Cc: linux-mtd
On Wed, Jul 12, 2006 at 11:50:48AM +0200, you [Jörn Engel] wrote:
> On Tue, 11 July 2006 09:23:42 +0300, Ville Herva wrote:
> >
> > #ifdef MODULE clutter
>
> Good enough for now. If the klibc discussion ever settles, the early
> initialization code could get moved to userspace.
Good.
One thing I only noticed now, is that while static compile + no boot time
argument test case works, it does unnecessarily printk
error: cannot open device ""
since the argument parsing is invoked even when no argument is supplied.
This is of course harmless, as nothing really happens, but
- ret = block2mtd_setup2(block2mtd_paramline);
+ if (strlen(block2mtd_paramline))
+ ret = block2mtd_setup2(block2mtd_paramline);
might be sensible in block2mtd_init(). (I'm trusting that .initdata and
block2mtd_paramline are zero-initialized.)
-- v --
v@iki.fi
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)
2006-07-12 17:24 ` Ville Herva
@ 2006-07-13 13:39 ` Jörn Engel
2006-07-13 13:49 ` Ville Herva
2006-07-13 15:41 ` [PATCH] [MTD] block2mtd.c: Remove unnecessary parsing of empty boot-time argument Ville Herva
0 siblings, 2 replies; 12+ messages in thread
From: Jörn Engel @ 2006-07-13 13:39 UTC (permalink / raw)
To: Ville Herva; +Cc: linux-mtd
On Wed, 12 July 2006 20:24:00 +0300, Ville Herva wrote:
>
> One thing I only noticed now, is that while static compile + no boot time
> argument test case works, it does unnecessarily printk
> error: cannot open device ""
> since the argument parsing is invoked even when no argument is supplied.
> This is of course harmless, as nothing really happens, but
>
> - ret = block2mtd_setup2(block2mtd_paramline);
> + if (strlen(block2mtd_paramline))
> + ret = block2mtd_setup2(block2mtd_paramline);
>
> might be sensible in block2mtd_init(). (I'm trusting that .initdata and
> block2mtd_paramline are zero-initialized.)
Looks sane. Can you send a proper patch for this?
Acked-by: Joern Engel <joern@wohnheim.fh-wedel.de>
Jörn
--
People will accept your ideas much more readily if you tell them
that Benjamin Franklin said it first.
-- unknown
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)
2006-07-13 13:39 ` Jörn Engel
@ 2006-07-13 13:49 ` Ville Herva
2006-07-13 14:55 ` Jörn Engel
2006-07-13 15:41 ` [PATCH] [MTD] block2mtd.c: Remove unnecessary parsing of empty boot-time argument Ville Herva
1 sibling, 1 reply; 12+ messages in thread
From: Ville Herva @ 2006-07-13 13:49 UTC (permalink / raw)
To: Jörn Engel; +Cc: linux-mtd
On Thu, Jul 13, 2006 at 03:39:59PM +0200, you [Jörn Engel] wrote:
> >
> > - ret = block2mtd_setup2(block2mtd_paramline);
> > + if (strlen(block2mtd_paramline))
> > + ret = block2mtd_setup2(block2mtd_paramline);
> >
> > might be sensible in block2mtd_init(). (I'm trusting that .initdata and
> > block2mtd_paramline are zero-initialized.)
>
> Looks sane. Can you send a proper patch for this?
>
> Acked-by: Joern Engel <joern@wohnheim.fh-wedel.de>
Sure. Do you prefer an incremental or the whole patch re-done?
-- v --
v@iki.fi
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)
2006-07-13 13:49 ` Ville Herva
@ 2006-07-13 14:55 ` Jörn Engel
2006-07-13 21:02 ` David Woodhouse
0 siblings, 1 reply; 12+ messages in thread
From: Jörn Engel @ 2006-07-13 14:55 UTC (permalink / raw)
To: Ville Herva; +Cc: linux-mtd
On Thu, 13 July 2006 16:49:51 +0300, Ville Herva wrote:
>
> Sure. Do you prefer an incremental or the whole patch re-done?
I don't have a strong preference. Dwmw2, do you?
If in doubt, just send an incremental patch. Applying both shouldn't
be a problem.
Jörn
--
The only real mistake is the one from which we learn nothing.
-- John Powell
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)
2006-07-13 14:55 ` Jörn Engel
@ 2006-07-13 21:02 ` David Woodhouse
2006-07-13 21:33 ` Ville Herva
0 siblings, 1 reply; 12+ messages in thread
From: David Woodhouse @ 2006-07-13 21:02 UTC (permalink / raw)
To: Jörn Engel; +Cc: linux-mtd, Ville Herva
On Thu, 2006-07-13 at 16:55 +0200, Jörn Engel wrote:
>
> I don't have a strong preference. Dwmw2, do you?
>
> If in doubt, just send an incremental patch. Applying both shouldn't
> be a problem.
A combined patch is probably best -- it's easier to apply, without
having to go find the current version of the previous patch too.
--
dwmw2
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)
2006-07-13 21:02 ` David Woodhouse
@ 2006-07-13 21:33 ` Ville Herva
0 siblings, 0 replies; 12+ messages in thread
From: Ville Herva @ 2006-07-13 21:33 UTC (permalink / raw)
To: David Woodhouse; +Cc: linux-mtd, Jörn Engel
On Thu, Jul 13, 2006 at 10:02:37PM +0100, you [David Woodhouse] wrote:
> On Thu, 2006-07-13 at 16:55 +0200, Jörn Engel wrote:
> >
> > I don't have a strong preference. Dwmw2, do you?
> >
> > If in doubt, just send an incremental patch. Applying both shouldn't
> > be a problem.
>
> A combined patch is probably best -- it's easier to apply, without
> having to go find the current version of the previous patch too.
Oops, I already sent an incremental, but fortunately it was blocked by the
mailing list software (suspicious headers). I'll do a combined in a jiffy.
-- v --
v@iki.fi
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH] [MTD] block2mtd.c: Remove unnecessary parsing of empty boot-time argument
2006-07-13 13:39 ` Jörn Engel
2006-07-13 13:49 ` Ville Herva
@ 2006-07-13 15:41 ` Ville Herva
1 sibling, 0 replies; 12+ messages in thread
From: Ville Herva @ 2006-07-13 15:41 UTC (permalink / raw)
To: linux-mtd; +Cc: Jörn Engel
Statically compiled block2mtd driver with no boot-time parameter works, but
it does unnecessarily printk
error: cannot open device ""
since argument parsing is invoked even when no argument is supplied.
This is harmless as no "" device is found, but perhaps worth correcting.
This is an incremental patch against the "Make kernel boot command line
arguments work (try 3)" patch.
From: Ville Herva <vherva@vianova.fi>
Signed-off-by: Ville Herva <vherva@vianova.fi>
Acked-by: Joern Engel <joern@wohnheim.fh-wedel.de>
--- linux-2.6.17.3.NEW3/drivers/mtd/devices/block2mtd.c 2006-07-07 15:05:40.000000000 +0300
+++ linux-2.6.17.3.NEW4/drivers/mtd/devices/block2mtd.c 2006-07-13 18:28:31.000000000 +0300
@@ -507,7 +507,8 @@ static int __init block2mtd_init(void)
INFO("version " VERSION);
#ifndef MODULE
- ret = block2mtd_setup2(block2mtd_paramline);
+ if (strlen(block2mtd_paramline))
+ ret = block2mtd_setup2(block2mtd_paramline);
block2mtd_init_called = 1;
#endif
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3)
2006-07-07 12:22 [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3) Ville Herva
2006-07-10 22:31 ` Ville Herva
2006-07-11 6:23 ` Ville Herva
@ 2006-07-12 9:50 ` Jörn Engel
2 siblings, 0 replies; 12+ messages in thread
From: Jörn Engel @ 2006-07-12 9:50 UTC (permalink / raw)
To: Ville Herva; +Cc: linux-mtd
On Fri, 7 July 2006 15:22:21 +0300, Ville Herva wrote:
>
> From: Ville Herva <vherva@vianova.fi>
> Signed-off-by: Ville Herva <vherva@vianova.fi>
Acked-by: Joern Engel <joern@wh.fh-wedel.de>
Jörn
--
Time? What's that? Time is only worth what you do with it.
-- Theo de Raadt
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2006-07-13 21:34 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-07 12:22 [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3) Ville Herva
2006-07-10 22:31 ` Ville Herva
2006-07-11 6:23 ` Ville Herva
2006-07-12 9:50 ` Jörn Engel
2006-07-12 17:24 ` Ville Herva
2006-07-13 13:39 ` Jörn Engel
2006-07-13 13:49 ` Ville Herva
2006-07-13 14:55 ` Jörn Engel
2006-07-13 21:02 ` David Woodhouse
2006-07-13 21:33 ` Ville Herva
2006-07-13 15:41 ` [PATCH] [MTD] block2mtd.c: Remove unnecessary parsing of empty boot-time argument Ville Herva
2006-07-12 9:50 ` [PATCH] [MTD] block2mtd.c: Make kernel boot command line arguments work (try 3) Jörn Engel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox