[元带你学: eMMC协议详解 20] emmc的命令(cmd)、响应(resp)详解

news/2025/2/21 0:15:48/

依JEDEC eMMC 5.1及经验辛苦整理,付费内容,禁止转载

所在专栏 《元带你学: eMMC协议详解》

内容摘要

全文 8100字, 主要内容

对eMMC的command进行详细介绍,主要包含如下内容:

(1) emmc命令有哪些

(2) 使用不同命令时要注意的点

(3) command class 分类

(4) command 命令参数和响应格式


1.前言

eMMC 命令很多, 可以分成很多类。比较重要的是class 0/2/4/11。

2.command类型

command类型说明
bc不带response的广播命令
bcr带有response的广播命令
ac点对点无数据传输
adtc点对点数据传输

表 command类型

3. command格式

如上图所示,eMMC Command 由 48 Bits 组成,各个 Bits 的解析如下所示:

表 command格式

  • 总长度48bits;
  • 固定以起始bit 值0开始,以End Bit 值1结束;
  • transmiter bit表示数据的传输方向,1代表从host to device,即写操作, 0 表示 device to host, 即读操作;
  • command index 用6个bits指示了command的索引,取值范围0~63;
  • argument:有些command需要发送参数,是否需要发送参数依赖于具体的命令;
  • CRC7是包含 Start Bit、Transmission Bit、 Command Index 和 Argument 内容的 CRC 校验值。通过CRC7保护,device 端在接收到CMD时同样会计算一个CRC值,如果与host发送的CRC不一致,则被认为是传输错误;

注1:eMMC可能不会支持0~63的所有命令,有些命令可能会不支持

注2: CRC 校验简单来说,是发送方将需要传输的数据“除于”(模2除)一个约定的数,并将得到的余数附在数据上一并发送出去。接收方收到数据后,再做同样的“除法”,然后校验得到余数是否与接收的余数相同。

如果不相同,那么意味着数据在传输过程中发生了改变。扩展阅读 CRC wiki 中的介绍。

Command 线是一跟线,所以在波形上看到这 48 bit 是依次传输的,看波形时, 要找到 Start bit(从高拉低),然后再数对应的bit 数目偏移, 一般偏移 2 个bit, 看对应的Command 是什么,来分析这一段波形的行为。

4. command class 分类

eMMC将command index(0~56)分成12个class,每个class代表一类功能,包含所有commands的一个子集。具体某一个设备支持哪些class的命令,可以通过CSD寄存器的CCC[95:84] feilds来查询,如bit84为1则表示支持class0。

其实一般命令(除了废弃classs)设备都会支持,也不复杂。要关注的是 class 11 Command Queue 命令,有的平台是不支持Command Queue, 这样无法做CMDQ Read 和 CMDQ Write, 智能用普通的Read(CMD16 or CMD17) 和 普通Write(CMD24 or CMD25) 命令,极速性能也会差一些。

对于 Pack Read 和 Pack Write, 虽然协议有这种, 但实际很少遇到。 这个功能不够灵活, 算是鸡肋功能, 但设备一般支持这个特性,只是主机几乎不会用到。所以大家也不要花太多resource 在 Pack Read/Write 上。

device command classclass description note
class 0basic基本命令
class 1obsolete 废弃
class 2block read块数据读相关命令,包括设置块长度、读取单块、读取多块
class 3obsolete废弃
class 4block write块数据写相关命令,包括设置块个数、写入单块、写入多块、修改设备id寄存器、修改CSD、设置RTC
class 5erase设置擦除组开始地址、设置擦除组结束地址、擦除操作
class 6write protection设置写保护、清除写保护、获取device的写保护状态、获取写保护类型
class 7lock devicelock/unlock device
class 8application-specific指示下一个命令是一个特定应用命令而非标准命令  
class 9I/O mode写寄存器、设置系统进入中断模式
class 10security protocols连续传输数据块从device to host或从host to device
class 11command queuing执行队列里的任务
class 12reserved\

 表 command分类

以上转载自

https://www.cnblogs.com/smartjourneys/p/6657397.html

5. Command 命令和Response 格式

Basic commands (class 0 and class 1)

CMD0

Abbr.TypeArgumentRespDescription
GO_IDLE_STATEbc[31:0] 00000000NoneResets the Device to idle state
GO_PRE_IDLE_STATEbc[31:0] F0F0F0F0NoneResets the Device to pre-idle state
BOOT_INITIATION-[31:0]FFFFFFFANoneInitiate alternative boot operation

CMD1

Abbr.TypeArgumentRespDescription
SEND_OP_CONDbcr[31:0] OCR without busyR3Asks Device, in idle state, to send its Operating Conditions Register contents in the response on the CMD line.

CMD2

Abbr.TypeArgumentRespDescription
ALL_SEND_CIDbcr[31:0] stuff bitsR2Asks Device to send its CID number on the CMD line

CMD3

Abbr.TypeArgumentRespDescription
SET_RELATIVE_ADDRac[31:16] RCA, [15:0] stuff bitsR1Assigns relative address to the Device

CMD4

