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