任何办法从用户空间的Linux发送到SD卡的命令? [英] Any way to send commands to SD card from Linux userspace?

查看:2624
本文介绍了任何办法从用户空间的Linux发送到SD卡的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Debian的Linux 7.0 3.2嵌入式ARM TI AM335x系统。这是我们开发了定制电路板,但SD卡部分至少是一样的开发板。有一些供应商特定SD卡的命令,我想发出的卡,即采用阅读一些CMD56 SMART数据。

I have a Debian 7.0 Linux 3.2 embedded ARM TI AM335x system. This is a custom board we've developed, but the SD card section at least is the same as the development board. There are some vendor-specific SD card commands I'd like to issue to the card, namely reading some SMART data using CMD56.

有没有办法将命令发送到SD卡控制器,并读取用户空间的反应?

Is there any way to send commands to the SD card controller and read the response from userspace?

推荐答案

您驱动程序是<一个href=\"http://lxr.free-electrons.com/source/drivers/mmc/host/omap_hsmmc.c?v=3.14\"><$c$c>omap_hsmmc根据<一个href=\"http://processors.wiki.ti.com/index.php/AM335x_MMC/SD_Driver%27s_Guide\">http://processors.wiki.ti.com/index.php/AM335x_MMC/SD_Driver%27s_Guide一些信息也是<一个href=\"https://www.kernel.org/doc/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt\">https://www.kernel.org/doc/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt

Your driver is omap_hsmmc according to http://processors.wiki.ti.com/index.php/AM335x_MMC/SD_Driver%27s_Guide some info also in https://www.kernel.org/doc/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt

在一些的网站的搜索在SD卡智能监控支持,我得到的搜索查询 MMC smartctl读取(因为 smartctl读取中的Linux * ATA SMART监控工具的名称, MMC 是实现MMC,SD,SDHC卡和控制器的内核子系统。我发现的bug充满对抗的一些移动PC操作系统的<一个href=\"https://$c$c.google.com/p/chromium/issues/detail?id=315380\">https://$c$c.google.com/p/chromium/issues/detail?id=315380通过Gwendal Grignou

After some web searching for SMART monitoring support in sd cards, I get the search query mmc smartctl (because smartctl is name of SMART monitoring utility for *ATA in Linux, and mmc is the kernel subsystem to implement MMC, SD, SDHC cards and controllers. I found the bug filled against some mobile PC OS, https://code.google.com/p/chromium/issues/detail?id=315380 by Gwendal Grignou

如果根设备是一个SATA设备:

If the root device is a SATA device:


      
  • 添加hdparm的 - 我的/ dev / sda的输出

  •   
  • 添加-a smartctl读取的/ dev / sda的输出

  •   

如果根设备是一个eMMC的设备:

If the root device is a eMMC device:


      
  • 当MMC-utils的将是图像的一部分,添加一个类似命令的输出。

  •   

这听起来像 MMC-utils的它选择的工具来实施智能SD卡。有在kernel.org MMC-utils的的家的git:<一href=\"http://git.kernel.org/cgit/linux/kernel/git/cjb/mmc-utils.git/tree/\">http://git.kernel.org/cgit/linux/kernel/git/cjb/mmc-utils.git/tree/

It sounds like the mmc-utils it the tool of choice to implement SMART for SD cards. There is home git of mmc-utils on kernel.org: http://git.kernel.org/cgit/linux/kernel/git/cjb/mmc-utils.git/tree/

我没有看到SMART在这里,但<一个href=\"http://git.kernel.org/cgit/linux/kernel/git/cjb/mmc-utils.git/tree/mmc_cmds.c\">mmc-utils/mmc_cmds.c有code发送使用的ioctl自定义命令到卡(FD,MMC_IOC_CMD,(结构mmc_ioc_cmd *)及ioctl_data)与FD指向正确的 mmcblkX 设备(我希望这个作品与大多数SD控制器)。由Johan RUDHOLM code(从ST-Ericsson的,2012年,在GPLv2):

I see no "SMART" here, but the mmc-utils/mmc_cmds.c has code to send custom commands to the card by using ioctl(fd, MMC_IOC_CMD, (struct mmc_ioc_cmd*) &ioctl_data) with fd pointing to correct mmcblkX device (I hope this works with most SD controllers). Code by Johan RUDHOLM (from st-ericsson, 2012, GPLv2):

   int read_extcsd(int fd, __u8 *ext_csd)
   {
       struct mmc_ioc_cmd idata;
       memset(&idata, 0, sizeof(idata));
       memset(ext_csd, 0, sizeof(__u8) * 512);
       idata.write_flag = 0;
       idata.opcode = MMC_SEND_EXT_CSD;
       idata.arg = 0;
       idata.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
       idata.blksz = 512;
       idata.blocks = 1;
       mmc_ioc_cmd_set_data(idata, ext_csd);

       return  ioctl(fd, MMC_IOC_CMD, &idata);
   }

   int write_extcsd_value(int fd, __u8 index, __u8 value)
   {
       struct mmc_ioc_cmd idata;

       memset(&idata, 0, sizeof(idata));
       idata.write_flag = 1;
       idata.opcode = MMC_SWITCH;
       idata.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) |
            (index << 16) |
            (value << 8) |
            EXT_CSD_CMD_SET_NORMAL;
       idata.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;

       return ioctl(fd, MMC_IOC_CMD, &idata);
   }

有关MMC_IOC_CMD一些文档和例子是在LKML 20张贴Shashidhar Hiremath十二月14:54 2011 [PATCH 1/1] MMC:用户应用程序进行测试SD / MMC命令和额外的IOCTL命令MMC卡复位

Some documentation and examples for MMC_IOC_CMD were posted in LKML by Shashidhar Hiremath at 20 Dec 14:54 2011 "[PATCH 1/1] mmc: User Application for testing SD/MMC Commands and extra IOCTL Command for MMC card reset"

结构mmc_ioc_cmd 官方userAPI(uapi)是在Linux源代码树<一个href=\"http://lxr.free-electrons.com/source/include/uapi/linux/mmc/ioctl.h?v=3.14\"><$c$c>include/uapi/linux/mmc/ioctl.h:

The official userAPI (uapi) for struct mmc_ioc_cmd is in linux source tree include/uapi/linux/mmc/ioctl.h:

  6 struct mmc_ioc_cmd {
...
 10         /* Application-specific command.  true = precede with CMD55 */
 11         int is_acmd;
...
 51  * Since this ioctl is only meant to enhance (and not replace) normal access
 52  * to the mmc bus device...

这篇关于任何办法从用户空间的Linux发送到SD卡的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