public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] phram: make kernel boot command line arguments work
@ 2011-10-17 15:40 h-fache
  2011-10-18  0:32 ` Jörn Engel
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: h-fache @ 2011-10-17 15:40 UTC (permalink / raw)
  To: linux-mtd; +Cc: joern, joern, Hervé Fache, dedekind1

From: Hervé Fache <h-fache@ti.com>

This patch is based on Ville Herva's similar patch to block2mtd.

Trying to pass kernel command line arguments at boot-time did not work, as
phram_setup() was called so early that kmalloc() was not functional.

This patch only saves the option string at the early boot stage, and parses
it later when init_phram() is called. This is determined by the fact that
init was called, or not.

With this patch, I can boot with a statically-compiled phram, and mount a
ext2 root fs from physical RAM, without the need for a initrd.

Signed-off-by: Hervé Fache <h-fache@ti.com>
---
 drivers/mtd/devices/phram.c |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 23423bd..6d58bf0 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -233,7 +233,10 @@ static inline void kill_final_newline(char *str)
 	return 1;		\
 } while (0)
 
-static int phram_setup(const char *val, struct kernel_param *kp)
+static int phram_init_called;
+static __initdata char phram_paramline[64+12+12];
+
+static int phram_setup2(const char *val)
 {
 	char buf[64+12+12], *str = buf;
 	char *token[3];
@@ -282,13 +285,41 @@ static int phram_setup(const char *val, struct kernel_param *kp)
 	return ret;
 }
 
+static int phram_setup(const char *val, struct kernel_param *kp)
+{
+	/* If more parameters are later passed in via
+	   /sys/module/phram/parameters/phram
+	   and init_phram() has already been called,
+	   we can parse the argument directly. */
+
+	if (phram_init_called)
+		return phram_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, phram_setup() is
+	   called so early that it is not possible to resolve
+	   the device (kmalloc() fails). Defer that work to
+	   phram_setup2(), called by init_phram(). */
+
+	strlcpy(phram_paramline, val, sizeof(phram_paramline));
+
+	return 0;
+}
+
 module_param_call(phram, phram_setup, NULL, NULL, 000);
 MODULE_PARM_DESC(phram, "Memory region to map. \"phram=<name>,<start>,<length>\"");
 
 
 static int __init init_phram(void)
 {
-	return 0;
+	int ret = 0;
+
+	if (strlen(phram_paramline))
+		ret = phram_setup2(phram_paramline);
+	phram_init_called = 1;
+
+	return ret;
 }
 
 static void __exit cleanup_phram(void)
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2011-10-29 20:10 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-17 15:40 [PATCH] phram: make kernel boot command line arguments work h-fache
2011-10-18  0:32 ` Jörn Engel
2011-10-18  8:05   ` Fache, Herve
2011-10-20 16:34   ` Artem Bityutskiy
2011-10-20 16:16 ` Artem Bityutskiy
2011-10-21  8:51   ` Fache, Herve
2011-10-25  7:37     ` Artem Bityutskiy
2011-10-25  9:09       ` Fache, Herve
2011-10-25 19:58         ` Jörn Engel
2011-10-29 20:10         ` Artem Bityutskiy
2011-10-20 16:20 ` Artem Bityutskiy
2011-10-21  8:49   ` Fache, Herve
2011-10-25  7:32     ` Artem Bityutskiy
2011-10-25  9:07       ` Fache, Herve
2011-10-29 20:09 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox