简介
主要研究下emmc中的UDA分区的enhance的用法,用的emmc芯片是三星的,芯片datasheet在参考链接有。
区域属性
emmc 标准中,支持为UDA 中一个特定大小的区域设定 Enhanced的属性。Enhanced attribute 的具体作用,由芯片制造商定义。
对于UDA分区来说,Enhanced attribute就是指Enhanced storage media。把UDA的某个区域设置为Enhanced storage media的
属性后,一般是把该区域的存储介质从 MLC 改变为 SLC,以获得更好的性能和健壮性。
未enhance前卡的基本信息
测试的卡的基本信息如下,uboot下读取extCSD寄存器的值

U-Boot> mmc reg read extcsd all
EXT_CSD:
000: 00 00 00 00 00 00 00 00 00 00
010: 00 00 00 00 00 00 39 00 00 00
020: 00 00 00 00 00 00 00 00 00 00
030: 00 00 00 00 00 00 00 00 00 00
040: 00 00 00 00 00 00 00 00 00 00
050: 00 00 00 00 00 00 00 00 00 00
060: 00 00 00 00 0f 00 00 c8 c8 00
070: 00 00 00 00 00 00 00 00 00 00
080: 00 00 00 00 00 01 00 00 00 00
090: 00 00 00 00 00 00 00 00 00 00
100: 00 05 00 00 00 00 00 00 00 00
110: 00 00 00 00 00 00 00 00 00 00
120: 00 00 00 00 00 00 00 00 00 00
130: 01 00 00 00 00 00 00 00 00 00
140: 00 00 00 00 00 00 00 00 00 00
150: 00 00 00 00 00 00 00 d2 01 00
160: 07 00 01 00 00 00 14 1f 04 00
170: 00 00 00 00 00 00 00 02 00 08
180: 00 00 00 00 01 01 00 00 00 00
190: 00 00 08 00 02 00 57 1f 0a 02
200: 00 00 00 00 00 00 00 00 00 00
210: 00 01 00 00 e9 00 07 11 00 07
220: 07 10 01 01 01 07 20 00 07 11
230: 1b 55 02 00 00 00 00 00 00 00
240: 00 1e 00 00 00 00 00 3c 0a 00
250: 00 01 00 00 06 00 00 00 00 00
260: 00 00 00 00 01 08 00 01 01 01
270: 00 00 00 00 00 00 00 00 00 00
280: 00 00 00 00 00 00 00 00 00 00
290: 00 00 00 00 00 00 00 00 00 00
300: 00 00 00 00 00 00 00 0f 01 00
310: 00 00 00 00 00 00 00 00 00 00
320: 00 00 00 00 00 00 00 00 00 00
330: 00 00 00 00 00 00 00 00 00 00
340: 00 00 00 00 00 00 00 00 00 00
350: 00 00 00 00 00 00 00 00 00 00
360: 00 00 00 00 00 00 00 00 00 00
370: 00 00 00 00 00 00 00 00 00 00
380: 00 00 00 00 00 00 00 00 00 00
390: 00 00 00 00 00 00 00 00 00 00
400: 00 00 00 00 00 00 00 00 00 00
410: 00 00 00 00 00 00 00 00 00 00
420: 00 00 00 00 00 00 00 00 00 00
430: 00 00 00 00 00 00 00 00 00 00
440: 00 00 00 00 00 00 00 00 00 00
450: 00 00 00 00 00 00 00 00 00 00
460: 00 00 00 00 00 00 00 00 00 00
470: 00 00 00 00 00 00 00 00 00 00
480: 00 00 00 00 00 00 00 00 00 81
490: c7 00 00 03 03 07 05 00 02 01
500: 3f 3f 01 01 01 00 00 00 00 00
510: 00 00
U-Boot>
容量信息,总的UDA分区为7634944KB


kernel下使用mmc-utils工具得到的信息
# mmc extcsd read /dev/mmcblk0
=============================================
Extended CSD rev 1.8 (MMC 5.1)
=============================================
Card Supported Command sets [S_CMD_SET: 0x01]
HPI Features [HPI_FEATURE: 0x01]: implementation based on CMD13
Background operations support [BKOPS_SUPPORT: 0x01]
Max Packet Read Cmd [MAX_PACKED_READS: 0x3f]
Max Packet Write Cmd [MAX_PACKED_WRITES: 0x3f]
Data TAG support [DATA_TAG_SUPPORT: 0x01]
Data TAG Unit Size [TAG_UNIT_SIZE: 0x02]
Tag Resources Size [TAG_RES_SIZE: 0x00]
Context Management Capabilities [CONTEXT_CAPABILITIES: 0x05]
Large Unit Size [LARGE_UNIT_SIZE_M1: 0x07]
Extended partition attribute support [EXT_SUPPORT: 0x03]
Generic CMD6 Timer [GENERIC_CMD6_TIME: 0x0a]
Power off notification [POWER_OFF_LONG_TIME: 0x3c]
Cache Size [CACHE_SIZE] is 8192 KiB
Background operations status [BKOPS_STATUS: 0x00]
1st Initialisation Time after programmed sector [INI_TIMEOUT_AP: 0x1e]
Power class for 52MHz, DDR at 3.6V [PWR_CL_DDR_52_360: 0x00]
Power class for 52MHz, DDR at 1.95V [PWR_CL_DDR_52_195: 0x00]
Power class for 200MHz at 3.6V [PWR_CL_200_360: 0x00]
Power class for 200MHz, at 1.95V [PWR_CL_200_195: 0x00]
Minimum Performance for 8bit at 52MHz in DDR mode:
[MIN_PERF_DDR_W_8_52: 0x00]
[MIN_PERF_DDR_R_8_52: 0x00]
TRIM Multiplier [TRIM_MULT: 0x02]
Secure Feature support [SEC_FEATURE_SUPPORT: 0x55]
Boot Information [BOOT_INFO: 0x07]
Device supports alternative boot method
Device supports dual data rate during boot
Device supports high speed timing during boot
Boot partition size [BOOT_SIZE_MULTI: 0x20]
Access size [ACC_SIZE: 0x07]
High-capacity erase unit size [HC_ERASE_GRP_SIZE: 0x01]
i.e. 512 KiB
High-capacity erase timeout [ERASE_TIMEOUT_MULT: 0x01]
Reliable write sector count [REL_WR_SEC_C: 0x01]
High-capacity W protect group size [HC_WP_GRP_SIZE: 0x10]
i.e. 8192 KiB
Sleep current (VCC) [S_C_VCC: 0x07]
Sleep current (VCCQ) [S_C_VCCQ: 0x07]
Sleep/awake timeout [S_A_TIMEOUT: 0x11]
Sector Count [SEC_COUNT: 0x00e90000]
Device is block-addressed
Minimum Write Performance for 8bit:
[MIN_PERF_W_8_52: 0x00]
[MIN_PERF_R_8_52: 0x00]
[MIN_PERF_W_8_26_4_52: 0x00]
[MIN_PERF_R_8_26_4_52: 0x00]
Minimum Write Performance for 4bit:
[MIN_PERF_W_4_26: 0x00]
[MIN_PERF_R_4_26: 0x00]
Power classes registers:
[PWR_CL_26_360: 0x00]
[PWR_CL_52_360: 0x00]
[PWR_CL_26_195: 0x00]
[PWR_CL_52_195: 0x00]
Partition switching timing [PARTITION_SWITCH_TIME: 0x02]
Out-of-interrupt busy timing [OUT_OF_INTERRUPT_TIME: 0x0a]
I/O Driver Strength [DRIVER_STRENGTH: 0x1f]
Card Type [CARD_TYPE: 0x57]
HS400 Dual Data Rate eMMC @200MHz 1.8VI/O
HS200 Single Data Rate eMMC @200MHz 1.8VI/O
HS Dual Data Rate eMMC @52MHz 1.8V or 3VI/O
HS eMMC @52MHz - at rated device voltage(s)
HS eMMC @26MHz - at rated device voltage(s)
CSD structure version [CSD_STRUCTURE: 0x02]
Command set [CMD_SET: 0x00]
Command set revision [CMD_SET_REV: 0x00]
Power class [POWER_CLASS: 0x00]
High-speed interface timing [HS_TIMING: 0x01]
Enhanced Strobe mode [STROBE_SUPPORT: 0x01]
Erased memory content [ERASED_MEM_CONT: 0x00]
Boot configuration bytes [PARTITION_CONFIG: 0x08]
Boot Partition 1 enabled
No access to boot partition
Boot config protection [BOOT_CONFIG_PROT: 0x00]
Boot bus Conditions [BOOT_BUS_CONDITIONS: 0x02]
High-density erase group definition [ERASE_GROUP_DEF: 0x01]
Boot write protection status registers [BOOT_WP_STATUS]: 0x00
Boot Area Write protection [BOOT_WP]: 0x00
Power ro locking: possible
Permanent ro locking: possible
partition 0 ro lock status: not locked
partition 1 ro lock status: not locked
User area write protection register [USER_WP]: 0x00
FW configuration [FW_CONFIG]: 0x00
RPMB Size [RPMB_SIZE_MULT]: 0x04
Write reliability setting register [WR_REL_SET]: 0x1f
user area: the device protects existing data if a power failure occurs during a write operation
partition 1: the device protects existing data if a power failure occurs during a write operation
partition 2: the device protects existing data if a power failure occurs during a write operation
partition 3: the device protects existing data if a power failure occurs during a write operation
partition 4: the device protects existing data if a power failure occurs during a write operation
Write reliability parameter register [WR_REL_PARAM]: 0x14
Device supports the enhanced def. of reliable write
Enable background operations handshake [BKOPS_EN]: 0x00
H/W reset function [RST_N_FUNCTION]: 0x01
HPI management [HPI_MGMT]: 0x01
Partitioning Support [PARTITIONING_SUPPORT]: 0x07
Device support partitioning feature
Device can have enhanced tech.
Max Enhanced Area Size [MAX_ENH_SIZE_MULT]: 0x0001d2
i.e. 3817472 KiB
Partitions attribute [PARTITIONS_ATTRIBUTE]: 0x00
Partitioning Setting [PARTITION_SETTING_COMPLETED]: 0x00
Device partition setting NOT complete
General Purpose Partition Size
[GP_SIZE_MULT_4]: 0x000000
[GP_SIZE_MULT_3]: 0x000000
[GP_SIZE_MULT_2]: 0x000000
[GP_SIZE_MULT_1]: 0x000000
Enhanced User Data Area Size [ENH_SIZE_MULT]: 0x000000
i.e. 0 KiB
Enhanced User Data Start Address [ENH_START_ADDR]: 0x00000000
i.e. 0 bytes offset
Bad Block Management mode [SEC_BAD_BLK_MGMNT]: 0x00
Periodic Wake-up [PERIODIC_WAKEUP]: 0x00
Program CID/CSD in DDR mode support [PROGRAM_CID_CSD_DDR_SUPPORT]: 0x01
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[127]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[126]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[125]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[124]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[123]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[122]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[121]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[120]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[119]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[118]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[117]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[116]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[115]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[114]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[113]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[112]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[111]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[110]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[109]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[108]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[107]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[106]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[105]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[104]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[103]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[102]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[101]]: 0x05
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[100]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[99]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[98]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[97]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[96]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[95]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[94]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[93]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[92]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[91]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[90]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[89]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[88]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[87]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[86]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[85]]: 0x01
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[84]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[83]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[82]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[81]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[80]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[79]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[78]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[77]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[76]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[75]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[74]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[73]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[72]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[71]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[70]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[69]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[68]]: 0xc8
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[67]]: 0xc8
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[66]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[65]]: 0x00
Vendor Specific Fields [VENDOR_SPECIFIC_FIELD[64]]: 0x0f
Native sector size [NATIVE_SECTOR_SIZE]: 0x00
Sector size emulation [USE_NATIVE_SECTOR]: 0x00
Sector size [DATA_SECTOR_SIZE]: 0x00
1st initialization after disabling sector size emulation [INI_TIMEOUT_EMU]: 0x00
Class 6 commands control [CLASS_6_CTRL]: 0x00
Number of addressed group to be Released[DYNCAP_NEEDED]: 0x00
Exception events control [EXCEPTION_EVENTS_CTRL]: 0x0000
Exception events status[EXCEPTION_EVENTS_STATUS]: 0x0000
Extended Partitions Attribute [EXT_PARTITIONS_ATTRIBUTE]: 0x0000
Context configuration [CONTEXT_CONF[51]]: 0x00
Context configuration [CONTEXT_CONF[50]]: 0x00
Context configuration [CONTEXT_CONF[49]]: 0x00
Context configuration [CONTEXT_CONF[48]]: 0x00
Context configuration [CONTEXT_CONF[47]]: 0x00
Context configuration [CONTEXT_CONF[46]]: 0x00
Context configuration [CONTEXT_CONF[45]]: 0x00
Context configuration [CONTEXT_CONF[44]]: 0x00
Context configuration [CONTEXT_CONF[43]]: 0x00
Context configuration [CONTEXT_CONF[42]]: 0x00
Context configuration [CONTEXT_CONF[41]]: 0x00
Context configuration [CONTEXT_CONF[40]]: 0x00
Context configuration [CONTEXT_CONF[39]]: 0x00
Context configuration [CONTEXT_CONF[38]]: 0x00
Context configuration [CONTEXT_CONF[37]]: 0x00
Packed command status [PACKED_COMMAND_STATUS]: 0x00
Packed command failure index [PACKED_FAILURE_INDEX]: 0x00
Power Off Notification [POWER_OFF_NOTIFICATION]: 0x01
Control to turn the Cache ON/OFF [CACHE_CTRL]: 0x01
Control to turn the Cache Barrier ON/OFF [BARRIER_CTRL]: 0x00
eMMC Firmware Version:
eMMC Life Time Estimation A [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]: 0x01
eMMC Life Time Estimation B [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B]: 0x01
eMMC Pre EOL information [EXT_CSD_PRE_EOL_INFO]: 0x01
Secure Removal Type [SECURE_REMOVAL_TYPE]: 0x39
information is configured to be removed using a vendor defined
Supported Secure Removal Type:
information removed by an erase of the physical memory
information removed using a vendor defined
Command Queue Support [CMDQ_SUPPORT]: 0x01
Command Queue Depth [CMDQ_DEPTH]: 16
Command Enabled [CMDQ_MODE_EN]: 0x00
Note: CMDQ_MODE_EN may not indicate the runtime CMDQ ON or OFF.
Please check sysfs node '/sys/devices/.../mmc_host/mmcX/mmcX:XXXX/cmdq_en'
#

写4G数据量的速度平均值为42.74MB/s
time dd if=/dev/zero of=/dev/mmcblk0 bs=1M count=4000

读4G数据量的速度平均值为45.23MB/s
time dd if=/dev/mmcblk0 of=/dev/null bs=1M count=4000

enhance相关寄存器介绍
主要有四个寄存器

Max Enhanced Area Size
定义最大能enhance的大小,公式为
Max Enhanced Area = MAX_ENH_SIZE_MULT x HC_WP_GRP_SIZE x HC_ERASE_GRP_SIZE x 512kBytes
这个最大的能enhance的大小,指的是GPP分区跟UDA分区一起能enhance的大小

这里的MAX_ENH_SIZE_MULT为0x1d2,带入上面的公式算出来就是3817472KB

Enhanced User Data Area Size
这个寄存器是表示已经enhance的UDA分区的大小,当然如果还没enhance的话肯定是0,enhance后该寄存器的值会反映enhance后的UDA分区的大小

Enhanced User Data Start Address
配置要从UDA分区的哪个偏移地址开始进行enhance,寄存器的值单位是512byte,也即当该寄存器的值为1时,表示偏移为512byte

Partitions atrribute
如果要进行UDA分区的enhance,则需要设置此寄存器的bit0,当然kernel下的mmc-utils工具会帮你设置好的

