summaryrefslogtreecommitdiffstats
path: root/target/linux/olpc/patches/300-block2mtd_init.patch
blob: 5e731311cd4a9edae295d09da10e7248298973a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
Index: linux-2.6.23/drivers/mtd/devices/block2mtd.c
===================================================================
--- linux-2.6.23.orig/drivers/mtd/devices/block2mtd.c	2007-12-06 23:30:31.583285849 +0100
+++ linux-2.6.23/drivers/mtd/devices/block2mtd.c	2007-12-06 23:31:29.970613152 +0100
@@ -20,6 +20,8 @@
 #include <linux/buffer_head.h>
 #include <linux/mutex.h>
 #include <linux/mount.h>
+#include <linux/list.h>
+#include <linux/delay.h>
 
 #define VERSION "$Revision: 1.30 $"
 
@@ -27,6 +29,12 @@
 #define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args)
 #define INFO(fmt, args...) printk(KERN_INFO "block2mtd: " fmt "\n" , ## args)
 
+struct retry {
+	struct list_head list;
+	const char *val;
+};
+
+static LIST_HEAD(retry_list);
 
 /* Info for the block device */
 struct block2mtd_dev {
@@ -38,10 +46,36 @@
 	char devname[0];
 };
 
+static int block2mtd_setup2(const char *val);
 
 /* Static info about the MTD, used in cleanup_module */
 static LIST_HEAD(blkmtd_device_list);
 
+static int add_retry(const char *val)
+{
+	struct retry *r = kmalloc(sizeof(struct retry), GFP_KERNEL);
+
+	INIT_LIST_HEAD(&r->list);
+	r->val = val;
+	list_add(&r->list, &retry_list);
+
+	return 0;
+}
+
+static int __init process_retries(void)
+{
+	struct list_head *p, *tmp;
+
+	list_for_each_safe(p, tmp, &retry_list) {
+		struct retry *r = list_entry(p, struct retry, list);
+		block2mtd_setup2(r->val);
+		msleep(100);
+		list_del(p);
+		kfree(r);
+	}
+	return 0;
+}
+rootfs_initcall(process_retries);
 
 static struct page *page_read(struct address_space *mapping, int index)
 {
@@ -518,7 +552,10 @@
 	if (token[2] && (strlen(token[2]) + 1 > 80))
 		parse_err("mtd device name too long");
 
-	add_device(name, erase_size, token[2]);
+	if (add_device(name, erase_size, token[2]) == NULL) {
+		add_retry(val);
+		return 0;
+	}
 
 	return 0;
 }
@@ -534,8 +571,11 @@
 	   and block2mtd_init() has already been called,
 	   we can parse the argument now. */
 
