Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

2014-11-07 Thread Brian Norris
On Fri, Nov 07, 2014 at 11:44:40AM +0200, Artem Bityutskiy wrote:
> On Sat, 2014-11-01 at 09:33 -0400, Rodrigo Freire wrote:
> > From: Felix Fietkau  
> > 
> > mtd: block2mtd: Ensure that block2mtd is presented timely on boot time
> > 
> > Currently, a block MTD device is not presented to the system on time, in 
> > order to start mounting the filesystems. This patch ensures that block2mtd 
> > is presented at the right time, so filesystems can be mounted on boot time. 
> > This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
> > over block2mtd devices as the root filesystem.
> > This patchset also adds a MTD device name and a timeout option to the 
> > driver. 
> > Original patchset: 
> > https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
> >  
> > https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
> >  
> 
> I  think you can mount jffs2 using /dev/mtdX, you do not need the block
> driver.

I realize you acknowledged your misunderstanding here, but for
posterity -- this point is addressed in the FAQ:

http://www.linux-mtd.infradead.org/faq/jffs2.html#L_mtdblock

Last I checked, the statement about busybox is still true. I think the
rootfs comment may be stale; I think the rootfstype= parameter can help
you.

Brian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

2014-11-07 Thread Artem Bityutskiy
On Sat, 2014-11-01 at 09:33 -0400, Rodrigo Freire wrote:
> From: Felix Fietkau  
> 
> mtd: block2mtd: Ensure that block2mtd is presented timely on boot time
> 
> Currently, a block MTD device is not presented to the system on time, in 
> order to start mounting the filesystems. This patch ensures that block2mtd 
> is presented at the right time, so filesystems can be mounted on boot time. 
> This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
> over block2mtd devices as the root filesystem.
> This patchset also adds a MTD device name and a timeout option to the driver. 
> Original patchset: 
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
>  
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
>  

I  think you can mount jffs2 using /dev/mtdX, you do not need the block
driver.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

2014-11-07 Thread Artem Bityutskiy
On Sat, 2014-11-01 at 09:33 -0400, Rodrigo Freire wrote:
 From: Felix Fietkau n...@openwrt.org 
 
 mtd: block2mtd: Ensure that block2mtd is presented timely on boot time
 
 Currently, a block MTD device is not presented to the system on time, in 
 order to start mounting the filesystems. This patch ensures that block2mtd 
 is presented at the right time, so filesystems can be mounted on boot time. 
 This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
 over block2mtd devices as the root filesystem.
 This patchset also adds a MTD device name and a timeout option to the driver. 
 Original patchset: 
 https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
  
 https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
  

I  think you can mount jffs2 using /dev/mtdX, you do not need the block
driver.

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

2014-11-07 Thread Brian Norris
On Fri, Nov 07, 2014 at 11:44:40AM +0200, Artem Bityutskiy wrote:
 On Sat, 2014-11-01 at 09:33 -0400, Rodrigo Freire wrote:
  From: Felix Fietkau n...@openwrt.org 
  
  mtd: block2mtd: Ensure that block2mtd is presented timely on boot time
  
  Currently, a block MTD device is not presented to the system on time, in 
  order to start mounting the filesystems. This patch ensures that block2mtd 
  is presented at the right time, so filesystems can be mounted on boot time. 
  This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
  over block2mtd devices as the root filesystem.
  This patchset also adds a MTD device name and a timeout option to the 
  driver. 
  Original patchset: 
  https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
   
  https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
   
 
 I  think you can mount jffs2 using /dev/mtdX, you do not need the block
 driver.

I realize you acknowledged your misunderstanding here, but for
posterity -- this point is addressed in the FAQ:

http://www.linux-mtd.infradead.org/faq/jffs2.html#L_mtdblock

Last I checked, the statement about busybox is still true. I think the
rootfs comment may be stale; I think the rootfstype= parameter can help
you.

Brian
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

