Skip to contentSkip to conversation

eeprom/at25: add erase support

PATCH In review Hubert Feurstein 2 participants 5 messages Nov 21, 2011 – Nov 24, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eeprom/at25: add erase support

---
 drivers/eeprom/at25.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
drivers/eeprom/at25.c +15 -0
index 8a979d5..39c5846 100644
@@ -237,10 +237,25 @@ static off_t at25_ee_lseek(struct cdev *cdev, off_t off)
 	return off;
 }
 
+static int at25_ee_erase(struct cdev *cdev, size_t count, unsigned long offset)
+{
+	int result;
+	void *buf = xzalloc(count);
+
+	result = at25_ee_write(cdev, buf, count, offset, 0);
+	free(buf);
+
+	if (result < 0)
+		return result;
+
+	return 0;
+}
+
 static struct file_operations at25_fops = {
 	.read	= at25_ee_read,
 	.write	= at25_ee_write,
 	.lseek	= at25_ee_lseek,
+	.erase	= at25_ee_erase,
 };
 
 static int at25_probe(struct device_d *dev)
Signature · 7 lines
1.7.4.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw
Quoted 4 lines · Hubert Feurstein
---
 drivers/eeprom/at25.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

Do we need this? We normally only have erase functions for devices that need it, namely flashes.

Sascha

Quoted 40 lines
drivers/eeprom/at25.c +15 -0
index 8a979d5..39c5846 100644
@@ -237,10 +237,25 @@ static off_t at25_ee_lseek(struct cdev *cdev, off_t off)
 	return off;
 }
 
+static int at25_ee_erase(struct cdev *cdev, size_t count, unsigned long offset)
+{
+	int result;
+	void *buf = xzalloc(count);
+
+	result = at25_ee_write(cdev, buf, count, offset, 0);
+	free(buf);
+
+	if (result < 0)
+		return result;
+
+	return 0;
+}
+
 static struct file_operations at25_fops = {
 	.read	= at25_ee_read,
 	.write	= at25_ee_write,
 	.lseek	= at25_ee_lseek,
+	.erase	= at25_ee_erase,
 };
 
 static int at25_probe(struct device_d *dev)
Signature · 7 lines
1.7.4.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

2011/11/22 Sascha Hauer <[email protected]>:

Quoted 9 lines · Hubert Feurstein
Quoted 4 lines

---
 drivers/eeprom/at25.c |   15 +++++++++++++++

 1 files changed, 15 insertions(+), 0 deletions(-)

Do we need this? We normally only have erase functions for devices that need it, namely flashes.

In my case I use the eeprom (or fram) to store the environment. So with this I can erase the env-partition simply by calling 'erase /dev/env0'.
So it's more like a convenience function. Or is there a other possibility to easily erase a partition completely? The memset-command is not really suitable because I have to pass the size as an argument.

Best Regards
Hubert

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw
Quoted 10 lines · Hubert Feurstein

2011/11/22 Sascha Hauer <[email protected]>:

Quoted 9 lines · Hubert Feurstein
Quoted 4 lines

---
 drivers/eeprom/at25.c |   15 +++++++++++++++

 1 files changed, 15 insertions(+), 0 deletions(-)

Do we need this? We normally only have erase functions for devices that need it, namely flashes.

Quoted 6 lines

In my case I use the eeprom (or fram) to store the environment. So with this I can erase the env-partition simply by calling 'erase /dev/env0'.
So it's more like a convenience function. Or is there a other possibility to easily erase a partition completely? The memset-command is not really suitable because I have to pass the size as an argument.

How about cp /dev/zero /dev/env0?

Sascha

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

2011/11/22 Sascha Hauer <[email protected]>:

Quoted 2 lines

How about cp /dev/zero /dev/env0?

Well, this works, aside from the error message "write: No space left on device". Personally I still prefer the 'erase' support also for eeprom-like devices. Then the handling of partitions would become uniform. But there is still the protect/unprotect thing ...

Best Regards
Hubert

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox