From a42930c635d00afa9dab80476eae964213694455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Fache?= Date: Tue, 4 Oct 2011 18:35:46 +0200 Subject: [PATCH] phram: make kernel boot command line arguments work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. 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 --- drivers/mtd/devices/phram.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c index 23423bd..93c7ebf 100644 --- a/drivers/mtd/devices/phram.c +++ b/drivers/mtd/devices/phram.c @@ -233,7 +233,12 @@ static inline void kill_final_newline(char *str) return 1; \ } while (0) -static int phram_setup(const char *val, struct kernel_param *kp) +#ifndef MODULE +static int phram_init_called; +static __initdata char phram_paramline[64+12+12]; +#endif + +static int phram_setup2(const char *val) { char buf[64+12+12], *str = buf; char *token[3]; @@ -282,13 +287,47 @@ static int phram_setup(const char *val, struct kernel_param *kp) return ret; } +static int phram_setup(const char *val, struct kernel_param *kp) +{ +#ifdef MODULE + return phram_setup2(val); +#else + /* 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; +#endif +} + module_param_call(phram, phram_setup, NULL, NULL, 000); MODULE_PARM_DESC(phram, "Memory region to map. \"phram=,,\""); static int __init init_phram(void) { - return 0; + int ret = 0; + +#ifndef MODULE + if (strlen(phram_paramline)) + ret = phram_setup2(phram_paramline); + phram_init_called = 1; +#endif + + return ret; } static void __exit cleanup_phram(void) -- 1.7.0.4