2014-11-05 Thread Brian Norris
On Thu, Oct 09, 2014 at 11:07:31AM -0400, Rodrigo Freire wrote:
> From: Felix Fietkau  
> 
> mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion 
> 
> Currently, a block MTD device is not presented to the system on time, in 
> order to start mounting the filesystems. This patch ensures that block2mtd 
> is presented at the right time, so filesystems can be mounted on boot time. 
> This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
> block2mtd filesystems. 
> This patchset also adds a MTD device name and a timeout option to the driver. 
> Original patchset: 
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
>  
> https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
>  
> 
> Signed-off-by: Felix Fietkau  
> Signed-off-by: Rodrigo Freire  
> Signed-off-by: Herton Krzesinski  
> --- 
> V2: Uses kstrdup, removed PAGE_MASK. 

FYI, this copy was malformed. All the indentation and formatting is
wrong, so it doesn't apply. I'll look at the previous copy you sent, but
please fix this in the future.

Brian

> --- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
> +++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
> @@ -9,7 +9,15 @@ 
> 
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 
> 
> +/* 
> +* When the first attempt at device initialization fails, we may need to 
> +* wait a little bit and retry. This timeout, by default 3 seconds, gives 
> +* device time to start up. Required on BCM2708 and a few other chipsets. 
> +*/ 
> +#define MTD_DEFAULT_TIMEOUT 3 
> + 
> #include  
> +#include  
> #include  
> #include  
> #include  
> @@ -17,6 +25,7 @@ 
> #include  
> #include  
> #include  
> +#include  
> #include  
> #include  
> #include  
> @@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
> } 
> 
> 
> -static struct block2mtd_dev *add_device(char *devname, int erase_size) 
> +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; 
> @@ -225,15 +236,28 @@ 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)) { 
> 
> - /* We might not have rootfs mounted at this point. Try 
> - to resolve the device name by other means. */ 
> - 
> - dev_t devt = name_to_dev_t(devname); 
> - if (devt) 
> - bdev = blkdev_get_by_dev(devt, mode, dev); 
> +#ifndef MODULE 
> +/* 
> +* We might not have the root device mounted at this point. 
> +* Try to resolve the device name by other means. 
> +*/ 
> + for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { 
> + dev_t devt; 
> + 
> + if (i) 
> + /* 
> + * Calling wait_for_device_probe in the first loop 
> + * was not enough, sleep for a bit in subsequent 
> + * go-arounds. 
> + */ 
> + msleep(1000); 
> + wait_for_device_probe(); 
> + 
> + devt = name_to_dev_t(devname); 
> + if (!devt) 
> + continue; 
> + bdev = blkdev_get_by_dev(devt, mode, dev); 
> } 
> #endif 
> 
> @@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 
> 
> /* Setup the MTD structure */ 
> /* make the name contain the block device in */ 
> - name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname); 
> + if (!mtdname) 
> + mtdname = devname; 
> + name = kstrdup (mtdname, GFP_KERNEL); 
> if (!name) 
> goto err_destroy_mutex; 
> 
> dev->mtd.name = name; 
> - 
> - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK; 
> + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1); 
> dev->mtd.erasesize = erase_size; 
> dev->mtd.writesize = 1; 
> dev->mtd.writebufsize = PAGE_SIZE; 
> @@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
> dev->mtd.priv = dev; 
> dev->mtd.owner = THIS_MODULE; 
> 
> - if (mtd_device_register(>mtd, NULL, 0)) { 
> + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
> + part->name = name; 
> + part->offset = 0; 
> + part->size = dev->mtd.size; 
> + if (mtd_device_register(>mtd, part, 1)) { 
> /* Device didn't get added, so free the entry */ 
> goto err_destroy_mutex; 
> } 
> + 
> list_add(>list, _device_list); 
> pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n", 
> dev->mtd.index, 
> - dev->mtd.name + strlen("block2mtd: "), 
> - dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
> + mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
> return dev; 
> 
> err_destroy_mutex: 
> @@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 
> 
> static int block2mtd_setup2(const char *val) 
> { 
> - char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
> + char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for 

Re: [RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

2014-11-05 Thread Brian Norris
On Thu, Oct 09, 2014 at 11:07:31AM -0400, Rodrigo Freire wrote:
 From: Felix Fietkau n...@openwrt.org 
 
 mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion 
 
 Currently, a block MTD device is not presented to the system on time, in 
 order to start mounting the filesystems. This patch ensures that block2mtd 
 is presented at the right time, so filesystems can be mounted on boot time. 
 This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
 block2mtd filesystems. 
 This patchset also adds a MTD device name and a timeout option to the driver. 
 Original patchset: 
 https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
  
 https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
  
 
 Signed-off-by: Felix Fietkau n...@openwrt.org 
 Signed-off-by: Rodrigo Freire rfre...@redhat.com 
 Signed-off-by: Herton Krzesinski her...@redhat.com 
 --- 
 V2: Uses kstrdup, removed PAGE_MASK. 

FYI, this copy was malformed. All the indentation and formatting is
wrong, so it doesn't apply. I'll look at the previous copy you sent, but
please fix this in the future.

Brian

 --- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
 +++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
 @@ -9,7 +9,15 @@ 
 
 #define pr_fmt(fmt) KBUILD_MODNAME :  fmt 
 
 +/* 
 +* When the first attempt at device initialization fails, we may need to 
 +* wait a little bit and retry. This timeout, by default 3 seconds, gives 
 +* device time to start up. Required on BCM2708 and a few other chipsets. 
 +*/ 
 +#define MTD_DEFAULT_TIMEOUT 3 
 + 
 #include linux/module.h 
 +#include linux/delay.h 
 #include linux/fs.h 
 #include linux/blkdev.h 
 #include linux/bio.h 
 @@ -17,6 +25,7 @@ 
 #include linux/list.h 
 #include linux/init.h 
 #include linux/mtd/mtd.h 
 +#include linux/mtd/partitions.h 
 #include linux/mutex.h 
 #include linux/mount.h 
 #include linux/slab.h 
 @@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
 } 
 
 
 -static struct block2mtd_dev *add_device(char *devname, int erase_size) 
 +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; 
 @@ -225,15 +236,28 @@ 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)) { 
 
 - /* We might not have rootfs mounted at this point. Try 
 - to resolve the device name by other means. */ 
 - 
 - dev_t devt = name_to_dev_t(devname); 
 - if (devt) 
 - bdev = blkdev_get_by_dev(devt, mode, dev); 
 +#ifndef MODULE 
 +/* 
 +* We might not have the root device mounted at this point. 
 +* Try to resolve the device name by other means. 
 +*/ 
 + for (i = 0; IS_ERR(bdev)  i = timeout; i++) { 
 + dev_t devt; 
 + 
 + if (i) 
 + /* 
 + * Calling wait_for_device_probe in the first loop 
 + * was not enough, sleep for a bit in subsequent 
 + * go-arounds. 
 + */ 
 + msleep(1000); 
 + wait_for_device_probe(); 
 + 
 + devt = name_to_dev_t(devname); 
 + if (!devt) 
 + continue; 
 + bdev = blkdev_get_by_dev(devt, mode, dev); 
 } 
 #endif 
 
 @@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 
 
 /* Setup the MTD structure */ 
 /* make the name contain the block device in */ 
 - name = kasprintf(GFP_KERNEL, block2mtd: %s, devname); 
 + if (!mtdname) 
 + mtdname = devname; 
 + name = kstrdup (mtdname, GFP_KERNEL); 
 if (!name) 
 goto err_destroy_mutex; 
 
 dev-mtd.name = name; 
 - 
 - dev-mtd.size = dev-blkdev-bd_inode-i_size  PAGE_MASK; 
 + dev-mtd.size = dev-blkdev-bd_inode-i_size  ~(erase_size - 1); 
 dev-mtd.erasesize = erase_size; 
 dev-mtd.writesize = 1; 
 dev-mtd.writebufsize = PAGE_SIZE; 
 @@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
 dev-mtd.priv = dev; 
 dev-mtd.owner = THIS_MODULE; 
 
 - if (mtd_device_register(dev-mtd, NULL, 0)) { 
 + part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
 + part-name = name; 
 + part-offset = 0; 
 + part-size = dev-mtd.size; 
 + if (mtd_device_register(dev-mtd, part, 1)) { 
 /* Device didn't get added, so free the entry */ 
 goto err_destroy_mutex; 
 } 
 + 
 list_add(dev-list, blkmtd_device_list); 
 pr_info(mtd%d: [%s] erase_size = %dKiB [%d]\n, 
 dev-mtd.index, 
 - dev-mtd.name + strlen(block2mtd: ), 
 - dev-mtd.erasesize  10, dev-mtd.erasesize); 
 + mtdname, dev-mtd.erasesize  10, dev-mtd.erasesize); 
 return dev; 
 
 err_destroy_mutex: 
 @@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 
 
 static int block2mtd_setup2(const char *val) 
 { 
 - char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
 + 

[RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

2014-11-01 Thread Rodrigo Freire
From: Felix Fietkau  

mtd: block2mtd: Ensure that block2mtd is presented timely on boot time

Currently, a block MTD device is not presented to the system on time, in 
order to start mounting the filesystems. This patch ensures that block2mtd 
is presented at the right time, so filesystems can be mounted on boot time. 
This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
over block2mtd devices as the root filesystem.
This patchset also adds a MTD device name and a timeout option to the driver. 
Original patchset: 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
 

Signed-off-by: Felix Fietkau  
Signed-off-by: Herton Ronaldo Krzesinski  
Signed-off-by: Rodrigo Freire  
--- 
V2: Uses kstrdup, removed PAGE_MASK. 
--- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
+++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
@@ -9,7 +9,15 @@ 

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 

+/* 
+* When the first attempt at device initialization fails, we may need to 
+* wait a little bit and retry. This timeout, by default 3 seconds, gives 
+* device time to start up. Required on BCM2835.
+*/ 
+#define MTD_DEFAULT_TIMEOUT 3 
+ 
#include  
+#include  
#include  
#include  
#include  
@@ -17,6 +25,7 @@ 
#include  
#include  
#include  
+#include  
#include  
#include  
#include  
@@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
} 


-static struct block2mtd_dev *add_device(char *devname, int erase_size) 
+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; 
@@ -225,15 +236,28 @@ 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)) { 

- /* We might not have rootfs mounted at this point. Try 
- to resolve the device name by other means. */ 
- 
- dev_t devt = name_to_dev_t(devname); 
- if (devt) 
- bdev = blkdev_get_by_dev(devt, mode, dev); 
+#ifndef MODULE 
+/* 
+* We might not have the root device mounted at this point. 
+* Try to resolve the device name by other means. 
+*/ 
+ for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { 
+ dev_t devt; 
+ 
+ if (i) 
+ /* 
+ * Calling wait_for_device_probe in the first loop 
+ * was not enough, sleep for a bit in subsequent 
+ * go-arounds. 
+ */ 
+ msleep(1000); 
+ wait_for_device_probe(); 
+ 
+ devt = name_to_dev_t(devname); 
+ if (!devt) 
+ continue; 
+ bdev = blkdev_get_by_dev(devt, mode, dev); 
} 
#endif 

@@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 

/* Setup the MTD structure */ 
/* make the name contain the block device in */ 
- name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname); 
+ if (!mtdname) 
+ mtdname = devname; 
+ name = kstrdup (mtdname, GFP_KERNEL); 
if (!name) 
goto err_destroy_mutex; 

