* [PATCH] mtd: Added an ioctl to query the lock status of a flash sector.
@ 2010-05-31 13:12 Richard Cochran
2010-06-13 9:05 ` Artem Bityutskiy
0 siblings, 1 reply; 5+ messages in thread
From: Richard Cochran @ 2010-05-31 13:12 UTC (permalink / raw)
To: linux-mtd
This patchs adds a way for user space programs to find out whether a
flash sector is locked. An optional driver method in the mtd_info struct
provides the information.
Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
---
drivers/mtd/chips/cfi_cmdset_0001.c | 8 ++++++++
drivers/mtd/mtdchar.c | 14 ++++++++++++++
drivers/mtd/mtdpart.c | 10 ++++++++++
include/linux/mtd/mtd.h | 1 +
include/mtd/mtd-abi.h | 1 +
5 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 5fbf29e..67caca7 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -63,6 +63,7 @@ static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *);
static void cfi_intelext_sync (struct mtd_info *);
static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
+static int cfi_intelext_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len);
#ifdef CONFIG_MTD_OTP
static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
@@ -448,6 +449,7 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
mtd->sync = cfi_intelext_sync;
mtd->lock = cfi_intelext_lock;
mtd->unlock = cfi_intelext_unlock;
+ mtd->locked = cfi_intelext_locked;
mtd->suspend = cfi_intelext_suspend;
mtd->resume = cfi_intelext_resume;
mtd->flags = MTD_CAP_NORFLASH;
@@ -2142,6 +2144,12 @@ static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
return ret;
}
+static int cfi_intelext_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+ return cfi_varsize_frob(mtd, do_getlockstatus_oneblock,
+ ofs, len, NULL) ? 1 : 0;
+}
+
#ifdef CONFIG_MTD_OTP
typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip,
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 5b081cb..2c7bdcf 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -663,6 +663,20 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
break;
}
+ case MEMISLOCKED:
+ {
+ struct erase_info_user einfo;
+
+ if (copy_from_user(&einfo, argp, sizeof(einfo)))
+ return -EFAULT;
+
+ if (!mtd->locked)
+ ret = -EOPNOTSUPP;
+ else
+ ret = mtd->locked(mtd, einfo.start, einfo.length);
+ break;
+ }
+
/* Legacy interface */
case MEMGETOOBSEL:
{
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index b8043a9..020b153 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -264,6 +264,14 @@ static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
return part->master->unlock(part->master, ofs + part->offset, len);
}
+static int part_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+ struct mtd_part *part = PART(mtd);
+ if ((len + ofs) > mtd->size)
+ return -EINVAL;
+ return part->master->locked(part->master, ofs + part->offset, len);
+}
+
static void part_sync(struct mtd_info *mtd)
{
struct mtd_part *part = PART(mtd);
@@ -402,6 +410,8 @@ static struct mtd_part *add_one_partition(struct mtd_info *master,
slave->mtd.lock = part_lock;
if (master->unlock)
slave->mtd.unlock = part_unlock;
+ if (master->locked)
+ slave->mtd.locked = part_locked;
if (master->block_isbad)
slave->mtd.block_isbad = part_block_isbad;
if (master->block_markbad)
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 0f32a9b..a40546c 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -219,6 +219,7 @@ struct mtd_info {
/* Chip-supported device locking */
int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
+ int (*locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
/* Power Management functions */
int (*suspend) (struct mtd_info *mtd);
diff --git a/include/mtd/mtd-abi.h b/include/mtd/mtd-abi.h
index be51ae2..e12872e 100644
--- a/include/mtd/mtd-abi.h
+++ b/include/mtd/mtd-abi.h
@@ -110,6 +110,7 @@ struct otp_info {
#define MEMERASE64 _IOW('M', 20, struct erase_info_user64)
#define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64)
#define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64)
+#define MEMISLOCKED _IOR('M', 23, struct erase_info_user)
/*
* Obsolete legacy interface. Keep it in order not to break userspace
--
1.6.3.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mtd: Added an ioctl to query the lock status of a flash sector.
2010-05-31 13:12 [PATCH] mtd: Added an ioctl to query the lock status of a flash sector Richard Cochran
@ 2010-06-13 9:05 ` Artem Bityutskiy
2010-06-14 16:10 ` Richard Cochran
0 siblings, 1 reply; 5+ messages in thread
From: Artem Bityutskiy @ 2010-06-13 9:05 UTC (permalink / raw)
To: Richard Cochran; +Cc: linux-mtd
On Mon, 2010-05-31 at 15:12 +0200, Richard Cochran wrote:
> This patchs adds a way for user space programs to find out whether a
> flash sector is locked. An optional driver method in the mtd_info struct
> provides the information.
>
> Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
> ---
> drivers/mtd/chips/cfi_cmdset_0001.c | 8 ++++++++
> drivers/mtd/mtdchar.c | 14 ++++++++++++++
> drivers/mtd/mtdpart.c | 10 ++++++++++
> include/linux/mtd/mtd.h | 1 +
> include/mtd/mtd-abi.h | 1 +
> 5 files changed, 34 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
> index 5fbf29e..67caca7 100644
> --- a/drivers/mtd/chips/cfi_cmdset_0001.c
> +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
> @@ -63,6 +63,7 @@ static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *);
> static void cfi_intelext_sync (struct mtd_info *);
> static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
> static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
> +static int cfi_intelext_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len);
> #ifdef CONFIG_MTD_OTP
> static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
> static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
> @@ -448,6 +449,7 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
> mtd->sync = cfi_intelext_sync;
> mtd->lock = cfi_intelext_lock;
> mtd->unlock = cfi_intelext_unlock;
> + mtd->locked = cfi_intelext_locked;
> mtd->suspend = cfi_intelext_suspend;
> mtd->resume = cfi_intelext_resume;
> mtd->flags = MTD_CAP_NORFLASH;
I think it is tiny bit nicer to name 'is_locked', which is a bit more
consistent with the already existing 'block_isbad'?
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mtd: Added an ioctl to query the lock status of a flash sector.
2010-06-13 9:05 ` Artem Bityutskiy
@ 2010-06-14 16:10 ` Richard Cochran
2010-06-29 6:42 ` Artem Bityutskiy
2010-07-01 3:44 ` Artem Bityutskiy
0 siblings, 2 replies; 5+ messages in thread
From: Richard Cochran @ 2010-06-14 16:10 UTC (permalink / raw)
To: Artem Bityutskiy; +Cc: linux-mtd
On Sun, Jun 13, 2010 at 12:05:03PM +0300, Artem Bityutskiy wrote:
> I think it is tiny bit nicer to name 'is_locked', which is a bit more
> consistent with the already existing 'block_isbad'?
Okay, here it is again.
Thanks,
Richard
This patchs adds a way for user space programs to find out whether a
flash sector is locked. An optional driver method in the mtd_info struct
provides the information.
Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
---
drivers/mtd/chips/cfi_cmdset_0001.c | 10 ++++++++++
drivers/mtd/mtdchar.c | 14 ++++++++++++++
drivers/mtd/mtdpart.c | 10 ++++++++++
include/linux/mtd/mtd.h | 1 +
include/mtd/mtd-abi.h | 1 +
5 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 62f3ea9..2fadb02 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -63,6 +63,8 @@ static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *);
static void cfi_intelext_sync (struct mtd_info *);
static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
+static int cfi_intelext_is_locked(struct mtd_info *mtd, loff_t ofs,
+ uint64_t len);
#ifdef CONFIG_MTD_OTP
static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
@@ -448,6 +450,7 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
mtd->sync = cfi_intelext_sync;
mtd->lock = cfi_intelext_lock;
mtd->unlock = cfi_intelext_unlock;
+ mtd->is_locked = cfi_intelext_is_locked;
mtd->suspend = cfi_intelext_suspend;
mtd->resume = cfi_intelext_resume;
mtd->flags = MTD_CAP_NORFLASH;
@@ -2139,6 +2142,13 @@ static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
return ret;
}
+static int cfi_intelext_is_locked(struct mtd_info *mtd, loff_t ofs,
+ uint64_t len)
+{
+ return cfi_varsize_frob(mtd, do_getlockstatus_oneblock,
+ ofs, len, NULL) ? 1 : 0;
+}
+
#ifdef CONFIG_MTD_OTP
typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip,
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 8b223c0..a8e69dd 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -676,6 +676,20 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
break;
}
+ case MEMISLOCKED:
+ {
+ struct erase_info_user einfo;
+
+ if (copy_from_user(&einfo, argp, sizeof(einfo)))
+ return -EFAULT;
+
+ if (!mtd->is_locked)
+ ret = -EOPNOTSUPP;
+ else
+ ret = mtd->is_locked(mtd, einfo.start, einfo.length);
+ break;
+ }
+
/* Legacy interface */
case MEMGETOOBSEL:
{
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index b8043a9..4c539de 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -264,6 +264,14 @@ static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
return part->master->unlock(part->master, ofs + part->offset, len);
}
+static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+ struct mtd_part *part = PART(mtd);
+ if ((len + ofs) > mtd->size)
+ return -EINVAL;
+ return part->master->is_locked(part->master, ofs + part->offset, len);
+}
+
static void part_sync(struct mtd_info *mtd)
{
struct mtd_part *part = PART(mtd);
@@ -402,6 +410,8 @@ static struct mtd_part *add_one_partition(struct mtd_info *master,
slave->mtd.lock = part_lock;
if (master->unlock)
slave->mtd.unlock = part_unlock;
+ if (master->is_locked)
+ slave->mtd.is_locked = part_is_locked;
if (master->block_isbad)
slave->mtd.block_isbad = part_block_isbad;
if (master->block_markbad)
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 5326435..43b7d72 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -216,6 +216,7 @@ struct mtd_info {
/* Chip-supported device locking */
int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
+ int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
/* Power Management functions */
int (*suspend) (struct mtd_info *mtd);
diff --git a/include/mtd/mtd-abi.h b/include/mtd/mtd-abi.h
index be51ae2..e12872e 100644
--- a/include/mtd/mtd-abi.h
+++ b/include/mtd/mtd-abi.h
@@ -110,6 +110,7 @@ struct otp_info {
#define MEMERASE64 _IOW('M', 20, struct erase_info_user64)
#define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64)
#define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64)
+#define MEMISLOCKED _IOR('M', 23, struct erase_info_user)
/*
* Obsolete legacy interface. Keep it in order not to break userspace
--
1.6.3.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] mtd: Added an ioctl to query the lock status of a flash sector.
2010-06-14 16:10 ` Richard Cochran
@ 2010-06-29 6:42 ` Artem Bityutskiy
2010-07-01 3:44 ` Artem Bityutskiy
1 sibling, 0 replies; 5+ messages in thread
From: Artem Bityutskiy @ 2010-06-29 6:42 UTC (permalink / raw)
To: Richard Cochran; +Cc: linux-mtd
On Mon, 2010-06-14 at 18:10 +0200, Richard Cochran wrote:
> On Sun, Jun 13, 2010 at 12:05:03PM +0300, Artem Bityutskiy wrote:
> > I think it is tiny bit nicer to name 'is_locked', which is a bit more
> > consistent with the already existing 'block_isbad'?
>
> Okay, here it is again.
Pushed to l2-mtd-2.6.git / master
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mtd: Added an ioctl to query the lock status of a flash sector.
2010-06-14 16:10 ` Richard Cochran
2010-06-29 6:42 ` Artem Bityutskiy
@ 2010-07-01 3:44 ` Artem Bityutskiy
1 sibling, 0 replies; 5+ messages in thread
From: Artem Bityutskiy @ 2010-07-01 3:44 UTC (permalink / raw)
To: Richard Cochran; +Cc: linux-mtd
On Mon, 2010-06-14 at 18:10 +0200, Richard Cochran wrote:
> On Sun, Jun 13, 2010 at 12:05:03PM +0300, Artem Bityutskiy wrote:
> > I think it is tiny bit nicer to name 'is_locked', which is a bit more
> > consistent with the already existing 'block_isbad'?
>
> Okay, here it is again.
>
> Thanks,
> Richard
>
>
> This patchs adds a way for user space programs to find out whether a
> flash sector is locked. An optional driver method in the mtd_info struct
> provides the information.
>
> Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Pushed to l2-mtd-2.6.git / master.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-07-01 3:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-31 13:12 [PATCH] mtd: Added an ioctl to query the lock status of a flash sector Richard Cochran
2010-06-13 9:05 ` Artem Bityutskiy
2010-06-14 16:10 ` Richard Cochran
2010-06-29 6:42 ` Artem Bityutskiy
2010-07-01 3:44 ` Artem Bityutskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).