From cddd9c9c38ee827a682d826fffc615ff386e35f1 Mon Sep 17 00:00:00 2001 From: Gustavo Henrique Nihei Date: Fri, 30 Jul 2021 10:40:18 -0300 Subject: [PATCH] mtd: Enable retrieval of MTD partition information Signed-off-by: Gustavo Henrique Nihei --- drivers/mtd/mtd_partition.c | 19 +++++++++++++++++++ include/nuttx/mtd/mtd.h | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/mtd/mtd_partition.c b/drivers/mtd/mtd_partition.c index 4760c2ce3f..a771604001 100644 --- a/drivers/mtd/mtd_partition.c +++ b/drivers/mtd/mtd_partition.c @@ -414,6 +414,25 @@ static int part_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) } break; + case MTDIOC_PARTINFO: + { + FAR struct partition_info_s *info = + (FAR struct partition_info_s *)arg; + if (info != NULL) + { + info->magic = 0; + info->numsectors = priv->neraseblocks * priv->blkpererase; + info->sectorsize = priv->blocksize; + info->startsector = priv->firstblock; + info->endsector = priv->firstblock + info->numsectors; + + strncpy(info->parent, priv->parent->name, NAME_MAX); + + ret = OK; + } + } + break; + case MTDIOC_XIPBASE: { FAR void **ppv = (FAR void**)arg; diff --git a/include/nuttx/mtd/mtd.h b/include/nuttx/mtd/mtd.h index fa29318c83..2b95bd13f4 100644 --- a/include/nuttx/mtd/mtd.h +++ b/include/nuttx/mtd/mtd.h @@ -74,6 +74,12 @@ #define MTDIOC_ERASESTATE _MTDIOC(0x000a) /* IN: Pointer to uint8_t * OUT: Byte value that represents the * erased state of the MTD cell */ +#define MTDIOC_PARTINFO _MTDIOC(0x000b) /* IN: Pointer to writable struct + * partition_info_s in which to + * receive partition information data + * OUT: Partition information structure + * populated with data from the MTD + * partition */ /* Macros to hide implementation */