300-block2mtd_init.patch 6.6 KB

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