diff --git a/Documentation/components/drivers/special/mtd.rst b/Documentation/components/drivers/special/mtd.rst index d165ca70b61..8f7f6b70914 100644 --- a/Documentation/components/drivers/special/mtd.rst +++ b/Documentation/components/drivers/special/mtd.rst @@ -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``): diff --git a/drivers/mtd/mtd_nand.c b/drivers/mtd/mtd_nand.c index c2eb679eeca..8bdd9723e85 100644 --- a/drivers/mtd/mtd_nand.c +++ b/drivers/mtd/mtd_nand.c @@ -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; diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index 6fe379e9963..aec16db1e3a 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -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.