有什么方法可以从Linux用户空间向SD卡发送命令吗?

前端之家收集整理的这篇文章主要介绍了有什么方法可以从Linux用户空间向SD卡发送命令吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个Debian 7.0 Linux 3.2嵌入式ARM TI AM335x系统.这是我们开发的定制板,但SD卡部分至少与开发板相同.我想向卡发出一些供应商特定的SD卡命令,即使用CMD56读取一些SMART数据.

有没有办法向SD卡控制器发送命令并从用户空间读取响应?

解决方法

根据 http://processors.wiki.ti.com/index.php/AM335x_MMC/SD_Driver%27s_Guide,你的驱动程序是 omap_hsmmc,也是 https://www.kernel.org/doc/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt的一些信息

在网上搜索SD卡中的SMART监控支持后,我得到了搜索查询mmc smartctl(因为smartctl是Linux中* ATA的SMART监控实用程序的名称,而mmc是实现MMC,SD,SDHC卡和控制器的内核子系统我发现Gwendal Grignou在某些移动PC OS https://code.google.com/p/chromium/issues/detail?id=315380上填充了这个bug

If the root device is a SATA device:

  • Add output of hdparm -I /dev/sda
  • Add output of smartctl -a /dev/sda

If the root device is a eMMC device:

  • When mmc-utils will be part of the image,add a similar command output.

听起来像mmc-utils它是实现SMART SD卡的首选工具. kernel.org上有mmc-utils的主页git:http://git.kernel.org/cgit/linux/kernel/git/cjb/mmc-utils.git/tree/

我在这里看不到“SMART”,但是mmc-utils/mmc_cmds.c代码通过使用ioctl(fd,MMC_IOC_CMD,(struct mmc_ioc_cmd *)& ioctl_data)向fd指向正确的mmcblkX设备向卡发送自定义命令(我希望这适用于大多数SD控制器).代码:Johan RUDHOLM(来自st-ericsson,2012,GPLv2):

  1. int read_extcsd(int fd,__u8 *ext_csd)
  2. {
  3. struct mmc_ioc_cmd idata;
  4. memset(&idata,sizeof(idata));
  5. memset(ext_csd,sizeof(__u8) * 512);
  6. idata.write_flag = 0;
  7. idata.opcode = MMC_SEND_EXT_CSD;
  8. idata.arg = 0;
  9. idata.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
  10. idata.blksz = 512;
  11. idata.blocks = 1;
  12. mmc_ioc_cmd_set_data(idata,ext_csd);
  13.  
  14. return ioctl(fd,&idata);
  15. }
  16.  
  17. int write_extcsd_value(int fd,__u8 index,__u8 value)
  18. {
  19. struct mmc_ioc_cmd idata;
  20.  
  21. memset(&idata,sizeof(idata));
  22. idata.write_flag = 1;
  23. idata.opcode = MMC_SWITCH;
  24. idata.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) |
  25. (index << 16) |
  26. (value << 8) |
  27. EXT_CSD_CMD_SET_NORMAL;
  28. idata.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
  29.  
  30. return ioctl(fd,&idata);
  31. }

MMC_IOC_CMD的一些文档和示例由Shashidhar Hiremath于2011年12月20日14:54 “[PATCH 1/1] mmc: User Application for testing SD/MMC Commands and extra IOCTL Command for MMC card reset”发布在LKML中

struct mmc_ioc_cmd的官方userAPI(uapi)位于linux源代码include/uapi/linux/mmc/ioctl.h中:

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

猜你在找的Linux相关文章