You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "Donny9 (via GitHub)" <gi...@apache.org> on 2023/07/28 04:18:42 UTC

[GitHub] [nuttx] Donny9 opened a new pull request, #9931: driver/mtd/ftl: support to skip bad block for earse/bread/bwrite

Donny9 opened a new pull request, #9931:
URL: https://github.com/apache/nuttx/pull/9931

   
   
   ## Summary
   driver/mtd/ftl: support to skip bad block for earse/bread/bwrite
   ## Impact
   1.support to use dd commond to burn romfs image to nand flash 
   2.support bare-write nand flash device without file system
   ## Testing
   daily test
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] Donny9 commented on a diff in pull request #9931: driver/mtd/ftl: support to skip bad block for earse/bread/bwrite

Posted by "Donny9 (via GitHub)" <gi...@apache.org>.
Donny9 commented on code in PR #9931:
URL: https://github.com/apache/nuttx/pull/9931#discussion_r1278224961


##########
drivers/mtd/ftl.c:
##########
@@ -172,6 +228,163 @@ static int ftl_close(FAR struct inode *inode)
   return OK;
 }
 
+/****************************************************************************
+ * Name: ftl_mtd_bread
+ *
+ * Description:
+ *   Read the specified number of sectors. If mtd device is nor flash, it
+ *   can be read once time. If mtd device is nand flash, it can be read one
+ *   block every time and need to skip bad block until the specified number
+ *   of sectors finish.
+ *
+ ****************************************************************************/
+
+static ssize_t ftl_mtd_bread(FAR struct ftl_struct_s *dev, off_t startblock,
+                             size_t nblocks, FAR uint8_t *buffer)
+{
+  off_t mask = dev->blkper - 1;
+  size_t nread = nblocks;
+  ssize_t ret = OK;
+
+  if (dev->lptable == NULL)
+    {
+      ret = MTD_BREAD(dev->mtd, startblock, nblocks, buffer);
+      if (ret != nblocks)
+        {
+          ferr("ERROR: Read %zu blocks starting at block %" PRIdOFF
+               " failed: %zd\n", nblocks, startblock, ret);
+        }
+
+      return ret;
+    }
+
+  while (nblocks > 0)
+    {
+      off_t startphysicalblock;
+      off_t starteraseblock;
+      size_t count;
+
+      starteraseblock = startblock / dev->blkper;
+      if (starteraseblock >= dev->lpcount)
+        {
+          ret = -ENOSPC;
+          break;
+        }
+
+      count = ftl_get_cblock(dev, starteraseblock, (nblocks + mask) & ~mask);

Review Comment:
   yes,The parameter count of ftl get_clock indicates the number of eraseblocks, but we have already done the conversion by `(nblocks + mask) & ~mask)`



##########
drivers/mtd/ftl.c:
##########
@@ -172,6 +228,163 @@ static int ftl_close(FAR struct inode *inode)
   return OK;
 }
 
+/****************************************************************************
+ * Name: ftl_mtd_bread
+ *
+ * Description:
+ *   Read the specified number of sectors. If mtd device is nor flash, it
+ *   can be read once time. If mtd device is nand flash, it can be read one
+ *   block every time and need to skip bad block until the specified number
+ *   of sectors finish.
+ *
+ ****************************************************************************/
+
+static ssize_t ftl_mtd_bread(FAR struct ftl_struct_s *dev, off_t startblock,
+                             size_t nblocks, FAR uint8_t *buffer)
+{
+  off_t mask = dev->blkper - 1;
+  size_t nread = nblocks;
+  ssize_t ret = OK;
+
+  if (dev->lptable == NULL)
+    {
+      ret = MTD_BREAD(dev->mtd, startblock, nblocks, buffer);
+      if (ret != nblocks)
+        {
+          ferr("ERROR: Read %zu blocks starting at block %" PRIdOFF
+               " failed: %zd\n", nblocks, startblock, ret);
+        }
+
+      return ret;
+    }
+
+  while (nblocks > 0)
+    {
+      off_t startphysicalblock;
+      off_t starteraseblock;
+      size_t count;
+
+      starteraseblock = startblock / dev->blkper;
+      if (starteraseblock >= dev->lpcount)
+        {
+          ret = -ENOSPC;
+          break;
+        }
+
+      count = ftl_get_cblock(dev, starteraseblock, (nblocks + mask) & ~mask);

Review Comment:
   yes,The parameter count of ftl get_clock indicates the number of eraseblocks, but we have already done the conversion by `(nblocks + mask) & ~mask)`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #9931: driver/mtd/ftl: support to skip bad block for earse/bread/bwrite

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #9931:
URL: https://github.com/apache/nuttx/pull/9931#discussion_r1277727357


##########
drivers/mtd/ftl.c:
##########
@@ -172,6 +228,163 @@ static int ftl_close(FAR struct inode *inode)
   return OK;
 }
 
+/****************************************************************************
+ * Name: ftl_mtd_bread
+ *
+ * Description:
+ *   Read the specified number of sectors. If mtd device is nor flash, it
+ *   can be read once time. If mtd device is nand flash, it can be read one
+ *   block every time and need to skip bad block until the specified number
+ *   of sectors finish.
+ *
+ ****************************************************************************/
+
+static ssize_t ftl_mtd_bread(FAR struct ftl_struct_s *dev, off_t startblock,
+                             size_t nblocks, FAR uint8_t *buffer)
+{
+  off_t mask = dev->blkper - 1;
+  size_t nread = nblocks;
+  ssize_t ret = OK;
+
+  if (dev->lptable == NULL)
+    {
+      ret = MTD_BREAD(dev->mtd, startblock, nblocks, buffer);
+      if (ret != nblocks)
+        {
+          ferr("ERROR: Read %zu blocks starting at block %" PRIdOFF
+               " failed: %zd\n", nblocks, startblock, ret);
+        }
+
+      return ret;
+    }
+
+  while (nblocks > 0)
+    {
+      off_t startphysicalblock;
+      off_t starteraseblock;
+      size_t count;
+
+      starteraseblock = startblock / dev->blkper;
+      if (starteraseblock >= dev->lpcount)
+        {
+          ret = -ENOSPC;
+          break;
+        }
+
+      count = ftl_get_cblock(dev, starteraseblock, (nblocks + mask) & ~mask);

Review Comment:
   @Donny9 should we divide nblocks by dev->blkper before pass to ftl_get_cblock?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] acassis commented on a diff in pull request #9931: driver/mtd/ftl: support to skip bad block for earse/bread/bwrite

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on code in PR #9931:
URL: https://github.com/apache/nuttx/pull/9931#discussion_r1278062353


##########
drivers/mtd/ftl.c:
##########
@@ -120,6 +126,56 @@ static const struct block_operations g_bops =
  * Private Functions
  ****************************************************************************/
 
+static int ftl_init_map(FAR struct ftl_struct_s *dev)

Review Comment:
   Please include the Description comment above this ftl_init_map() function



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] Donny9 commented on a diff in pull request #9931: driver/mtd/ftl: support to skip bad block for earse/bread/bwrite

Posted by "Donny9 (via GitHub)" <gi...@apache.org>.
Donny9 commented on code in PR #9931:
URL: https://github.com/apache/nuttx/pull/9931#discussion_r1278224524


##########
drivers/mtd/ftl.c:
##########
@@ -120,6 +126,56 @@ static const struct block_operations g_bops =
  * Private Functions
  ****************************************************************************/
 
+static int ftl_init_map(FAR struct ftl_struct_s *dev)

Review Comment:
   Done~



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] acassis merged pull request #9931: driver/mtd/ftl: support to skip bad block for earse/bread/bwrite

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis merged PR #9931:
URL: https://github.com/apache/nuttx/pull/9931


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org