From: Felix Fietkau Date: Thu, 10 Apr 2014 14:43:17 +0000 (+0000) Subject: x86: try harder to attach block2mtd to fix boot issues on devices with longer delays X-Git-Tag: reboot~7482 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f02e3a2a4a656aa550ad37e3c547a309872a011d;p=openwrt%2Fstaging%2Fxback.git x86: try harder to attach block2mtd to fix boot issues on devices with longer delays Signed-off-by: Felix Fietkau SVN-Revision: 40444 --- diff --git a/target/linux/generic/patches-3.10/441-block2mtd_probe.patch b/target/linux/generic/patches-3.10/441-block2mtd_probe.patch index 0b2e80cdac..a9c100da10 100644 --- a/target/linux/generic/patches-3.10/441-block2mtd_probe.patch +++ b/target/linux/generic/patches-3.10/441-block2mtd_probe.patch @@ -1,10 +1,108 @@ --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c -@@ -234,6 +234,7 @@ static struct block2mtd_dev *add_device( - /* We might not have rootfs mounted at this point. Try - to resolve the device name by other means. */ +@@ -7,6 +7,7 @@ + * Licence: GPL + */ + #include ++#include + #include + #include + #include +@@ -211,13 +212,14 @@ static void block2mtd_free_device(struct + + /* FIXME: ensure that mtd->size % erase_size == 0 */ +-static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname) ++static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout) + { + const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL; +- struct block_device *bdev; ++ struct block_device *bdev = ERR_PTR(-ENODEV); + struct block2mtd_dev *dev; + struct mtd_partition *part; + char *name; ++ int i; + + if (!devname) + return NULL; +@@ -228,15 +230,20 @@ static struct block2mtd_dev *add_device( + + /* Get a handle on the device */ + bdev = blkdev_get_by_path(devname, mode, dev); ++ + #ifndef MODULE +- if (IS_ERR(bdev)) { ++ for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { ++ dev_t devt; + +- /* We might not have rootfs mounted at this point. Try +- to resolve the device name by other means. */ ++ if (i) ++ msleep(1000); + wait_for_device_probe(); - dev_t devt = name_to_dev_t(devname); - if (devt) - bdev = blkdev_get_by_dev(devt, mode, dev); ++ ++ devt = name_to_dev_t(devname); ++ if (!devt) ++ continue; + +- dev_t devt = name_to_dev_t(devname); +- if (devt) +- bdev = blkdev_get_by_dev(devt, mode, dev); ++ bdev = blkdev_get_by_dev(devt, mode, dev); + } + #endif + +@@ -360,11 +367,12 @@ static char block2mtd_paramline[80 + 12] + + static int block2mtd_setup2(const char *val) + { +- char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */ ++ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */ + char *str = buf; +- char *token[3]; ++ char *token[4]; + char *name; + size_t erase_size = PAGE_SIZE; ++ unsigned long timeout = 0; + int i, ret; + + if (strnlen(val, sizeof(buf)) >= sizeof(buf)) +@@ -373,7 +381,7 @@ static int block2mtd_setup2(const char * + strcpy(str, val); + kill_final_newline(str); + +- for (i = 0; i < 3; i++) ++ for (i = 0; i < 4; i++) + token[i] = strsep(&str, ","); + + if (str) +@@ -395,7 +403,10 @@ static int block2mtd_setup2(const char * + if (token[2] && (strlen(token[2]) + 1 > 80)) + parse_err("mtd device name too long"); + +- add_device(name, erase_size, token[2]); ++ if (token[3] && kstrtoul(token[3], 0, &timeout)) ++ parse_err("invalid timeout"); ++ ++ add_device(name, erase_size, token[2], timeout); + + return 0; + } +@@ -429,7 +440,7 @@ static int block2mtd_setup(const char *v + + + module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200); +-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=[,[,]]\""); ++MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=[,[,[,]]]\""); + + static int __init block2mtd_init(void) + { +@@ -462,7 +473,7 @@ static void block2mtd_exit(void) + } + + +-module_init(block2mtd_init); ++late_initcall(block2mtd_init); + module_exit(block2mtd_exit); + + MODULE_LICENSE("GPL"); diff --git a/target/linux/generic/patches-3.12/440-block2mtd_init.patch b/target/linux/generic/patches-3.12/440-block2mtd_init.patch index 4617bf4170..198d9615b1 100644 --- a/target/linux/generic/patches-3.12/440-block2mtd_init.patch +++ b/target/linux/generic/patches-3.12/440-block2mtd_init.patch @@ -89,7 +89,7 @@ } } + if (token[2] && (strlen(token[2]) + 1 > 80)) -+ parse_err("mtd device name too long"); ++ pr_err("mtd device name too long\n"); - add_device(name, erase_size); + add_device(name, erase_size, token[2]); diff --git a/target/linux/generic/patches-3.12/441-block2mtd_probe.patch b/target/linux/generic/patches-3.12/441-block2mtd_probe.patch index 28ed2ce210..5cfa0b2b91 100644 --- a/target/linux/generic/patches-3.12/441-block2mtd_probe.patch +++ b/target/linux/generic/patches-3.12/441-block2mtd_probe.patch @@ -1,10 +1,108 @@ --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c -@@ -233,6 +233,7 @@ static struct block2mtd_dev *add_device( - /* We might not have rootfs mounted at this point. Try - to resolve the device name by other means. */ +@@ -10,6 +10,7 @@ + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include ++#include + #include + #include + #include +@@ -210,13 +211,14 @@ static void block2mtd_free_device(struct + + + /* FIXME: ensure that mtd->size % erase_size == 0 */ +-static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname) ++static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout) + { + const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL; +- struct block_device *bdev; ++ struct block_device *bdev = ERR_PTR(-ENODEV); + struct block2mtd_dev *dev; + struct mtd_partition *part; + char *name; ++ int i; + + if (!devname) + return NULL; +@@ -227,15 +229,20 @@ static struct block2mtd_dev *add_device( + + /* Get a handle on the device */ + bdev = blkdev_get_by_path(devname, mode, dev); ++ + #ifndef MODULE +- if (IS_ERR(bdev)) { ++ for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { ++ dev_t devt; + +- /* We might not have rootfs mounted at this point. Try +- to resolve the device name by other means. */ ++ if (i) ++ msleep(1000); + wait_for_device_probe(); - dev_t devt = name_to_dev_t(devname); - if (devt) - bdev = blkdev_get_by_dev(devt, mode, dev); ++ ++ devt = name_to_dev_t(devname); ++ if (!devt) ++ continue; + +- dev_t devt = name_to_dev_t(devname); +- if (devt) +- bdev = blkdev_get_by_dev(devt, mode, dev); ++ bdev = blkdev_get_by_dev(devt, mode, dev); + } + #endif + +@@ -354,11 +361,12 @@ static char block2mtd_paramline[80 + 12] + + static int block2mtd_setup2(const char *val) + { +- char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */ ++ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */ + char *str = buf; +- char *token[3]; ++ char *token[4]; + char *name; + size_t erase_size = PAGE_SIZE; ++ unsigned long timeout = 0; + int i, ret; + + if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { +@@ -369,7 +377,7 @@ static int block2mtd_setup2(const char * + strcpy(str, val); + kill_final_newline(str); + +- for (i = 0; i < 3; i++) ++ for (i = 0; i < 4; i++) + token[i] = strsep(&str, ","); + + if (str) { +@@ -398,7 +406,10 @@ static int block2mtd_setup2(const char * + if (token[2] && (strlen(token[2]) + 1 > 80)) + pr_err("mtd device name too long\n"); + +- add_device(name, erase_size, token[2]); ++ if (token[3] && kstrtoul(token[3], 0, &timeout)) ++ pr_err("invalid timeout\n"); ++ ++ add_device(name, erase_size, token[2], timeout); + + return 0; + } +@@ -432,7 +443,7 @@ static int block2mtd_setup(const char *v + + + module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200); +-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=[,[,]]\""); ++MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=[,[,[,]]]\""); + + static int __init block2mtd_init(void) + { +@@ -466,7 +477,7 @@ static void block2mtd_exit(void) + } + + +-module_init(block2mtd_init); ++late_initcall(block2mtd_init); + module_exit(block2mtd_exit); + + MODULE_LICENSE("GPL"); diff --git a/target/linux/generic/patches-3.12/442-block2mtd_logmessages.patch b/target/linux/generic/patches-3.12/442-block2mtd_logmessages.patch deleted file mode 100644 index 07487e1c4a..0000000000 --- a/target/linux/generic/patches-3.12/442-block2mtd_logmessages.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/drivers/mtd/devices/block2mtd.c -+++ b/drivers/mtd/devices/block2mtd.c -@@ -397,7 +397,7 @@ static int block2mtd_setup2(const char * - } - } - if (token[2] && (strlen(token[2]) + 1 > 80)) -- parse_err("mtd device name too long"); -+ pr_err("mtd device name too long\n"); - - add_device(name, erase_size, token[2]); - diff --git a/target/linux/generic/patches-3.13/440-block2mtd_init.patch b/target/linux/generic/patches-3.13/440-block2mtd_init.patch index 2818bb9369..4af7c1bb1c 100644 --- a/target/linux/generic/patches-3.13/440-block2mtd_init.patch +++ b/target/linux/generic/patches-3.13/440-block2mtd_init.patch @@ -89,7 +89,7 @@ } } + if (token[2] && (strlen(token[2]) + 1 > 80)) -+ parse_err("mtd device name too long"); ++ pr_err("mtd device name too long\n"); - add_device(name, erase_size); + add_device(name, erase_size, token[2]); diff --git a/target/linux/generic/patches-3.13/441-block2mtd_probe.patch b/target/linux/generic/patches-3.13/441-block2mtd_probe.patch index 0b2e80cdac..3ab9d1a3fc 100644 --- a/target/linux/generic/patches-3.13/441-block2mtd_probe.patch +++ b/target/linux/generic/patches-3.13/441-block2mtd_probe.patch @@ -1,10 +1,108 @@ --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c -@@ -234,6 +234,7 @@ static struct block2mtd_dev *add_device( - /* We might not have rootfs mounted at this point. Try - to resolve the device name by other means. */ +@@ -10,6 +10,7 @@ + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include ++#include + #include + #include + #include +@@ -211,13 +212,14 @@ static void block2mtd_free_device(struct + + + /* FIXME: ensure that mtd->size % erase_size == 0 */ +-static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname) ++static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout) + { + const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL; +- struct block_device *bdev; ++ struct block_device *bdev = ERR_PTR(-ENODEV); + struct block2mtd_dev *dev; + struct mtd_partition *part; + char *name; ++ int i; + + if (!devname) + return NULL; +@@ -228,15 +230,20 @@ static struct block2mtd_dev *add_device( + + /* Get a handle on the device */ + bdev = blkdev_get_by_path(devname, mode, dev); ++ + #ifndef MODULE +- if (IS_ERR(bdev)) { ++ for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { ++ dev_t devt; + +- /* We might not have rootfs mounted at this point. Try +- to resolve the device name by other means. */ ++ if (i) ++ msleep(1000); + wait_for_device_probe(); - dev_t devt = name_to_dev_t(devname); - if (devt) - bdev = blkdev_get_by_dev(devt, mode, dev); ++ ++ devt = name_to_dev_t(devname); ++ if (!devt) ++ continue; + +- dev_t devt = name_to_dev_t(devname); +- if (devt) +- bdev = blkdev_get_by_dev(devt, mode, dev); ++ bdev = blkdev_get_by_dev(devt, mode, dev); + } + #endif + +@@ -355,11 +362,12 @@ static char block2mtd_paramline[80 + 12] + + static int block2mtd_setup2(const char *val) + { +- char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */ ++ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */ + char *str = buf; +- char *token[3]; ++ char *token[4]; + char *name; + size_t erase_size = PAGE_SIZE; ++ unsigned long timeout = 0; + int i, ret; + + if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { +@@ -370,7 +378,7 @@ static int block2mtd_setup2(const char * + strcpy(str, val); + kill_final_newline(str); + +- for (i = 0; i < 3; i++) ++ for (i = 0; i < 4; i++) + token[i] = strsep(&str, ","); + + if (str) { +@@ -399,7 +407,10 @@ static int block2mtd_setup2(const char * + if (token[2] && (strlen(token[2]) + 1 > 80)) + pr_err("mtd device name too long\n"); + +- add_device(name, erase_size, token[2]); ++ if (token[3] && kstrtoul(token[3], 0, &timeout)) ++ pr_err("invalid timeout\n"); ++ ++ add_device(name, erase_size, token[2], timeout); + + return 0; + } +@@ -433,7 +444,7 @@ static int block2mtd_setup(const char *v + + + module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200); +-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=[,[,]]\""); ++MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=[,[,[,]]]\""); + + static int __init block2mtd_init(void) + { +@@ -467,7 +478,7 @@ static void block2mtd_exit(void) + } + + +-module_init(block2mtd_init); ++late_initcall(block2mtd_init); + module_exit(block2mtd_exit); + + MODULE_LICENSE("GPL"); diff --git a/target/linux/generic/patches-3.13/442-block2mtd_logmessages.patch b/target/linux/generic/patches-3.13/442-block2mtd_logmessages.patch deleted file mode 100644 index 983106b54f..0000000000 --- a/target/linux/generic/patches-3.13/442-block2mtd_logmessages.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/drivers/mtd/devices/block2mtd.c -+++ b/drivers/mtd/devices/block2mtd.c -@@ -398,7 +398,7 @@ static int block2mtd_setup2(const char * - } - } - if (token[2] && (strlen(token[2]) + 1 > 80)) -- parse_err("mtd device name too long"); -+ pr_err("mtd device name too long\n"); - - add_device(name, erase_size, token[2]); - diff --git a/target/linux/generic/patches-3.14/440-block2mtd_init.patch b/target/linux/generic/patches-3.14/440-block2mtd_init.patch index 2818bb9369..4af7c1bb1c 100644 --- a/target/linux/generic/patches-3.14/440-block2mtd_init.patch +++ b/target/linux/generic/patches-3.14/440-block2mtd_init.patch @@ -89,7 +89,7 @@ } } + if (token[2] && (strlen(token[2]) + 1 > 80)) -+ parse_err("mtd device name too long"); ++ pr_err("mtd device name too long\n"); - add_device(name, erase_size); + add_device(name, erase_size, token[2]); diff --git a/target/linux/generic/patches-3.14/441-block2mtd_probe.patch b/target/linux/generic/patches-3.14/441-block2mtd_probe.patch index 0b2e80cdac..3ab9d1a3fc 100644 --- a/target/linux/generic/patches-3.14/441-block2mtd_probe.patch +++ b/target/linux/generic/patches-3.14/441-block2mtd_probe.patch @@ -1,10 +1,108 @@ --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c -@@ -234,6 +234,7 @@ static struct block2mtd_dev *add_device( - /* We might not have rootfs mounted at this point. Try - to resolve the device name by other means. */ +@@ -10,6 +10,7 @@ + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include ++#include + #include + #include + #include +@@ -211,13 +212,14 @@ static void block2mtd_free_device(struct + + + /* FIXME: ensure that mtd->size % erase_size == 0 */ +-static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname) ++static struct block2mtd_dev *add_device(char *devname, int erase_size, const char *mtdname, int timeout) + { + const fmode_t mode = FMODE_READ | FMODE_WRITE | FMODE_EXCL; +- struct block_device *bdev; ++ struct block_device *bdev = ERR_PTR(-ENODEV); + struct block2mtd_dev *dev; + struct mtd_partition *part; + char *name; ++ int i; + + if (!devname) + return NULL; +@@ -228,15 +230,20 @@ static struct block2mtd_dev *add_device( + + /* Get a handle on the device */ + bdev = blkdev_get_by_path(devname, mode, dev); ++ + #ifndef MODULE +- if (IS_ERR(bdev)) { ++ for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { ++ dev_t devt; + +- /* We might not have rootfs mounted at this point. Try +- to resolve the device name by other means. */ ++ if (i) ++ msleep(1000); + wait_for_device_probe(); - dev_t devt = name_to_dev_t(devname); - if (devt) - bdev = blkdev_get_by_dev(devt, mode, dev); ++ ++ devt = name_to_dev_t(devname); ++ if (!devt) ++ continue; + +- dev_t devt = name_to_dev_t(devname); +- if (devt) +- bdev = blkdev_get_by_dev(devt, mode, dev); ++ bdev = blkdev_get_by_dev(devt, mode, dev); + } + #endif + +@@ -355,11 +362,12 @@ static char block2mtd_paramline[80 + 12] + + static int block2mtd_setup2(const char *val) + { +- char buf[80 + 12 + 80]; /* 80 for device, 12 for erase size, 80 for name */ ++ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 8 for timeout */ + char *str = buf; +- char *token[3]; ++ char *token[4]; + char *name; + size_t erase_size = PAGE_SIZE; ++ unsigned long timeout = 0; + int i, ret; + + if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { +@@ -370,7 +378,7 @@ static int block2mtd_setup2(const char * + strcpy(str, val); + kill_final_newline(str); + +- for (i = 0; i < 3; i++) ++ for (i = 0; i < 4; i++) + token[i] = strsep(&str, ","); + + if (str) { +@@ -399,7 +407,10 @@ static int block2mtd_setup2(const char * + if (token[2] && (strlen(token[2]) + 1 > 80)) + pr_err("mtd device name too long\n"); + +- add_device(name, erase_size, token[2]); ++ if (token[3] && kstrtoul(token[3], 0, &timeout)) ++ pr_err("invalid timeout\n"); ++ ++ add_device(name, erase_size, token[2], timeout); + + return 0; + } +@@ -433,7 +444,7 @@ static int block2mtd_setup(const char *v + + + module_param_call(block2mtd, block2mtd_setup, NULL, NULL, 0200); +-MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=[,[,]]\""); ++MODULE_PARM_DESC(block2mtd, "Device to use. \"block2mtd=[,[,[,]]]\""); + + static int __init block2mtd_init(void) + { +@@ -467,7 +478,7 @@ static void block2mtd_exit(void) + } + + +-module_init(block2mtd_init); ++late_initcall(block2mtd_init); + module_exit(block2mtd_exit); + + MODULE_LICENSE("GPL"); diff --git a/target/linux/generic/patches-3.14/442-block2mtd_logmessages.patch b/target/linux/generic/patches-3.14/442-block2mtd_logmessages.patch deleted file mode 100644 index 983106b54f..0000000000 --- a/target/linux/generic/patches-3.14/442-block2mtd_logmessages.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/drivers/mtd/devices/block2mtd.c -+++ b/drivers/mtd/devices/block2mtd.c -@@ -398,7 +398,7 @@ static int block2mtd_setup2(const char * - } - } - if (token[2] && (strlen(token[2]) + 1 > 80)) -- parse_err("mtd device name too long"); -+ pr_err("mtd device name too long\n"); - - add_device(name, erase_size, token[2]); - diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile index 4b40e64de7..03aa350da2 100644 --- a/target/linux/x86/image/Makefile +++ b/target/linux/x86/image/Makefile @@ -53,15 +53,15 @@ ifneq ($(CONFIG_GRUB_IMAGES),) endef define Image/cmdline/jffs2-64k - block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait + block2mtd.block2mtd=$(ROOTPART),65536,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait endef define Image/cmdline/jffs2-128k - block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait + block2mtd.block2mtd=$(ROOTPART),131072,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait endef define Image/cmdline/squashfs - block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait + block2mtd.block2mtd=$(ROOTPART),65536,rootfs,5 root=/dev/mtdblock0 rootfstype=squashfs rootwait endef define Image/Build/grub2