drivers/mtd: add MTDIOC_ISBAD ioctl

add an ioctl item MTDIOC_ISBAD
used for flashtool command to check bad blocks

Signed-off-by: zhengyu9 <zhengyu9@xiaomi.com>
This commit is contained in:
zhengyu9
2024-08-23 16:40:33 +08:00
committed by Alan C. Assis
parent 37381a9e7d
commit 491ce83508
3 changed files with 21 additions and 0 deletions
@@ -36,6 +36,7 @@ See include/nuttx/mtd/mtd.h for additional information.
- ``MTDIOC_GEOMETRY``: Get MTD geometry
- ``MTDIOC_BULKERASE``: Erase the entire device
- ``MTDIOC_ISBAD``: Check if a block is bad
is provided via a single ``ioctl`` method (see
``include/nuttx/fs/ioctl.h``):
+9
View File
@@ -837,6 +837,15 @@ static int nand_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
}
break;
case MTDIOC_ISBAD:
{
FAR struct mtd_bad_block_s *bad_block =
(FAR struct mtd_bad_block_s *)arg;
bad_block->bad_flag = nand_isbad(dev, bad_block->block_num);
ret = OK;
}
break;
default:
ret = -ENOTTY; /* Bad command */
break;
+11
View File
@@ -85,6 +85,9 @@
* OUT: None
* Resets the device to the power-on
* default condition */
#define MTDIOC_ISBAD _MTDIOC(0x000e) /* IN: Erase block number
* OUT: 0=A good block
* 1=A bad block */
/* Macros to hide implementation */
@@ -158,6 +161,14 @@ struct mtd_erase_s
uint32_t nblocks; /* Number of blocks to be erased */
};
/* This structure store the bad block information of a block */
struct mtd_bad_block_s
{
off_t block_num;
int bad_flag;
};
/* This structure defines the interface to a simple memory technology device.
* It will likely need to be extended in the future to support more complex
* devices.