Abbr.TypeArgumentRespDescription
SET_DSRbc[31:16] DSR, [15:0] stuff bits-Programs the DSR of the Device

CMD5

Abbr.TypeArgumentRespDescription
SLEEP_AWAKEac[31:16] RCA, [15]Sleep/Awake, [14:0] stuff bitsR1bToggles the Device between Sleep state and Standby state.

CMD6

Abbr.TypeArgumentRespDescription
SWITCHac[31:26] Set to 0, [25:24] Access, [23:16] Index, [15:8] Value, [7:3] Set to 0, [2:0] Cmd SetR1bSwitches the mode of operation of the selected Device or modifies the EXT_CSD registers.

CMD7

Abbr.TypeArgumentRespDescription
SELECT/DESELECT_CARDac[31:16] RCA, [15:0] stuff bitsR1/R1bCommand toggles a device between the standby and transfer states or between the programming and disconnect states.

CMD8

Abbr.TypeArgumentRespDescription
SEND_EXT_CSDadtc[31:0] stuff bitsR1Device sends its EXT_CSD register as a block of data.

CMD9

Abbr.TypeArgumentRespDescription
SEND_CSDac[31:16] RCA, [15:0] stuff bitsR2Addressed Device sends its Device-pecific data (CSD) on the CMD line.

CMD10

Abbr.TypeArgumentRespDescription
SEND_CIDac[31:16] RCA, [15:0] stuff bitsR2Addressed Device sends its Device identification (CID) on CMD the line.

CMD12

Abbr.TypeArgumentRespDescription
STOP_TRANSMISSIONac[31:16] RCA, [15:1] stuff bits, [0] HPIR1/R1bForces the Device to stop transmission. If HPI flag is set the device shall interrupt its internal operations in a well-defined timing.

CMD13

Abbr.TypeArgumentRespDescription
SEND_STATUSac[31:16] RCA, [15] SQS, [14:1] stuff bits, [0] HPIR1In case SQS bit = 0: Addressed Device sends its status register. If HPI flag is set the device shall interrupt its internal operations in a well-defined timing. In case SQS bit = 1: indicate that this is a QSR query. In response device shall send the QSR (Queue Status Register). In this case HPI must be set to ‘0’

CMD14

Abbr.TypeArgumentRespDescription
BUSTEST_Radtc[31:0] stuff bitsR1A host reads the reversed bus testing data pattern from a Device.

CMD15

Abbr.TypeArgumentRespDescription
GO_INACTIVE_STATEac[31:16] RCA, [15:0] stuff bits-Sets the Device to inactive state

CMD19

Abbr.TypeArgumentRespDescription
BUSTEST_Wadtc[31:0] stuff bitsR1A host sends the bus test data pattern to a Device

NOTE 1 - CMD7, R1 while selecting from Stand-By State to Transfer State; R1b while selecting from Disconnected State to Programming State.
NOTE 2 - CMD12, RCA in CMD12 is used only if HPI bit is set. The argument does not imply any RCA check on the device side.
NOTE 3 - CMD12, R1 for read cases and R1b for write cases.

Block-oriented read commands (class 2)

CMD16

Abbr.TypeArgumentRespDescription
SET_BLOCKLENac[31:0] block lengthR1Sets the block length (in bytes) for all following block commands (read and write). Default block length is specified in the CSD

CMD17

Abbr.TypeArgumentRespDescription
READ_SINGLE_BLOCKadtc[31:0] data addressR1Reads a block of the size selected by the SET_BLOCKLEN command

CMD18

Abbr.TypeArgumentRespDescription
READ_MULTIPLE_BLOCKadtc[31:0] data addressR1Continuously transfers data blocks from Device to host until interrupted by a stop command, or the requested number of data blocks is transmitted If sent as part of a packed read command, the argument shall contain the first read data address in the pack (address of first individual read command inside the pack).

CMD21

Abbr.TypeArgumentRespDescription
SEND_TUNING_BLOCKadtc[31:0] stuff bitsR1128 clocks of tuning pattern (64 byte in 4bit mode or 128 byte in 8 bit mode) is sent for HS200 optimal sampling point detection.

NOTE 1 - CMD17 & CMD18, Data address for media =<2 32="" gb="" is="" a="" bit="" byte="" address="" and="" data="" for="" media=""> 2GB is a 32 bit sector (512 B) address.
NOTE 2 - CMD17, The transferred data must not cross a physical block boundary, unless READ_BLK_MISALIGN is set in the CSD register.

Block-oriented write commands (class 4)

CMD23 (default)

Abbr.TypeArgumentRespDescription
SET_BLOCK_COUNTac[31] Reliable Write Request, [30] ‘0’ non- packed, [29] tag request,[28:25] context ID, [24]: forced programming, [23:16] set to 0, [15:0] number of blocksR1Defines the number of blocks (read/write) and the reliable writer parameter (write) for a block read or write command.

CMD23 (packed)

Abbr.TypeArgumentRespDescription
SET_BLOCK_COUNTac[31] set to 0, [30] ‘1’ packed, [29:16] set to 0, [15:0] number of blocksR1Defines the number of blocks (read/write) for the following packed write command or for the header of the following packed read command.