enhance测试
准备工作
先拷贝一个文件到UDA分区的offset为0x2000 blk处,这样就可以对比enhance前后,UDA分区中数据的变化,0x2000 blk也即4096KB
以python3.11这个文件为例

如图所示,我们的文件已写入0x2000 blk偏移处

将相关的寄存器值内容打印出来
mmc extcsd read /dev/mmcblk0 | grep MAX_ENH_SIZE_MULT -A 1
mmc extcsd read /dev/mmcblk0 | grep ENH_SIZE_MULT -A 1
mmc extcsd read /dev/mmcblk0 | grep ENH_START_ADDR -A 1
mmc extcsd read /dev/mmcblk0 | grep PARTITIONS -A 1

预设
因为enhance操作是一次性编程的操作,配了一次UDA的enhance后就不能再配了,所以mmc-utils中的mmc enh_area set有预先设置命令,相当于一种预告,注意使用参数-n
其参数用法为
mmc enh_area set <-y|-n|-c> <start KiB> <length KiB> <device>
start KiB:我们这里假如配置为4096,代表开始enhance的区域的偏移量,4096KB反映到前面提到的Enhanced User Data Start Address寄存器,则会是0x2000
# mmc enh_area set -n 4096 81920 /dev/mmcblk0
# mmc extcsd read /dev/mmcblk0 | grep ENH_START_ADDR -A 1
# mmc extcsd read /dev/mmcblk0 | grep PARTITIONS -A 1
# mmc extcsd read /dev/mmcblk0 | grep ENH_SIZE_MULT -A 1
这里我们配置了一下,开始的偏移为4096KB,enhance的大小为81920KB,可以看到预设后的extcsd寄存器的相关变化

实操
上一步中的-n参数是一种预设值,只是让你看到设置后得到的预期结果,并没有实际生效,下电后就没有了。而-y参数则是真正生效的操作,配置后下电重启即可生效,这一步操作是不可撤销的,注意。
mmc enh_area set -y 4096 81920 /dev/mmcblk0

enhance后卡的信息
下电后再上电,可以看到我们的容量变小了 ,也即enhance生效了


不过本来想对比是不是4096KB处的数据被清掉了,结果发现好像UDA分区全部都被清零了


现在查看enhance相关寄存器的信息
mmc extcsd read /dev/mmcblk0 | grep ENH_START_ADDR -A 1
mmc extcsd read /dev/mmcblk0 | grep PARTITIONS -A 1
mmc extcsd read /dev/mmcblk0 | grep ENH_SIZE_MULT -A 1

速度上,好像没体现出来从MLC变成SLC之后变快的特性,也有可能是因为我只enhance了80MB的原因?不够大,体现不出来


因为UDA的enhance的大小是一次性编程的,这时候如果再去设置一次,就会提示已经enhance过了
mmc enh_area set -n 102400 102400 /dev/mmcblk0

参考链接
后续
下次介绍GPP分区的创建,也是跟这个enhance有关