mtd: add OTP (one-time-programmable) erase ioctl
Subsystems (2)
PATCH 1/1 mtd: add OTP (one-time-programmable) erase ioctl
This may sound like a contradiction but some SPI-NOR flashes really support erasing their OTP region until it is finally locked. Having the possibility to erase an OTP region might come in handy during development.
The ioctl argument follows the OTPLOCK style.
---
Changes since RFC:
- check write permissions for OTPERASE
- use correct ioctl macro (_IOW)
drivers/mtd/mtdchar.c | 7 ++++++- drivers/mtd/mtdcore.c | 12 ++++++++++++ include/linux/mtd/mtd.h | 3 +++ include/uapi/mtd/mtd-abi.h | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-)
drivers/mtd/mtdchar.c +6 -1
@@ -666,6 +666,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)case MEMWRITEOOB :case MEMWRITEOOB64 :case MEMWRITE : +case OTPERASE :if (!(file->f_mode &FMODE_WRITE ))return -EPERM ;break ;
@@ -930,6 +931,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) }case OTPLOCK : +case OTPERASE : {struct otp_info oinfo;
@@ -937,7 +939,10 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)return -EINVAL ;if (copy_from_user (&oinfo, argp,sizeof (oinfo)))return -EFAULT ; - ret =mtd_lock_user_prot_reg (mtd, oinfo.start, oinfo.length); +if (cmd ==OTPLOCK ) + ret =mtd_lock_user_prot_reg (mtd, oinfo.start, oinfo.length); +else + ret =mtd_erase_user_prot_reg (mtd, oinfo.start, oinfo.length);break ; }
drivers/mtd/mtdcore.c +12 -0
@@ -1919,6 +1919,18 @@ int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len) }EXPORT_SYMBOL_GPL (mtd_lock_user_prot_reg); +int mtd_erase_user_prot_reg (struct mtd_info *mtd,loff_t from,size_t len) +{ +struct mtd_info *master =mtd_get_master (mtd); + +if (!master->_erase_user_prot_reg) +return -EOPNOTSUPP ; +if (!len) +return 0 ; +return master->_erase_user_prot_reg (master, from, len); +} +EXPORT_SYMBOL_GPL (mtd_erase_user_prot_reg); +/* Chip-supported device locking */ int mtd_lock (struct mtd_info *mtd,loff_t ofs,uint64_t len) {
include/linux/mtd/mtd.h +3 -0
@@ -337,6 +337,8 @@ struct mtd_info { size_t len, size_t *retlen, u_char *buf);int (*_lock_user_prot_reg) (struct mtd_info *mtd,loff_t from,size_t len); +int (*_erase_user_prot_reg) (struct mtd_info *mtd,loff_t from, +size_t len);int (*_writev) (struct mtd_info *mtd,const struct kvec *vecs,unsigned long count,loff_t to,size_t *retlen);void (*_sync) (struct mtd_info *mtd);
@@ -518,6 +520,7 @@ int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,int mtd_write_user_prot_reg (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen,u_char *buf);int mtd_lock_user_prot_reg (struct mtd_info *mtd,loff_t from,size_t len); +int mtd_erase_user_prot_reg (struct mtd_info *mtd,loff_t from,size_t len);int mtd_writev (struct mtd_info *mtd,const struct kvec *vecs,unsigned long count,loff_t to,size_t *retlen);
include/uapi/mtd/mtd-abi.h +2 -0
@@ -205,6 +205,8 @@ struct otp_info {* without OOB, e.g., NOR flash. */ #define MEMWRITE _IOWR('M', 24, struct mtd_write_req) +/* Erase a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER) */ +#define OTPERASE _IOW('M', 25, struct otp_info)/* * Obsolete legacy interface. Keep it in order not to break userspace
Signature · 1 line
2.20.1
Quoted 9 lines · Michael Walle
This may sound like a contradiction but some SPI-NOR flashes really support erasing their OTP region until it is finally locked. Having the possibility to erase an OTP region might come in handy during development.
The ioctl argument follows the OTPLOCK style.
Signed-off-by Michael Walle <[email protected]>---
[...]
Regards
Vignesh
Michael,
Would you please resend this patch, together with the mtd-utils and the SPI NOR patch in a single patch set? You'll help us all having all in a single place.
For the new ioctl we'll need acks from all the mtd maintainers and at least a tested-by tag.
Cheers,
ta
Hi Tudor,
Am 2021-04-08 07:51, schrieb [email protected]:
Quoted 3 lines
Would you please resend this patch, together with the mtd-utils and the SPI NOR patch in a single patch set? You'll help us all having all in a single place.
This has already been picked-up:
https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/commit/?h=mtd/next&id=e3c1f1c92d6ede3cfa09d6a103d3d1c1ef645e35
Although, I didn't receive an email notice.
-michael
Miquel Raynal
maintainerHello,
Michael Walle <[email protected]> wrote on Thu, 08 Apr 2021 08:55:42 +0200:
Quoted 7 lines
Hi Tudor,
Am 2021-04-08 07:51, schrieb [email protected]:
Quoted 3 lines
Would you please resend this patch, together with the mtd-utils and the SPI NOR patch in a single patch set? You'll help us all having all in a single place.
Quoted 6 lines
This has already been picked-up:
https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git/commit/?h=mtd/next&id=e3c1f1c92d6ede3cfa09d6a103d3d1c1ef645e35Although, I didn't receive an email notice.
-michael
Sometimes the notifications are not triggered when there is a conflict when applying the patch from patchwork directly. I usually answer manually in this case but I might have forgotten.
About the patch, I felt it was good enough for merging, and I want to avoid applying such patches right before freezing our branches. Hence, I tend to be more aggressive earlier in the release cycles because I hate when my patches get delayed infinitely. The other side is a more careful approach when -rc6 gets tagged so that I can drop anything which would be crazily broken before our -next branches are stalled, leading for an useless public revert. Of course, I am fully open to removing this patch from -next if you ever feel it was too early and will happily get rid of it for this release: we can move the patch for the next release if you agree on this (especially since it touches the ABI).
Cheers,
Miquèl