3

I need to securely erase an MMC card in an embedded system. However, my ioctl(BLKSECDISCARD) returns EOPNOTSUPP, (as does BLKDISCARD).

By reading kernel code, the MMC driver enables DISCARD by setting QUEUE_FLAG_DISCARD in kernel/linux/drivers/mmc/card/queue.c mmc_queue_setup_discard(), which is called as follows:

if (mmc_can_erase(card))
    mmc_queue_setup_discard(mq->queue, card);

Where mmc_can_erase() is defined in kernel/linux/drivers/mmc/core/core.c as:

int mmc_can_erase(struct mmc_card *card)
{
    if ((card->host->caps & MMC_CAP_ERASE) &&
        (card->csd.cmdclass & CCC_ERASE) && card->erase_size)
        return 1;
    return 0;
}

What is required for the conditions in mmc_can_erase() to be met?

Is it a feature of the card, the controller, the driver, the way the kernel is built, or something else?

Ideally, I'd like to enable the BLKSECDISCARD feature, but am unsure what I need to do, or even if it is possible on my embedded system. Can it be done?

Matt Muggeridge
  • 465
  • 3
  • 11

1 Answers1

4

card->host->caps describes the capabilities of the host controller. Where this is set (assuming it is supported) depends on which controller you're using, for example for the SDHCI controller its set in sdhci_setup_host().

card->csd.cmdclass is read from the card's CSD (Card/Device Specific Data), and indicates which classes of commands the card supports. In this case the code is checking for the erase class of commands. See mmc_decode_csd().

card->erase_size is also read from the card's CSD (or the extended CSD if the card has one), and is set in mmc_set_erase_size().

None of these depend on how the kernel is built, but the capabilities of your hardware. To find out which one(s) are preventing you using secure erase you will need to add some instrumentation to your kernel to print the values of these fields.

Stuart Menefy
  • 618
  • 3
  • 6