CMD24

Abbr.TypeArgumentRespDescription
WRITE_BLOCKadtc[31:0] data addressR1Writes a block of the size selected by the

SET_BLOCKLEN command. |

CMD25

Abbr.TypeArgumentRespDescription
WRITE_MULTIPLE_BLOCKadtc[31:0] data addressR1Continuously writes blocks of data until a STOP_TRANSMISSION follows or the requested number of block received. If sent as a packed command (either packed write, or the header of packed read) the argument shall contain

the first read/write data address in the pack (address of first individual command inside the pack). |

CMD26

Abbr.TypeArgumentRespDescription
PROGRAM_CIDadtc[31:0] stuff bitsR1Programming of the Device identification register. This command shall be issued only once. The Device contains hardware to prevent this operation after the first programming. Normally this command is reserved for the manufacturer.

CMD27

Abbr.TypeArgumentRespDescription
PROGRAM_CSDadtc[31:0] stuff bitsR1Programming of the programmable bits of the CSD.

CMD49

Abbr.TypeArgumentRespDescription
SET_TIMEadtc[31:0] stuff bitsR1Sets the real time clock according to the RTC information in the 512 B data block.

NOTE 1 - CMD24 & CMD25, Data address for media =<2 32="" gb="" is="" a="" bit="" byte="" address="" and="" data="" for="" media=""> 2GB is a 32 bit sector (512 B) address.
NOTE 2 - CMD24, The transferred data must not cross a physical block boundary, unless READ_BLK_MISALIGN is set in the CSD register.

Block-oriented write protection commands (class 6)

Erase commands (class 5)

I/O mode commands (class 9)

Lock Device commands (class 7)

Application-specific commands (class 8)

Security Protocols (class 10)

Command Queue (Class 11)

本部分你转载自 

eMMC Commands_子曰小玖的博客-CSDN博客


参考

[1] https://www.cnblogs.com/smartjourneys/p/6657397.html

免责声明

本文根据公开信息整理,旨在介绍更多的存储知识,所载文章仅为作者观点,不构成投资或商用建议。本文仅用于学习交流, 不允许商用。若有疑问或有侵权行为请联系作者处理。


http://www.ppmy.cn/news/559474.html

相关文章

SparkSQL之AstBuilder

Spark SQL是基于ANTLR实现的&#xff0c;前文中有关于ANTLR的介绍文章《ANTLR实战》和《设计模式之访问者模式》&#xff0c;这篇文章主要介绍的内容是AstBuilder类。 Catalyst中提供了直接面向用户的ParseInterface接口&#xff0c;该接口中包含了对SQL语句、Expression表达式…

弱口令检测 -- WebCrack v(1.1)

要买东西的时候&#xff0c;店家常常说&#xff0c;你要是真心买的&#xff0c;还能给你便宜&#xff0c;你看真心就是不怎么值钱。。。 ---- 网易云热评 一、工具简介 WebCrack是一款web后台弱口令/万能密码批量检测工具&#xff0c;在工具中导入后台地址即可进行自动化检…

WEB安全工具-curl

官网&#xff1a;https://curl.se/ Usage: curl [options...] <url>-d, --data <data> HTTP POST data-f, --fail Fail silently (no output at all) on HTTP errors-h, --help <category> Get help for commands-i, --include Include pro…

web cracker

最新是4.0 Web Cracker v2.0 Final Copyright 1998 by DiTTo Released 12/02/98 This program MAY NOT BE SOLD!IMPORTANT: Please see the end of this document for Version History and Recent Changes! HOMEPAGE & EMAIL:Visit the Web Cracker Home Page at http://we…

crawler

1 网络爬虫 网络爬虫&#xff08;Web crawler&#xff09;&#xff0c;是一种按照一定的规则&#xff0c;自动地抓取万维网信息的程序或者脚本。 1.1 爬虫入门程序 1.1.1 环境准备 1.JDK1.8 2.IntelliJ IDEA 2.IDEA自带的Maven 1.打开IDEA如图所示的界面&#xff0c;选择Pr…

WebBrowser

WebBrowser控件属性&#xff1a; 1、Application 如果该对象有效&#xff0c;则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDispatch)。如果在宿主对象中自动化对象无效&#xff0c;程序将返回WebBrowser控件的自动化对象 2、Parent 返回WebBrowser控件的…

c++ auto学习笔记

一、auto的意义 在C11中赋予auto的意义是&#xff1a;在声明变量时&#xff0c;根据初始化表达式自动推断该变量的类型。声明函数时作为函数返回值的占位符&#xff08;用在函数返回类型后置的情况&#xff09;。 如 auto i 6; //auto推断为intauto func()->int //函数返…

WebCrack:一键自动化日站工具 ——yzddMr6

前言 当初日学校内网的时候有很多后台&#xff0c;就想着能不能批量检测一下弱口令 但是学校的后台系统种类很多&#xff0c;asp aspx php jsp 等等 因为单个网站的爆破比较好整&#xff0c;直接上burp或者py脚本或者hydra 好像还没有听说过批量工具 想着找一找有没有现成…