mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/5] minor SPI flash fixes
@ 2012-06-06 16:04 Johannes Stezenbach
  2012-06-06 16:04 ` [PATCH 1/5] m25p80: prevent endless loop in erase Johannes Stezenbach
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Johannes Stezenbach @ 2012-06-06 16:04 UTC (permalink / raw)
  To: barebox

Hi,

I'm playing around with barebox on an ARM926EJ-S based board
with SPI flash.  I found a few minor but annoying issues
with erase handling (I inadvertantly erased my boot loader).

Johannes


 drivers/nor/m25p80.c |    8 ++++++--
 fs/devfs.c           |    3 +++
 fs/fs.c              |   18 ++++++++----------
 3 files changed, 17 insertions(+), 12 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] m25p80: prevent endless loop in erase
  2012-06-06 16:04 [PATCH 0/5] minor SPI flash fixes Johannes Stezenbach
@ 2012-06-06 16:04 ` Johannes Stezenbach
  2012-06-06 16:04 ` [PATCH 2/5] m25p80: allow erase to be interrupted Johannes Stezenbach
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Johannes Stezenbach @ 2012-06-06 16:04 UTC (permalink / raw)
  To: barebox

"erase /dev/myflash0 0+1" erased the whole flash,
similar for other value of count if you guessed the
erae block size wrong.

Signed-off-by: Johannes Stezenbach <js@sig21.net>
---
 drivers/nor/m25p80.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c
index 92b07af..a3dfe75 100644
--- a/drivers/nor/m25p80.c
+++ b/drivers/nor/m25p80.c
@@ -235,6 +235,8 @@ static ssize_t m25p80_erase(struct cdev *cdev, size_t count, unsigned long offse
 			if (erase_sector(flash, addr))
 				return -EIO;
 
+			if (len <= flash->erasesize)
+				break;
 			addr += flash->erasesize;
 			len -= flash->erasesize;
 			show_progress(progress++);
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/5] m25p80: allow erase to be interrupted
  2012-06-06 16:04 [PATCH 0/5] minor SPI flash fixes Johannes Stezenbach
  2012-06-06 16:04 ` [PATCH 1/5] m25p80: prevent endless loop in erase Johannes Stezenbach
@ 2012-06-06 16:04 ` Johannes Stezenbach
  2012-06-06 16:04 ` [PATCH 3/5] m25p80: progressbar tweak Johannes Stezenbach
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Johannes Stezenbach @ 2012-06-06 16:04 UTC (permalink / raw)
  To: barebox

Check for Ctrl-C before erasing each sector.

Signed-off-by: Johannes Stezenbach <js@sig21.net>
---
 drivers/nor/m25p80.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c
