Hello,

I'm using an i2c eeprom with sector (page) size of 16 bytes and through the bch driver I perform some read/write sequences from user space. However, when writing block of data with a size not multiple of the sector size I got a partial eeprom write; in this situation, the bch driver flags the partial sector (remaining bytes) as "dirty". In order to write these remaining bytes to the eeprom, I need to flush the buffer.

In commit 9fc55224385d4abe2dc7a3336f6d9d3f147a0f2d this flush operation has been removed to reduce multiple writes but nothing has been introduced to manually write "dirty" sector from userspace.

Currently, the only option is to call a close() followed by a open() to trigger the bchlib_flushsector().

A possible solution consists in implementing an ioctl in bch driver (like the existing BIOC_FLUSH) to trigger bchlib_flushsector().
Attached to this mail a possible patch.

Let me know if I miss something.

Thanks

Regards,
Federico Braghiroli

>From 25d783b3051f16a27053dd2f1a499cdbf95d0eae Mon Sep 17 00:00:00 2001
From: Federico Braghiroli <braghir...@amelchem.com>
Date: Tue, 27 Jul 2021 12:47:04 +0200
Subject: [PATCH] drivers/bch: handle manual sector flush through BIOC_FLUSH
 ioctl

Signed-off-by: Federico Braghiroli <braghir...@amelchem.com>
---
 drivers/bch/bchdev_driver.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/bch/bchdev_driver.c b/drivers/bch/bchdev_driver.c
index 50e9102bac..01b74bcab8 100644
--- a/drivers/bch/bchdev_driver.c
+++ b/drivers/bch/bchdev_driver.c
@@ -433,6 +433,16 @@ static int bch_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
         break;
 #endif
 
+      case BIOC_FLUSH:
+        {
+          ret = bchlib_flushsector(bch);
+          if (ret < 0)
+            {
+              ferr("ERROR: flush failed: %d\n", -ret);
+            }
+        }
+        break;
+
       /* Otherwise, pass the IOCTL command on to the contained block
        * driver.
        */
-- 
2.17.1

Reply via email to