全国服务热线:

0416-3905144
当前位置:首页 > 经典案例
经典案例

在Ubuntu系统下使用MMCBLK读写eMMC芯片教程(命令行模式)

浏览: 发布日期:2024/1/29 17:53:19

在Ubuntu系统下使用MMCBLK读写EMMC芯片教程(命令行模式)
首先,您需要安装Ubuntu操作系统才能进行以下操作,为了更方便的使用您可以将系统安装到虚拟机或U盘。
操作系统链接:https://cn.ubuntu.com

命令行模式读写eMMC操作步骤
虚拟机USB兼容性设置:
如果使用的是虚拟机,建议先将USB兼容性设置为USB3.x。

1、查看设备与驱动
在命令行下输入lsusb -t查看树形结构显示USB设备的连接,如果显示Driver=rtsx_usb就可以进行下一步操作,新版Ubuntu操作系统一般是自带此驱动。

2、查看eMMC芯片列出分区
把放好芯片的读写器插入电脑,输入命令ls /dev/mmc*查看eMMC芯片是否正确挂载。如果挂载正常,会在命令下显示/dev/mmcblk0、/dev/mmcblk0boot0、/dev/mmcblk0boot1等分区,它们分别对应eMMC芯片的User、Boot0、Boot1分区。

3、切换系统权限
输入命令sudo su提升权限,这里会要求输入管理员密码,请按要求输入授权即可。
4、禁用只读模式:Disable read-only mode
依次输入以下命令并回车,将默认的只读模式关闭,以便我们接下来可以顺利读取数据和写入数据。
echo 0 > /sys/block/mmcblk0/force_ro
echo 0 > /sys/block/mmcblk0boot0/force_ro
echo 0 > /sys/block/mmcblk0boot1/force_ro

5、读取数据和写入数据
接下来就可以使用Linux下的dd命令进行读写操作,用到的命令解释以下:
sudo 授权普通用户执行管理员命令
dd 复制文件的命令
bs=4M 设置块大小
if= 选择源盘(或文件)的路径
of= 选择目标文件(或目标盘)的路径
status=progress 显示进度状态
5.1、备份数据
备份boot0数据
sudo dd if=/dev/mmcblk0boot0 of=emmc/boot0.bin
备份boot1数据
sudo dd if=/dev/mmcblk0boot1 of=emmc/boot1.bin
备份user数据
sudo dd if=/dev/mmcblk0 of=emmc/user.bin bs=4M status=progress

5.2、写入数据
恢复boot0数据到芯片
sudo dd if=emmc/boot0.bin of=/dev/mmcblk0boot0
恢复boot1数据到芯片
sudo dd if=emmc/boot1.bin of=/dev/mmcblk0boot1
恢复user数据到芯片
sudo dd if=emmc/user.bin of=/dev/mmcblk0 bs=4M status=progress

6、安装mmc-utils
apt install mmc-utils
7、查看Ext_Csd信息:
mmc extcsd read /dev/mmcblk0

获取CID:

cat /sys/block/mmcblk0/device/cid

获取CSD:

cat /sys/block/mmcblk0/device/csd

获取OCR:

cat /sys/block/mmcblk0/device/ocr

获取RCA:

cat /sys/block/mmcblk0/device/rca

获取DSR:

cat /sys/block/mmcblk0/device/dsr

查看eMMC芯片寿命:

sudo mmc extcsd read /dev/mmcblk0 | grep Life

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]: 0x03

从eMMC5.0开始,支持健康度查询,以记录芯片的读写次数换算为寿命信息。数据越靠近0越好,0x01表示0-10%之间,0x0A表示90%-100%之间,0x0B表示寿命已尽。

# cat /sys/block/mmcblk0/device/*

# mmc help

Usage:

mmc extcsd read

Print extcsd data from .

mmc writeprotect boot get

Print the boot partitions write protect status for .

mmc writeprotect boot set

Set the boot partitions write protect status for .

This sets the eMMC boot partitions to be write-protected until

the next boot.

mmc writeprotect user set

Set the write protect configuration for the specified region

of the user area for .

 must be "none|temp|pwron".

    "none"  - Clear temporary write protection.

    "temp"  - Set temporary write protection.

    "pwron" - Set write protection until the next poweron.

 specifies the first block of the protected area.

 specifies the size of the protected area in blocks.