index a3dfe75..86e6d25 100644
--- a/drivers/nor/m25p80.c
+++ b/drivers/nor/m25p80.c
@@ -232,6 +232,8 @@ static ssize_t m25p80_erase(struct cdev *cdev, size_t count, unsigned long offse
 	/* "sector"-at-a-time erase */
 	} else {
 		while (len) {
+			if (ctrlc())
+				return -EINTR;
 			if (erase_sector(flash, addr))
 				return -EIO;
 
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/5] m25p80: progressbar tweak
  2012-06-06 16:04 [PATCH 0/5] minor SPI flash fixes Johannes Stezenbach
  2012-06-06 16:04 ` [PATCH 1/5] m25p80: prevent endless loop in erase Johannes Stezenbach
  2012-06-06 16:04 ` [PATCH 2/5] m25p80: allow erase to be interrupted Johannes Stezenbach
@ 2012-06-06 16:04 ` Johannes Stezenbach
  2012-06-06 16:04 ` [PATCH 4/5] devfs: don't erase past the end of the partition Johannes Stezenbach
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Johannes Stezenbach @ 2012-06-06 16:04 UTC (permalink / raw)
  To: barebox

Show progressbar even when erasing just a single sector,
otherwise it looks as if erase didn't do anything.

Signed-off-by: Johannes Stezenbach <js@sig21.net>
---
 drivers/nor/m25p80.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nor/m25p80.c b/drivers/nor/m25p80.c
index 86e6d25..77669c2 100644
--- a/drivers/nor/m25p80.c
+++ b/drivers/nor/m25p80.c
@@ -214,7 +214,7 @@ static ssize_t m25p80_erase(struct cdev *cdev, size_t count, unsigned long offse
 
 	start_sector = offset / flash->erasesize;
 	end_sector = (offset + count - 1) / flash->erasesize;
-	init_progression_bar(end_sector - start_sector);
+	init_progression_bar(end_sector - start_sector + 1);
 
 	/* whole-chip erase? */
 	if (len == flash->size) {
@@ -237,11 +237,11 @@ static ssize_t m25p80_erase(struct cdev *cdev, size_t count, unsigned long offse
 			if (erase_sector(flash, addr))
 				return -EIO;
 
+			show_progress(++progress);
 			if (len <= flash->erasesize)
 				break;
 			addr += flash->erasesize;
 			len -= flash->erasesize;
-			show_progress(progress++);
 		}
 	}
 
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/5] devfs: don't erase past the end of the partition
  2012-06-06 16:04 [PATCH 0/5] minor SPI flash fixes Johannes Stezenbach
                   ` (2 preceding siblings ...)
  2012-06-06 16:04 ` [PATCH 3/5] m25p80: progressbar tweak Johannes Stezenbach
@ 2012-06-06 16:04 ` Johannes Stezenbach
  2012-06-06 16:05 ` [PATCH 5/5] fs: limit flash erase and protect to the partiton boundary Johannes Stezenbach
  2012-06-07 17:32 ` [PATCH 0/5] minor SPI flash fixes Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Johannes Stezenbach @ 2012-06-06 16:04 UTC (permalink / raw)
  To: barebox

"erase /dev/myflash0.mypart 0xf0000+0xf0000" could erase past
the end of the partition.

Signed-off-by: Johannes Stezenbach <js@sig21.net>
---
 fs/devfs.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/devfs.c b/fs/devfs.c
index e3a21ae..ae48451 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -73,6 +73,9 @@ static int devfs_erase(struct device_d *_dev, FILE *f, size_t count, unsigned lo
 	if (!cdev->ops->erase)
 		return -ENOSYS;
 
+	if (count + offset > cdev->size)
+		count = cdev->size - offset;
+
 	return cdev->ops->erase(cdev, count, offset + cdev->offset);
 }
 
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/5] fs: limit flash erase and protect to the partiton boundary
  2012-06-06 16:04 [PATCH 0/5] minor SPI flash fixes Johannes Stezenbach
                   ` (3 preceding siblings ...)
  2012-06-06 16:04 ` [PATCH 4/5] devfs: don't erase past the end of the partition Johannes Stezenbach
@ 2012-06-06 16:05 ` Johannes Stezenbach
  2012-06-07 17:32 ` [PATCH 0/5] minor SPI flash fixes Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Johannes Stezenbach @ 2012-06-06 16:05 UTC (permalink / raw)
  To: barebox

Passing a too large size or offset to erase could
affect flash outside the partition boundary.
Addresses for SPI flash wrap around, thus giving a
count + offset going past the end of the flash would
wrap around and erase flash at offset 0.

Add the same check for protect.

Signed-off-by: Johannes Stezenbach <js@sig21.net>
---
 fs/fs.c |   18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 9cda1d9..af73c8c 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -751,14 +751,13 @@ int erase(int fd, size_t count, unsigned long offset)
 
 	if (check_fd(fd))
 		return -errno;
+	if (offset >= f->size)
+		return 0;
+	if (count > f->size - offset)
+		count = f->size - offset;
 
 	dev = f->dev;
-
 	fsdrv = dev_to_fs_driver(dev);
-
-	if (f->pos + count > f->size)
-		count = f->size - f->pos;
-
 	if (fsdrv->erase)
 		ret = fsdrv->erase(dev, f, count, offset);
 	else
@@ -780,14 +779,13 @@ int protect(int fd, size_t count, unsigned long offset, int prot)
 
 	if (check_fd(fd))
 		return -errno;
+	if (offset >= f->size)
+		return 0;
+	if (count > f->size - offset)
+		count = f->size - offset;
 
 	dev = f->dev;
-
 	fsdrv = dev_to_fs_driver(dev);
-
-	if (f->pos + count > f->size)
-		count = f->size - f->pos;
-
 	if (fsdrv->protect)
 		ret = fsdrv->protect(dev, f, count, offset, prot);
 	else
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] minor SPI flash fixes
  2012-06-06 16:04 [PATCH 0/5] minor SPI flash fixes Johannes Stezenbach
                   ` (4 preceding siblings ...)
  2012-06-06 16:05 ` [PATCH 5/5] fs: limit flash erase and protect to the partiton boundary Johannes Stezenbach
@ 2012-06-07 17:32 ` Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2012-06-07 17:32 UTC (permalink / raw)
  To: Johannes Stezenbach; +Cc: barebox

Hi Johannes,

On Wed, Jun 06, 2012 at 06:04:55PM +0200, Johannes Stezenbach wrote:
> Hi,
> 
> I'm playing around with barebox on an ARM926EJ-S based board
> with SPI flash.  I found a few minor but annoying issues
> with erase handling (I inadvertantly erased my boot loader).

Nice fixes. Applied to master.

Thanks

 Sascha

> 
> Johannes
> 
> 
>  drivers/nor/m25p80.c |    8 ++++++--
>  fs/devfs.c           |    3 +++
>  fs/fs.c              |   18 ++++++++----------
>  3 files changed, 17 insertions(+), 12 deletions(-)
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-06-07 17:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-06 16:04 [PATCH 0/5] minor SPI flash fixes Johannes Stezenbach
2012-06-06 16:04 ` [PATCH 1/5] m25p80: prevent endless loop in erase Johannes Stezenbach
2012-06-06 16:04 ` [PATCH 2/5] m25p80: allow erase to be interrupted Johannes Stezenbach
2012-06-06 16:04 ` [PATCH 3/5] m25p80: progressbar tweak Johannes Stezenbach
2012-06-06 16:04 ` [PATCH 4/5] devfs: don't erase past the end of the partition Johannes Stezenbach
2012-06-06 16:05 ` [PATCH 5/5] fs: limit flash erase and protect to the partiton boundary Johannes Stezenbach
2012-06-07 17:32 ` [PATCH 0/5] minor SPI flash fixes Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox