Skip to content

Commit 9938424

Browse files
richardcochranDavid Woodhouse
authored andcommitted
mtd: add an ioctl to query the lock status of a flash sector
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> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 1df6206 commit 9938424

5 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎drivers/mtd/chips/cfi_cmdset_0001.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *);
6363
static void cfi_intelext_sync (struct mtd_info *);
6464
static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
6565
static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
66+
static int cfi_intelext_is_locked(struct mtd_info *mtd, loff_t ofs,
67+
uint64_t len);
6668
#ifdef CONFIG_MTD_OTP
6769
static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
6870
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)
448450
mtd->sync = cfi_intelext_sync;
449451
mtd->lock = cfi_intelext_lock;
450452
mtd->unlock = cfi_intelext_unlock;
453+
mtd->is_locked = cfi_intelext_is_locked;
451454
mtd->suspend = cfi_intelext_suspend;
452455
mtd->resume = cfi_intelext_resume;
453456
mtd->flags = MTD_CAP_NORFLASH;
@@ -2139,6 +2142,13 @@ static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
21392142
return ret;
21402143
}
21412144

2145+
static int cfi_intelext_is_locked(struct mtd_info *mtd, loff_t ofs,
2146+
uint64_t len)
2147+
{
2148+
return cfi_varsize_frob(mtd, do_getlockstatus_oneblock,
2149+
ofs, len, NULL) ? 1 : 0;
2150+
}
2151+
21422152
#ifdef CONFIG_MTD_OTP
21432153

21442154
typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip,

‎drivers/mtd/mtdchar.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,20 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
676676
break;
677677
}
678678

679+
case MEMISLOCKED:
680+
{
681+
struct erase_info_user einfo;
682+
683+
if (copy_from_user(&einfo, argp, sizeof(einfo)))
684+
return -EFAULT;
685+
686+
if (!mtd->is_locked)
687+
ret = -EOPNOTSUPP;
688+
else
689+
ret = mtd->is_locked(mtd, einfo.start, einfo.length);
690+
break;
691+
}
692+
679693
/* Legacy interface */
680694
case MEMGETOOBSEL:
681695
{

‎drivers/mtd/mtdpart.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
264264
return part->master->unlock(part->master, ofs + part->offset, len);
265265
}
266266

267+
static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
268+
{
269+
struct mtd_part *part = PART(mtd);
270+
if ((len + ofs) > mtd->size)
271+
return -EINVAL;
272+
return part->master->is_locked(part->master, ofs + part->offset, len);
273+
}
274+
267275
static void part_sync(struct mtd_info *mtd)
268276
{
269277
struct mtd_part *part = PART(mtd);
@@ -402,6 +410,8 @@ static struct mtd_part *add_one_partition(struct mtd_info *master,
402410
slave->mtd.lock = part_lock;
403411
if (master->unlock)
404412
slave->mtd.unlock = part_unlock;
413+
if (master->is_locked)
414+
slave->mtd.is_locked = part_is_locked;
405415
if (master->block_isbad)
406416
slave->mtd.block_isbad = part_block_isbad;
407417
if (master->block_markbad)

‎include/linux/mtd/mtd.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ struct mtd_info {
216216
/* Chip-supported device locking */
217217
int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
218218
int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
219+
int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
219220

220221
/* Power Management functions */
221222
int (*suspend) (struct mtd_info *mtd);

‎include/mtd/mtd-abi.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ struct otp_info {
110110
#define MEMERASE64 _IOW('M', 20, struct erase_info_user64)
111111
#define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64)
112112
#define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64)
113+
#define MEMISLOCKED _IOR('M', 23, struct erase_info_user)
113114

114115
/*
115116
* Obsolete legacy interface. Keep it in order not to break userspace

0 commit comments

Comments
 (0)