Patchwork UBI: Do not try to autoresize in readonly mode

login
register
mail settings
Submitter Artem Bityutskiy
Date Aug. 24, 2012, 3:29 p.m.
Message ID <1345822171.2848.325.camel@sauron.fi.intel.com>
Download mbox | patch
Permalink /patch/179862/
State Accepted
Commit abb3e01103eb4e2ea5c15e6fedbc74e08bd4cc2b
Headers show

Comments

Artem Bityutskiy - Aug. 24, 2012, 3:29 p.m.
On Sat, 2012-08-18 at 14:11 +0200, Pali Rohár wrote:
> I'm sending small patch which skip autoresizing ubi in readonly 
> mode. I think it is really not good idea to try resize in ro 
> mode.

Hi, I've just pushed a similar patch to linux-ubi.git, is this fine with
you? I've also CCed -stable.

From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Date: Sat, 18 Aug 2012 14:11:42 +0200
Subject: [PATCH] UBI: fix autoresize handling in R/O mode

Currently UBI fails in autoresize when it is in R/O mode (e.g., because the
underlying MTD device is R/O). This patch fixes the issue - we just skip
autoresize and print a warning.

Reported-by: Pali Rohár <pali.rohar@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
---
 drivers/mtd/ubi/build.c |    5 +++++
 1 file changed, 5 insertions(+)
Pali Rohár - Aug. 24, 2012, 3:48 p.m.
On Friday 24 August 2012 18:29:31 Artem Bityutskiy wrote:
> On Sat, 2012-08-18 at 14:11 +0200, Pali Rohár wrote:
> > I'm sending small patch which skip autoresizing ubi in
> > readonly mode. I think it is really not good idea to try
> > resize in ro mode.
> 
> Hi, I've just pushed a similar patch to linux-ubi.git, is this
> fine with you? I've also CCed -stable.
> 

Hi, patch is OK. I tested it and working for me fine.

> > BTW, is there userspace tool for unpacking data from ubifs
> > image without need to simulate nand device in kernel?
> 
> Unfortunately no.

Ok. I have patch for block2mtd.ko which allows me to mount ubifs 
image in way: losetup --> block2mtd --> ubiattach --> mount 
without nandsim. I needed to patch block2mtd, because ubi code 
needs correct erase size, write size nand subpage shift and full 
image size. So I added params for these properties in block2mtd 
code - and it working. But I do not know if this is correct way, 
but I can send my patch.
Artem Bityutskiy - Aug. 24, 2012, 3:57 p.m.
On Fri, 2012-08-24 at 17:48 +0200, Pali Rohár wrote:
> > > BTW, is there userspace tool for unpacking data from ubifs
> > > image without need to simulate nand device in kernel?
> > 
> > Unfortunately no.
> 
> Ok. I have patch for block2mtd.ko which allows me to mount ubifs 
> image in way: losetup --> block2mtd --> ubiattach --> mount 
> without nandsim. I needed to patch block2mtd, because ubi code 
> needs correct erase size, write size nand subpage shift and full 
> image size. So I added params for these properties in block2mtd 
> code - and it working. But I do not know if this is correct way, 
> but I can send my patch.

Why do you need to use block2mtd? If you have an image for NOR flash,
use mtdram, if it is for NAND - use nandsim. What prevents you from
using mtdram or nandsim?
Pali Rohár - Aug. 24, 2012, 3:59 p.m.
On Friday 24 August 2012 18:57:01 Artem Bityutskiy wrote:
> On Fri, 2012-08-24 at 17:48 +0200, Pali Rohár wrote:
> > > > BTW, is there userspace tool for unpacking data from
> > > > ubifs
> > > > image without need to simulate nand device in kernel?
> > > 
> > > Unfortunately no.
> > 
> > Ok. I have patch for block2mtd.ko which allows me to mount
> > ubifs image in way: losetup --> block2mtd --> ubiattach -->
> > mount without nandsim. I needed to patch block2mtd, because
> > ubi code needs correct erase size, write size nand subpage
> > shift and full image size. So I added params for these
> > properties in block2mtd code - and it working. But I do not
> > know if this is correct way, but I can send my patch.
> 
> Why do you need to use block2mtd? If you have an image for NOR
> flash, use mtdram, if it is for NAND - use nandsim. What
> prevents you from using mtdram or nandsim?

I do not know why, but copying 256 MB image to nandsim takes more 
time than losetup & block2mtd & mount...
Artem Bityutskiy - Aug. 24, 2012, 4:09 p.m.
On Fri, 2012-08-24 at 17:59 +0200, Pali Rohár wrote:
> > Why do you need to use block2mtd? If you have an image for NOR
> > flash, use mtdram, if it is for NAND - use nandsim. What
> > prevents you from using mtdram or nandsim?
> 
> I do not know why, but copying 256 MB image to nandsim takes more 
> time than losetup & block2mtd & mount...

May be, how much more? Is that a show-stopper for you? If you copy with
'dd', try 'bs=2048' if you are simulating a device with a 2048 bytes
NAND page size.

But I guess you can patch block2mtd, I do not have objections (although
it'll report about itself as NOR flash?), but I never used it and I am
not sure how many bugs there are.

Patch

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 355756b..8966088 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -799,6 +799,11 @@  static int autoresize(struct ubi_device *ubi, int vol_id)
 	struct ubi_volume *vol = ubi->volumes[vol_id];
 	int err, old_reserved_pebs = vol->reserved_pebs;
 
+	if (ubi->ro_mode) {
+		ubi_warn("skip auto-resize because of R/O mode");
+		return 0;
+	}
+
 	/*
 	 * Clear the auto-resize flag in the volume in-memory copy of the
 	 * volume table, and 'ubi_resize_volume()' will propagate this change