You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

eMMC卡安全擦除问题:BLKSECDISCARD返回EOPNOTSUPP错误

Fixing EOPNOTSUPP for BLKSECDISCARD/BLKDISCARD on MMC Cards

Alright, let's break down why you're hitting the EOPNOTSUPP (Operation Not Supported) error when trying to securely erase your MMC card via those ioctls, and walk through how to resolve it.

Root Cause

The core issue is that your kernel's MMC subsystem hasn't enabled DISCARD functionality for your block device. As you found in the code, mmc_queue_setup_discard() (in kernel/linux/drivers/mmc/card/queue.c) only sets the QUEUE_FLAG_DISCARD flag if mmc_can_erase(card) returns true. If that check fails, the block device won't advertise support for BLKDISCARD or BLKSECDISCARD, hence the error when you call those ioctls.

Deep Dive into mmc_can_erase()

Let's unpack what mmc_can_erase() (defined in kernel/linux/drivers/mmc/core/core.c) actually checks:

  • First, it verifies the card supports the basic MMC_CMD_ERASE command—this is the low-level erase instruction the card understands.
  • Next, it validates the card type: it must be a standard MMC card (not an SD card, which uses different erase logic), and it can't be an MMC Mobile or reduced-function MMC card.
  • Finally, it checks that the card's CSD register has a valid erase_grp_size value—this tells the kernel the card supports block-aligned erase operations.

If any of these conditions aren't met, mmc_can_erase() returns false, and DISCARD support stays disabled.

Troubleshooting & Fix Steps

Here's how to tackle this step by step:

  • Verify the MMC card's hardware capabilities first
    Use tools like mmc-utils (try the mmc erase command) to test if the card responds to low-level erase commands. If the hardware itself doesn't support erase, no kernel tweaks will help—you'll need to swap in an MMC card that does support this feature.
  • Check your kernel configuration
    Make sure CONFIG_MMC_BLOCK_DISCARD is enabled in your kernel config. This is the compile-time switch that allows the MMC block driver to expose DISCARD functionality to user space. Without it, even a compatible card won't support those ioctls.
  • Debug why mmc_can_erase() is failing
    If your card should support erase but the function returns false, add debug prints to the mmc_can_erase() function to pinpoint which check is failing:
    pr_debug("MMC card type: %d, erase cmd support: %d, erase group size: %d\n",
             card->type, mmc_card_erase(card), card->csd.erase_grp_size);
    
    Check the dmesg output after booting to see which condition isn't satisfied. For example, if the card type is misidentified, you might need to adjust the driver's card detection logic.
  • Alternative approach if DISCARD can't be enabled
    If you can't get BLKSECDISCARD working, you can skip the block layer entirely and call the MMC subsystem's low-level erase API directly from kernel space:
    int ret = mmc_erase(card, start_sector, num_sectors);
    
    If you need user-space access, you could wrap this in a custom character device driver to expose the erase functionality to your application.

内容的提问来源于stack exchange,提问作者Matt Muggeridge

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:14:36