drivers: mmc: support secure erase.
PATCH 1/1 drivers: mmc: support secure erase.
According to the JEDEC Standard, eMMC v4.4 cards can supoort secure erase. the first bit in ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT] - EXT_CSD_SEC_ER_EN is used to check if secure erase supoort by the device.
--- drivers/mmc/Kconfig | 8 ++++++++ drivers/mmc/mmc.c | 4 ++++ drivers/mmc/mmc_write.c | 16 +++++++++++++--- include/mmc.h | 5 ++++- 4 files changed, 29 insertions(+), 4 deletions(-)
drivers/mmc/Kconfig +8 -0
@@ -18,6 +18,14 @@ config MMC_WRITE help Enable write access to MMC and SD Cards +config MMC_SECURE_ERASE + bool "Enable secure erase for eMMC" + depends on MMC_WRITE + default n + help + This option replace the default erase with secure erase in eMMC v4.4 + and above cards. + config MMC_BROKEN_CD bool "Poll for broken card detection case" help
drivers/mmc/mmc.c +4 -0
@@ -2272,6 +2272,10 @@ static int mmc_startup_v4(struct mmc *mmc)if ((capacity >>20 ) >2 *1024 ) mmc->capacity_user = capacity; } +#if CONFIG_IS_ENABLED (MMC_SECURE_ERASE ) +if (mmc->version >=MMC_VERSION_4_4 &&IS_MMC (mmc)) + mmc->sec_feature_support = ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT ]; +#endif if (mmc->version >=MMC_VERSION_4_5 ) mmc->gen_cmd6_time = ext_csd[EXT_CSD_GENERIC_CMD6_TIME ];
drivers/mmc/mmc_write.c +13 -3
@@ -15,7 +15,7 @@#include <linux/math64.h> #include "mmc_private.h" -static ulong mmc_erase_t (struct mmc *mmc,ulong start,lbaint_t blkcnt) +static ulong mmc_erase_t (struct mmc *mmc,ulong start,lbaint_t blkcnt,uint arg) {struct mmc_cmd cmd;ulong end;
@@ -52,7 +52,7 @@ static ulong mmc_erase_t(struct mmc *mmc, ulong start, lbaint_t blkcnt) goto err_out; cmd.cmdidx =MMC_CMD_ERASE ; - cmd.cmdarg =MMC_ERASE_ARG ; + cmd.cmdarg = arg; cmd.resp_type = MMC_RSP_R1b; err =mmc_send_cmd (mmc, &cmd,NULL );
@@ -81,6 +81,7 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt)struct mmc *mmc =find_mmc_device (dev_num);lbaint_t blk =0 , blk_r =0 ;int timeout_ms =1000 ; +uint arg =MMC_ERASE_ARG ;if (!mmc)return -1 ;
@@ -105,6 +106,15 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt) ((start + blkcnt + mmc->erase_grp_size) & ~(mmc->erase_grp_size - 1)) - 1); +#if CONFIG_IS_ENABLED (MMC_SECURE_ERASE ) +if (!(mmc->sec_feature_support &EXT_CSD_SEC_ER_EN )) { +printf ("secure erase not supported on device\n" +"perform insecure erase\n" ); + }else { + arg =MMC_SECURE_ERASE_ARG ; + } +#endif +while (blk < blkcnt) {if (IS_SD (mmc) && mmc->ssr.au) { blk_r = ((blkcnt - blk) > mmc->ssr.au) ?
@@ -113,7 +123,7 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt) blk_r = ((blkcnt - blk) > mmc->erase_grp_size) ? mmc->erase_grp_size : (blkcnt - blk); } - err =mmc_erase_t (mmc, start + blk, blk_r); + err =mmc_erase_t (mmc, start + blk, blk_r, arg);if (err)break ;
include/mmc.h +4 -1
@@ -80,7 +80,6 @@ struct bd_info;#define MMC_MODE_1BIT BIT(28)#define MMC_MODE_SPI BIT(27) -#define SD_DATA_4BIT 0x00040000#define IS_SD (x) ((x)->version & SD_VERSION_SD)
@@ -240,6 +239,7 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)#define EXT_CSD_HC_WP_GRP_SIZE 221/* RO */ #define EXT_CSD_HC_ERASE_GRP_SIZE 224/* RO */ #define EXT_CSD_BOOT_MULT 226/* RO */ +#define EXT_CSD_SEC_FEATURE_SUPPORT 231/* RO */ #define EXT_CSD_GENERIC_CMD6_TIME 248/* RO */ #define EXT_CSD_BKOPS_SUPPORT 502/* RO */
@@ -247,6 +247,8 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)* EXT_CSD field definitions */ +#define EXT_CSD_SEC_ER_EN BIT(0) +#define EXT_CSD_CMD_SET_NORMAL (1 << 0)#define EXT_CSD_CMD_SET_SECURE (1 << 1)#define EXT_CSD_CMD_SET_CPSECURE (1 << 2)
@@ -690,6 +692,7 @@ struct mmc {uint tran_speed;uint legacy_speed;/* speed for the legacy mode provided by the card */ uint read_bl_len; +u8 sec_feature_support;#if CONFIG_IS_ENABLED (MMC_WRITE )uint write_bl_len;uint erase_grp_size;/* in 512-byte sectors */
Signature · 1 line
2.17.1
PATCH 1/1 drivers: mmc: support secure erase.
Hi,
CC'd Peng (mmc maintainer).
Quoted 3 lines · dennis
According to the JEDEC Standard, eMMC v4.4 cards can supoort secure erase. the first bit in ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT] -
EXT_CSD_SEC_ER_ENis used to check if secure erase supoort by the device.
%s/supoort/supports/
Anyway, i don't know what
Quoted 33 lines
Signed-off-by dennis <[email protected]>--- drivers/mmc/Kconfig | 8 ++++++++ drivers/mmc/mmc.c | 4 ++++ drivers/mmc/mmc_write.c | 16 +++++++++++++--- include/mmc.h | 5 ++++- 4 files changed, 29 insertions(+), 4 deletions(-)drivers/mmc/Kconfig +8
-0@@ -18,6 +18,14 @@ config MMC_WRITE help Enable write access to MMC and SD Cards +config MMC_SECURE_ERASE + bool "Enable secure erase for eMMC" + depends on MMC_WRITE + default n + help + This option replace the default erase with secure erase in eMMC v4.4 + and above cards. + config MMC_BROKEN_CD bool "Poll for broken card detection case" helpdrivers/mmc/mmc.c +0
-0
drivers/mmc/mmc.c static int mmc_startup_v4(struct mmc *mmc) · line 2276
Quoted 5 lines
drivers/mmc/mmc.c +2
-0@@ -2272,6 +2272,10 @@ static int mmc_startup_v4(struct mmc *mmc)if ((capacity >>20 ) >2 *1024 ) mmc->capacity_user = capacity; } +#if CONFIG_IS_ENABLED (MMC_SECURE_ERASE ) +if (mmc->version >=MMC_VERSION_4_4 &&IS_MMC (mmc))
if (IS_ENABLED())?
Quoted 36 lines
drivers/mmc/mmc.c +2
-0+ mmc->sec_feature_support = ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT ]; +#endif if (mmc->version >=MMC_VERSION_4_5 ) mmc->gen_cmd6_time = ext_csd[EXT_CSD_GENERIC_CMD6_TIME ];drivers/mmc/mmc_write.c +3
-2@@ -15,7 +15,7 @@#include <linux/math64.h> #include "mmc_private.h" -static ulong mmc_erase_t (struct mmc *mmc,ulong start,lbaint_t blkcnt) +static ulong mmc_erase_t (struct mmc *mmc,ulong start,lbaint_t blkcnt,uint arg) {struct mmc_cmd cmd;ulong end;@@ -52,7 +52,7 @@ static ulong mmc_erase_t(struct mmc *mmc, ulong start, lbaint_t blkcnt) goto err_out; cmd.cmdidx =MMC_CMD_ERASE ; - cmd.cmdarg =MMC_ERASE_ARG ; + cmd.cmdarg = arg; cmd.resp_type = MMC_RSP_R1b; err =mmc_send_cmd (mmc, &cmd,NULL );@@ -81,6 +81,7 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt)struct mmc *mmc =find_mmc_device (dev_num);lbaint_t blk =0 , blk_r =0 ;int timeout_ms =1000 ; +uint arg =MMC_ERASE_ARG ;if (!mmc)return -1 ;
drivers/mmc/mmc_write.c ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt) · line 110
Quoted 5 lines
drivers/mmc/mmc_write.c +2
-0@@ -105,6 +106,15 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt) ((start + blkcnt + mmc->erase_grp_size) & ~(mmc->erase_grp_size - 1)) - 1); +#if CONFIG_IS_ENABLED (MMC_SECURE_ERASE ) +if (!(mmc->sec_feature_support &EXT_CSD_SEC_ER_EN )) {
ditto. if (IS_ENABLED()) instead of #if.
And i don't know why doesn't check this in mmc_erase_t(). Then it doesn't need to pass arg as argument.
Quoted 24 lines
drivers/mmc/mmc_write.c +8
-1+printf ("secure erase not supported on device\n" + "perform insecure erase\n"); + }else { + arg =MMC_SECURE_ERASE_ARG ; + } +#endif +while (blk < blkcnt) {if (IS_SD (mmc) && mmc->ssr.au) { blk_r = ((blkcnt - blk) > mmc->ssr.au) ?@@ -113,7 +123,7 @@ ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt) blk_r = ((blkcnt - blk) > mmc->erase_grp_size) ? mmc->erase_grp_size : (blkcnt - blk); } - err =mmc_erase_t (mmc, start + blk, blk_r); + err =mmc_erase_t (mmc, start + blk, blk_r, arg);if (err)break ;include/mmc.h +0
-0
include/mmc.h struct bd_info; · line 83
Quoted 4 lines
include/mmc.h +0
-1@@ -80,7 +80,6 @@ struct bd_info;#define MMC_MODE_1BIT BIT(28)#define MMC_MODE_SPI BIT(27) -
Not need to touch this.
Quoted 21 lines
include/mmc.h +3
-0#define SD_DATA_4BIT 0x00040000#define IS_SD (x) ((x)->version & SD_VERSION_SD)@@ -240,6 +239,7 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)#define EXT_CSD_HC_WP_GRP_SIZE 221/* RO */ #define EXT_CSD_HC_ERASE_GRP_SIZE 224/* RO */ #define EXT_CSD_BOOT_MULT 226/* RO */ +#define EXT_CSD_SEC_FEATURE_SUPPORT 231/* RO */ #define EXT_CSD_GENERIC_CMD6_TIME 248/* RO */ #define EXT_CSD_BKOPS_SUPPORT 502/* RO */ @@ -247,6 +247,8 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)* EXT_CSD field definitions */ +#define EXT_CSD_SEC_ER_EN BIT(0) +#define EXT_CSD_CMD_SET_NORMAL (1 << 0)#define EXT_CSD_CMD_SET_SECURE (1 << 1)#define EXT_CSD_CMD_SET_CPSECURE (1 << 2)
include/mmc.h struct mmc { · line 695
Quoted 4 lines
include/mmc.h +1
-0@@ -690,6 +692,7 @@ struct mmc {uint tran_speed;uint legacy_speed;/* speed for the legacy mode provided by the card */ uint read_bl_len; +u8 sec_feature_support;
This is located at below under MMC_WRITE and it's only used when MMC_SECURE_ERASE is enabled.
Best Regards,
Jaehoon Chung
Quoted 4 lines
include/mmc.h +0
-0#if CONFIG_IS_ENABLED (MMC_WRITE )uint write_bl_len;uint erase_grp_size;/* in 512-byte sectors */
PATCH 1/1 drivers: mmc: support secure erase.
Hi Jaehoon Chung,
for your comment:
"ditto. if (IS_ENABLED()) instead of #if.
And i don't know why doesn't check this in mmc_erase_t(). Then it doesn't need to pass arg as argument."
I check the support of secure erase in the mmc_berase and not in mmc_erase_t because mmc_erase_t is called multiple times for each block. So to prevent unnecessary checks, I check the support in mmc_berase function.
PATCH 1/1 drivers: mmc: support secure erase.
Hi Dennis,
Quoted 10 lines · On 12/26/20 5:44 PM, dennis laplacian1 wrote:
Hi Jaehoon Chung,
for your comment:
"ditto. if (IS_ENABLED()) instead of #if.
And i don't know why doesn't check this inmmc_erase_t(). Then it doesn't need to pass arg as argument."I check the support of secure erase in the
mmc_beraseand not inmmc_erase_tbecausemmc_erase_tis called multiple times for each block. So to prevent unnecessary checks, I check the support inmmc_berasefunction.
It there any problem to check a condition in mmc_erase_t()? or any dramatic degradation? And CONFIG_MMC_SECURE_ERASE is not enabled by default. So It doesn't need to add a variable.
Best Regards,
Jaehoon Chung
Quoted 1 line
PATCH 1/1 drivers: mmc: support secure erase.
Hi Jaehoon.
The only degradation is that the check will be for every block in the deleted range and not for the range.
I can move the check to mmc_erase_t, but then if the device is not supporting secure erase the error message will be printed for every block. I can check the support also in mmc_berase and print an error message only in this function.
What do you think?
??????? ??? ??, 28 ????? 2020 ?-0:39 ??? ?Jaehoon Chung?? <? [email protected]??>:?
Quoted 25 lines
Hi Dennis,
Quoted 10 lines · On 12/26/20 5:44 PM, dennis laplacian1 wrote:
Hi Jaehoon Chung,
for your comment:
"ditto. if (IS_ENABLED()) instead of #if.
And i don't know why doesn't check this inmmc_erase_t(). Then it doesn't need to pass arg as argument."I check the support of secure erase in the
mmc_beraseand not inmmc_erase_tbecausemmc_erase_tis called multiple times for each block. So to prevent unnecessary checks, I check the support inmmc_berasefunction.It there any problem to check a condition in
mmc_erase_t()? or any dramatic degradation?
AndCONFIG_MMC_SECURE_ERASEis not enabled by default. So It doesn't need to add a variable.Best Regards,
Jaehoon ChungQuoted 1 line
PATCH 1/1 drivers: mmc: support secure erase.
Hi Dennis,
Quoted 8 lines · On 1/1/21 8:42 PM, dennis laplacian1 wrote:
Hi Jaehoon.
The only degradation is that the check will be for every block in the deleted range and not for the range.
I can move the check tommc_erase_t, but then if the device is not supporting secure erase the error message will be printed for every block. I can check the support also inmmc_beraseand print an error message only in this function.
What do you think?
I understood what you said. Your code is displaying "secure erase not supported..". So it will be displayed spamming when card doesn't support secure erase. In this case, your mention is right.
Well, if you're ok, it can be changed from printf to debug.
And I think that it can be located to mmc->sec_feature_support is assigned.
If it needs to know whether card is sec_feature_support or not, i think that it can be implemented into mmcinfo. I don't think what's correct or wrong. :) It's just my preference.
Best Regards,
Jaehoon Chung
Quoted 30 lines
??????? ??? ??, 28 ????? 2020 ?-0:39 ??? ?Jaehoon Chung?? <? jh80.chung at samsung.com??>:?
Quoted 25 lines
Hi Dennis,
Quoted 10 lines · On 12/26/20 5:44 PM, dennis laplacian1 wrote:
Hi Jaehoon Chung,
for your comment:
"ditto. if (IS_ENABLED()) instead of #if.
And i don't know why doesn't check this inmmc_erase_t(). Then it doesn't need to pass arg as argument."I check the support of secure erase in the
mmc_beraseand not inmmc_erase_tbecausemmc_erase_tis called multiple times for each block. So to prevent unnecessary checks, I check the support inmmc_berasefunction.It there any problem to check a condition in
mmc_erase_t()? or any dramatic degradation?
AndCONFIG_MMC_SECURE_ERASEis not enabled by default. So It doesn't need to add a variable.Best Regards,
Jaehoon ChungQuoted 1 line