dev->mtd.name = name; 
- 
- dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK; 
+ dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1); 
dev->mtd.erasesize = erase_size; 
dev->mtd.writesize = 1; 
dev->mtd.writebufsize = PAGE_SIZE; 
@@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
dev->mtd.priv = dev; 
dev->mtd.owner = THIS_MODULE; 

- if (mtd_device_register(>mtd, NULL, 0)) { 
+ part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
+ part->name = name; 
+ part->offset = 0; 
+ part->size = dev->mtd.size; 
+ if (mtd_device_register(>mtd, part, 1)) { 
/* Device didn't get added, so free the entry */ 
goto err_destroy_mutex; 
} 
+ 
list_add(>list, _device_list); 
pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n", 
dev->mtd.index, 
- dev->mtd.name + strlen("block2mtd: "), 
- dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
+ mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
return dev; 

err_destroy_mutex: 
@@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 

static int block2mtd_setup2(const char *val) 
{ 
- char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
+ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 
8 for timeout */ 
char *str = buf; 
- char *token[2]; 
+ char *token[4]; 
char *name; 
size_t erase_size = PAGE_SIZE; 
+ unsigned long timeout = MTD_DEFAULT_TIMEOUT; 
int i, ret; 

if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { 
@@ -368,7 +398,7 @@ static int block2mtd_setup2(const char * 
strcpy(str, val); 
kill_final_newline(str); 

- for (i = 0; i < 2; i++) 
+ for (i = 0; i < 4; i++) 
token[i] = strsep(, ","); 

if (str) { 
@@ -395,7 +425,13 @@ static int block2mtd_setup2(const char * 
} 
} 

- 

[RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

2014-11-01 Thread Rodrigo Freire
From: Felix Fietkau n...@openwrt.org 

mtd: block2mtd: Ensure that block2mtd is presented timely on boot time

Currently, a block MTD device is not presented to the system on time, in 
order to start mounting the filesystems. This patch ensures that block2mtd 
is presented at the right time, so filesystems can be mounted on boot time. 
This issue is seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
over block2mtd devices as the root filesystem.
This patchset also adds a MTD device name and a timeout option to the driver. 
Original patchset: 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
 

Signed-off-by: Felix Fietkau n...@openwrt.org 
Signed-off-by: Herton Ronaldo Krzesinski her...@redhat.com 
Signed-off-by: Rodrigo Freire rfre...@redhat.com 
--- 
V2: Uses kstrdup, removed PAGE_MASK. 
--- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
+++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
@@ -9,7 +9,15 @@ 

#define pr_fmt(fmt) KBUILD_MODNAME :  fmt 

+/* 
+* When the first attempt at device initialization fails, we may need to 
+* wait a little bit and retry. This timeout, by default 3 seconds, gives 
+* device time to start up. Required on BCM2835.
+*/ 
+#define MTD_DEFAULT_TIMEOUT 3 
+ 
#include linux/module.h 
+#include linux/delay.h 
#include linux/fs.h 
#include linux/blkdev.h 
#include linux/bio.h 
@@ -17,6 +25,7 @@ 
#include linux/list.h 
#include linux/init.h 
#include linux/mtd/mtd.h 
+#include linux/mtd/partitions.h 
#include linux/mutex.h 
#include linux/mount.h 
#include linux/slab.h 
@@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
} 


-static struct block2mtd_dev *add_device(char *devname, int erase_size) 
+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; 
@@ -225,15 +236,28 @@ 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)) { 

- /* We might not have rootfs mounted at this point. Try 
- to resolve the device name by other means. */ 
- 
- dev_t devt = name_to_dev_t(devname); 
- if (devt) 
- bdev = blkdev_get_by_dev(devt, mode, dev); 
+#ifndef MODULE 
+/* 
+* We might not have the root device mounted at this point. 
+* Try to resolve the device name by other means. 
+*/ 
+ for (i = 0; IS_ERR(bdev)  i = timeout; i++) { 
+ dev_t devt; 
+ 
+ if (i) 
+ /* 
+ * Calling wait_for_device_probe in the first loop 
+ * was not enough, sleep for a bit in subsequent 
+ * go-arounds. 
+ */ 
+ msleep(1000); 
+ wait_for_device_probe(); 
+ 
+ devt = name_to_dev_t(devname); 
+ if (!devt) 
+ continue; 
+ bdev = blkdev_get_by_dev(devt, mode, dev); 
} 
#endif 

@@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 

/* Setup the MTD structure */ 
/* make the name contain the block device in */ 
- name = kasprintf(GFP_KERNEL, block2mtd: %s, devname); 
+ if (!mtdname) 
+ mtdname = devname; 
+ name = kstrdup (mtdname, GFP_KERNEL); 
if (!name) 
goto err_destroy_mutex; 

dev-mtd.name = name; 
- 
- dev-mtd.size = dev-blkdev-bd_inode-i_size  PAGE_MASK; 
+ dev-mtd.size = dev-blkdev-bd_inode-i_size  ~(erase_size - 1); 
dev-mtd.erasesize = erase_size; 
dev-mtd.writesize = 1; 
dev-mtd.writebufsize = PAGE_SIZE; 
@@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
dev-mtd.priv = dev; 
dev-mtd.owner = THIS_MODULE; 

- if (mtd_device_register(dev-mtd, NULL, 0)) { 
+ part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
+ part-name = name; 
+ part-offset = 0; 
+ part-size = dev-mtd.size; 
+ if (mtd_device_register(dev-mtd, part, 1)) { 
/* Device didn't get added, so free the entry */ 
goto err_destroy_mutex; 
} 
+ 
list_add(dev-list, blkmtd_device_list); 
pr_info(mtd%d: [%s] erase_size = %dKiB [%d]\n, 
dev-mtd.index, 
- dev-mtd.name + strlen(block2mtd: ), 
- dev-mtd.erasesize  10, dev-mtd.erasesize); 
+ mtdname, dev-mtd.erasesize  10, dev-mtd.erasesize); 
return dev; 

err_destroy_mutex: 
@@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 

static int block2mtd_setup2(const char *val) 
{ 
- char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
+ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 
8 for timeout */ 
char *str = buf; 
- char *token[2]; 
+ char *token[4]; 
char *name; 
size_t erase_size = PAGE_SIZE; 
+ unsigned long timeout = MTD_DEFAULT_TIMEOUT; 
int i, ret; 

if (strnlen(val, sizeof(buf)) = sizeof(buf)) { 
@@ -368,7 +398,7 @@ static int block2mtd_setup2(const char * 
strcpy(str, val); 

[RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

2014-10-09 Thread Rodrigo Freire
From: Felix Fietkau  

mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion 

Currently, a block MTD device is not presented to the system on time, in 
order to start mounting the filesystems. This patch ensures that block2mtd 
is presented at the right time, so filesystems can be mounted on boot time. 
This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
block2mtd filesystems. 
This patchset also adds a MTD device name and a timeout option to the driver. 
Original patchset: 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
 

Signed-off-by: Felix Fietkau  
Signed-off-by: Rodrigo Freire  
Signed-off-by: Herton Krzesinski  
--- 
V2: Uses kstrdup, removed PAGE_MASK. 
--- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
+++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
@@ -9,7 +9,15 @@ 

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 

+/* 
+* When the first attempt at device initialization fails, we may need to 
+* wait a little bit and retry. This timeout, by default 3 seconds, gives 
+* device time to start up. Required on BCM2708 and a few other chipsets. 
+*/ 
+#define MTD_DEFAULT_TIMEOUT 3 
+ 
#include  
+#include  
#include  
#include  
#include  
@@ -17,6 +25,7 @@ 
#include  
#include  
#include  
+#include  
#include  
#include  
#include  
@@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
} 


-static struct block2mtd_dev *add_device(char *devname, int erase_size) 
+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; 
@@ -225,15 +236,28 @@ 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)) { 

- /* We might not have rootfs mounted at this point. Try 
- to resolve the device name by other means. */ 
- 
- dev_t devt = name_to_dev_t(devname); 
- if (devt) 
- bdev = blkdev_get_by_dev(devt, mode, dev); 
+#ifndef MODULE 
+/* 
+* We might not have the root device mounted at this point. 
+* Try to resolve the device name by other means. 
+*/ 
+ for (i = 0; IS_ERR(bdev) && i <= timeout; i++) { 
+ dev_t devt; 
+ 
+ if (i) 
+ /* 
+ * Calling wait_for_device_probe in the first loop 
+ * was not enough, sleep for a bit in subsequent 
+ * go-arounds. 
+ */ 
+ msleep(1000); 
+ wait_for_device_probe(); 
+ 
+ devt = name_to_dev_t(devname); 
+ if (!devt) 
+ continue; 
+ bdev = blkdev_get_by_dev(devt, mode, dev); 
} 
#endif 

@@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 

/* Setup the MTD structure */ 
/* make the name contain the block device in */ 
- name = kasprintf(GFP_KERNEL, "block2mtd: %s", devname); 
+ if (!mtdname) 
+ mtdname = devname; 
+ name = kstrdup (mtdname, GFP_KERNEL); 
if (!name) 
goto err_destroy_mutex; 

dev->mtd.name = name; 
- 
- dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK; 
+ dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1); 
dev->mtd.erasesize = erase_size; 
dev->mtd.writesize = 1; 
dev->mtd.writebufsize = PAGE_SIZE; 
@@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
dev->mtd.priv = dev; 
dev->mtd.owner = THIS_MODULE; 

- if (mtd_device_register(>mtd, NULL, 0)) { 
+ part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
+ part->name = name; 
+ part->offset = 0; 
+ part->size = dev->mtd.size; 
+ if (mtd_device_register(>mtd, part, 1)) { 
/* Device didn't get added, so free the entry */ 
goto err_destroy_mutex; 
} 
+ 
list_add(>list, _device_list); 
pr_info("mtd%d: [%s] erase_size = %dKiB [%d]\n", 
dev->mtd.index, 
- dev->mtd.name + strlen("block2mtd: "), 
- dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
+ mtdname, dev->mtd.erasesize >> 10, dev->mtd.erasesize); 
return dev; 

err_destroy_mutex: 
@@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 

static int block2mtd_setup2(const char *val) 
{ 
- char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
+ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 
8 for timeout */ 
char *str = buf; 
- char *token[2]; 
+ char *token[4]; 
char *name; 
size_t erase_size = PAGE_SIZE; 
+ unsigned long timeout = MTD_DEFAULT_TIMEOUT; 
int i, ret; 

if (strnlen(val, sizeof(buf)) >= sizeof(buf)) { 
@@ -368,7 +398,7 @@ static int block2mtd_setup2(const char * 
strcpy(str, val); 
kill_final_newline(str); 

- for (i = 0; i < 2; i++) 
+ for (i = 0; i < 4; i++) 
token[i] = strsep(, ","); 

if (str) { 
@@ -395,7 +425,13 @@ static int block2mtd_setup2(const char * 
} 
} 

- 

[RESEND PATCH V2] mtd: block2mtd: Present block2mtd timely on boot time

2014-10-09 Thread Rodrigo Freire
From: Felix Fietkau n...@openwrt.org 

mtd: block2mtd: Ensure that block2mtd is presented in a timely fashion 

Currently, a block MTD device is not presented to the system on time, in 
order to start mounting the filesystems. This patch ensures that block2mtd 
is presented at the right time, so filesystems can be mounted on boot time. 
This issue was seen on BCM2835 (Raspberry Pi) systems when mounting JFFS2 
block2mtd filesystems. 
This patchset also adds a MTD device name and a timeout option to the driver. 
Original patchset: 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/440-block2mtd_init.patch?rev=40444
 
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-3.12/441-block2mtd_probe.patch?rev=40444
 

Signed-off-by: Felix Fietkau n...@openwrt.org 
Signed-off-by: Rodrigo Freire rfre...@redhat.com 
Signed-off-by: Herton Krzesinski her...@redhat.com 
--- 
V2: Uses kstrdup, removed PAGE_MASK. 
--- a/drivers/mtd/devices/block2mtd.c 2014-09-16 21:38:12.543952627 -0300 
+++ b/drivers/mtd/devices/block2mtd.c 2014-09-17 17:43:21.424944394 -0300 
@@ -9,7 +9,15 @@ 

#define pr_fmt(fmt) KBUILD_MODNAME :  fmt 

+/* 
+* When the first attempt at device initialization fails, we may need to 
+* wait a little bit and retry. This timeout, by default 3 seconds, gives 
+* device time to start up. Required on BCM2708 and a few other chipsets. 
+*/ 
+#define MTD_DEFAULT_TIMEOUT 3 
+ 
#include linux/module.h 
+#include linux/delay.h 
#include linux/fs.h 
#include linux/blkdev.h 
#include linux/bio.h 
@@ -17,6 +25,7 @@ 
#include linux/list.h 
#include linux/init.h 
#include linux/mtd/mtd.h 
+#include linux/mtd/partitions.h 
#include linux/mutex.h 
#include linux/mount.h 
#include linux/slab.h 
@@ -209,12 +218,14 @@ static void block2mtd_free_device(struct 
} 


-static struct block2mtd_dev *add_device(char *devname, int erase_size) 
+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; 
@@ -225,15 +236,28 @@ 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)) { 

- /* We might not have rootfs mounted at this point. Try 
- to resolve the device name by other means. */ 
- 
- dev_t devt = name_to_dev_t(devname); 
- if (devt) 
- bdev = blkdev_get_by_dev(devt, mode, dev); 
+#ifndef MODULE 
+/* 
+* We might not have the root device mounted at this point. 
+* Try to resolve the device name by other means. 
+*/ 
+ for (i = 0; IS_ERR(bdev)  i = timeout; i++) { 
+ dev_t devt; 
+ 
+ if (i) 
+ /* 
+ * Calling wait_for_device_probe in the first loop 
+ * was not enough, sleep for a bit in subsequent 
+ * go-arounds. 
+ */ 
+ msleep(1000); 
+ wait_for_device_probe(); 
+ 
+ devt = name_to_dev_t(devname); 
+ if (!devt) 
+ continue; 
+ bdev = blkdev_get_by_dev(devt, mode, dev); 
} 
#endif 

@@ -257,13 +281,14 @@ static struct block2mtd_dev *add_device( 

/* Setup the MTD structure */ 
/* make the name contain the block device in */ 
- name = kasprintf(GFP_KERNEL, block2mtd: %s, devname); 
+ if (!mtdname) 
+ mtdname = devname; 
+ name = kstrdup (mtdname, GFP_KERNEL); 
if (!name) 
goto err_destroy_mutex; 

dev-mtd.name = name; 
- 
- dev-mtd.size = dev-blkdev-bd_inode-i_size  PAGE_MASK; 
+ dev-mtd.size = dev-blkdev-bd_inode-i_size  ~(erase_size - 1); 
dev-mtd.erasesize = erase_size; 
dev-mtd.writesize = 1; 
dev-mtd.writebufsize = PAGE_SIZE; 
@@ -276,15 +301,19 @@ static struct block2mtd_dev *add_device( 
dev-mtd.priv = dev; 
dev-mtd.owner = THIS_MODULE; 

- if (mtd_device_register(dev-mtd, NULL, 0)) { 
+ part = kzalloc(sizeof(struct mtd_partition), GFP_KERNEL); 
+ part-name = name; 
+ part-offset = 0; 
+ part-size = dev-mtd.size; 
+ if (mtd_device_register(dev-mtd, part, 1)) { 
/* Device didn't get added, so free the entry */ 
goto err_destroy_mutex; 
} 
+ 
list_add(dev-list, blkmtd_device_list); 
pr_info(mtd%d: [%s] erase_size = %dKiB [%d]\n, 
dev-mtd.index, 
- dev-mtd.name + strlen(block2mtd: ), 
- dev-mtd.erasesize  10, dev-mtd.erasesize); 
+ mtdname, dev-mtd.erasesize  10, dev-mtd.erasesize); 
return dev; 

err_destroy_mutex: 
@@ -353,11 +382,12 @@ static char block2mtd_paramline[80 + 12] 

static int block2mtd_setup2(const char *val) 
{ 
- char buf[80 + 12]; /* 80 for device, 12 for erase size */ 
+ char buf[80 + 12 + 80 + 8]; /* 80 for device, 12 for erase size, 80 for name, 
8 for timeout */ 
char *str = buf; 
- char *token[2]; 
+ char *token[4]; 
char *name; 
size_t erase_size = PAGE_SIZE; 
+ unsigned long timeout = MTD_DEFAULT_TIMEOUT; 
int i, ret; 

if (strnlen(val, sizeof(buf)) = sizeof(buf)) { 
@@ -368,7 +398,7 @@ static int block2mtd_setup2(const char * 
strcpy(str, val);