-	if (block2mtd_init_called)
+	if (block2mtd_init_called) {
+		/* if the call failed (e.g. because the device does not exist yet)
+		 * then try again just before attempting to mount the rootfs */
 		return block2mtd_setup2(val);
+	}
 
 	/* During early boot stage, we only save the parameters
 	   here. We must parse them later: if the param passed
Index: linux-2.6.23/init/do_mounts.c
===================================================================
--- linux-2.6.23.orig/init/do_mounts.c	2007-12-06 23:30:28.019082737 +0100
+++ linux-2.6.23/init/do_mounts.c	2007-12-06 23:30:32.459335774 +0100
@@ -241,16 +241,8 @@
 	return 1;
 }
 
-static unsigned int __initdata root_delay;
-static int __init root_delay_setup(char *str)
-{
-	root_delay = simple_strtoul(str, NULL, 0);
-	return 1;
-}
-
 __setup("rootflags=", root_data_setup);
 __setup("rootfstype=", fs_names_setup);
-__setup("rootdelay=", root_delay_setup);
 
 static void __init get_fs_names(char *page)
 {
@@ -426,18 +418,6 @@
 {
 	int is_floppy;
 
-	if (root_delay) {
-		printk(KERN_INFO "Waiting %dsec before mounting root device...\n",
-		       root_delay);
-		ssleep(root_delay);
-	}
-
-	/* wait for the known devices to complete their probing */
-	while (driver_probe_done() != 0)
-		msleep(100);
-
-	md_run_setup();
-
 	if (saved_root_name[0]) {
 		root_device_name = saved_root_name;
 		if (!strncmp(root_device_name, "mtd", 3)) {
Index: linux-2.6.23/init/main.c
===================================================================
--- linux-2.6.23.orig/init/main.c	2007-12-06 23:30:28.023082962 +0100
+++ linux-2.6.23/init/main.c	2007-12-06 23:30:32.463336000 +0100
@@ -65,6 +65,7 @@
 #ifdef CONFIG_X86_LOCAL_APIC
 #include <asm/smp.h>
 #endif
+#include "do_mounts.h"
 
 /*
  * This is one of the first .c files built. Error out early if we have compiler
@@ -662,13 +663,14 @@
 __setup("initcall_debug", initcall_debug_setup);
 
 extern initcall_t __initcall_start[], __initcall_end[];
+extern initcall_t __root_initcall_start[], __root_initcall_end[];
 
-static void __init do_initcalls(void)
+static void __init do_initcalls(initcall_t *start, initcall_t *end)
 {
 	initcall_t *call;
 	int count = preempt_count();
 
-	for (call = __initcall_start; call < __initcall_end; call++) {
+	for (call = start; call < end; call++) {
 		ktime_t t0, t1, delta;
 		char *msg = NULL;
 		char msgbuf[40];
@@ -737,7 +739,7 @@
 	usermodehelper_init();
 	driver_init();
 	init_irq_proc();
-	do_initcalls();
+	do_initcalls(__initcall_start, __initcall_end);
 }
 
 static int __initdata nosoftlockup;
@@ -810,6 +812,14 @@
 	panic("No init found.  Try passing init= option to kernel.");
 }
 
+static unsigned int __initdata root_delay;
+static int __init root_delay_setup(char *str)
+{
+	root_delay = simple_strtoul(str, NULL, 0);
+	return 1;
+}
+__setup("rootdelay=", root_delay_setup);
+
 static int __init kernel_init(void * unused)
 {
 	lock_kernel();
@@ -851,6 +861,17 @@
 
 	if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
 		ramdisk_execute_command = NULL;
+		if (root_delay) {
+			printk(KERN_INFO "Waiting %dsec before mounting root device...\n",
+		       root_delay);
+			ssleep(root_delay);
+		}
+		/* wait for the known devices to complete their probing */
+		while (driver_probe_done() != 0)
+			msleep(100);
+		md_run_setup();
+		do_initcalls(__root_initcall_start, __root_initcall_end);
+
 		prepare_namespace();
 	}
 
Index: linux-2.6.23/arch/i386/kernel/vmlinux.lds.S
===================================================================
--- linux-2.6.23.orig/arch/i386/kernel/vmlinux.lds.S	2007-12-06 23:30:28.035083650 +0100
+++ linux-2.6.23/arch/i386/kernel/vmlinux.lds.S	2007-12-06 23:30:32.467336225 +0100
@@ -146,6 +146,11 @@
 	INITCALLS
   	__initcall_end = .;
   }
+  .root_initcall.init : AT(ADDR(.root_initcall.init) - LOAD_OFFSET) {
+  	__root_initcall_start = .;
+	INITCALLS_ROOT
+  	__root_initcall_end = .;
+  }
   .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
   	__con_initcall_start = .;
 	*(.con_initcall.init)
Index: linux-2.6.23/include/asm-generic/vmlinux.lds.h
===================================================================
--- linux-2.6.23.orig/include/asm-generic/vmlinux.lds.h	2007-12-06 23:30:28.043084102 +0100
+++ linux-2.6.23/include/asm-generic/vmlinux.lds.h	2007-12-06 23:30:32.467336225 +0100
@@ -243,12 +243,14 @@
   	*(.initcall4s.init)						\
   	*(.initcall5.init)						\
   	*(.initcall5s.init)						\
-	*(.initcallrootfs.init)						\
   	*(.initcall6.init)						\
   	*(.initcall6s.init)						\
   	*(.initcall7.init)						\
   	*(.initcall7s.init)
 
+#define INITCALLS_ROOT						\
+	*(.initcallrootfs.init)
+
 #define PERCPU(align)							\
 	. = ALIGN(align);						\
 	__per_cpu_start = .;						\