NOTE! The area must start and end on Write Protect Group

boundries, Use the "writeprotect user get" command to get the

Write Protect Group size.

mmc writeprotect user get

Print the user areas write protect configuration for .

mmc disable 512B emulation

Set the eMMC data sector size to 4KB by disabling emulation on

.

mmc gp create <-y|-n|-c>

Create general purpose partition for the .

Dry-run only unless -y or -c is passed.

Use -c if more partitioning settings are still to come.

NOTE!  This is a one-time programmable (unreversible) change.

To set enhanced attribute to general partition being created set

 to 1 else set it to 0.

To set extended attribute to general partition

 set to 1,2 else set it to 0

mmc enh_area set <-y|-n|-c>

Enable the enhanced user area for the .

Dry-run only unless -y or -c is passed.

Use -c if more partitioning settings are still to come.

NOTE!  This is a one-time programmable (unreversible) change.

mmc write_reliability set <-y|-n|-c>

Enable write reliability per partition for the .

Dry-run only unless -y or -c is passed.

Use -c if more partitioning settings are still to come.

NOTE!  This is a one-time programmable (unreversible) change.

mmc status get

Print the response to STATUS_SEND (CMD13).

mmc bootpart enable

Enable the boot partition for the .

Disable the boot partition for the if is set to 0.

To receive acknowledgment of boot from the card set

to 1, else set it to 0.

mmc bootbus set

Set Boot Bus Conditions.

 must be "single_backward|single_hs|dual"

 must be "x1|retain"

 must be "x1|x4|x8"

mmc bkops enable

Enable the eMMC BKOPS feature on .

NOTE!  This is a one-time programmable (unreversible) change.

mmc hwreset enable

Permanently enable the eMMC H/W Reset feature on .

NOTE!  This is a one-time programmable (unreversible) change.

mmc hwreset disable

Permanently disable the eMMC H/W Reset feature on .

NOTE!  This is a one-time programmable (unreversible) change.

mmc sanitize

Send Sanitize command to the .

This will delete the unmapped memory region of the device.

mmc rpmb write-key

Program authentication key which is 32 bytes length and stored

in the specified file. Also you can specify '-' instead of

key file path to read the key from stdin.

NOTE!  This is a one-time programmable (unreversible) change.

Example:

  $ echo -n AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH | \

    mmc rpmb write-key /dev/mmcblk0rpmb -

mmc rpmb read-counter

Counter value for the will be read to stdout.

mmc rpmb read-block

[key file]


Blocks of 256 bytes will be read from to output

file or stdout if '-' is specified. If key is specified - read

data will be verified. Instead of regular path you can specify

'-' to read key from stdin.

Example:

  $ echo -n AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH | \

    mmc rpmb read-block /dev/mmcblk0rpmb 0x02 2 /tmp/block -

or read two blocks without verification

  $ mmc rpmb read-block /dev/mmcblk0rpmb 0x02 2 /tmp/block

mmc rpmb write-block

<256 byte data file>


Block of 256 bytes will be written from data file to

. Also you can specify '-' instead of key

file path or data file to read the data from stdin.

Example:

  $ (awk 'BEGIN {while (c++<256) printf "a"}' | \

    echo -n AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH) | \

    mmc rpmb write-block /dev/mmcblk0rpmb 0x02 - -

mmc cache enable

Enable the eMMC cache feature on .

NOTE! The cache is an optional feature on devices >= eMMC4.5.

mmc cache disable

Disable the eMMC cache feature on .

NOTE! The cache is an optional feature on devices >= eMMC4.5.

mmc csd read

Print CSD data from .

The device path should specify the csd file directory.

mmc cid read

Print CID data from .

The device path should specify the cid file directory.

mmc scr read

Print SCR data from .

The device path should specify the scr file directory.

mmc ffu 

Run Field Firmware Update with  on .

mmc help|--help|-h

Show the help.

mmc --help

Show detailed help for a command or subset of commands.

0.1


版权所有©2014-2023 锦州辰硕家电维修中心 技术支持:13840665804 电话:0416-3905144 地址:锦州市古塔区中央大街26号
ICP备案/许可证号:辽ICP备2023002984号-2