分享

eMMC启动uboot

 XeonGate 2021-09-17

https://blog.csdn.net/ccwzhu/article/details/103522367

eMMC分区介绍

分区     名称     描述
0x0     No access to boot partition(default)     不可访问分区
0x1     R/W boot partition 1     读写引导分区1
0x2     R/W boot partition 2     读写引导分区2
0x3     R/W Replace Protect Memory Block(RPMB)     读写重发保护存储器块
0x4     Access to General Purpose Partition 1     访问通用分区 1
0x5     Access to General Purpose Partition 2     访问通用分区 2
0x6     Access to General Purpose Partition 3     访问通用分区 3
0x7     Access to General Purpose Partition 4     访问通用分区 4

R/W boot partition 1/2:此分区主要是为了支持从 eMMC 启动系统而设计的。大小为:4MB
RPMB:在实际应用中,RPMB 分区通常用来保存安全相关的数据,例如指纹数据、安全支付相关的密钥等。大小为:512KB-32MB
General Purpose Partition 1/2/3/4:此区域则主要用于存储系统或者用户数据。
User Data Area: 此区域则主要用于存储系统或者用户数据。

emmc的boot分区烧录uboot方式有两种:

一: Linux下读写boot分区

boot分区中一般存放的是bootloader或者相关配置参数,这些参数一般是不允许修改的,所以默认情况下是能读boot分区,不能写。

1 使能读写

如果需要些则需要,修改/sys/block/mmcblk0boot0/force_ro。

使能写:

echo 0 > /sys/block/mmcblk0boot0/force_ro

关闭写:

echo 1 > /sys/block/mmcblk0boot1/force_ro

在重启之后,force_ro会恢复为1。

二: emmc boot启动分区选择

boot配置在EXT_CSD寄存器第179个字节定义,可以设置BOOT_PARTITION_ENABLE位的值来选择从Boot Partition或者User Area分区启动。关于第179字节的定义如下:
179字节定义

设置Boot Partition大小

可知,Boot Partition大小范围为:128KB ~ 31.875MB
大小


当前包含2个mmc设备

uboot>mmc list
FSL_SDHC: 0 (eMMC)
FSL_SDHC: 1

uboot>mmc partconf dev
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x0
PARTITION_ACCESS: 0x0

1: 从上述结果根据EXT_CSD寄存器第179个字节定义,默认emmc是没有设置boot启动分区,如果要从user area启动BOOT_PARTITION_ENABLE的值设置为0x07

uboot>mmc partconf dev 0 0x07  0

uboot>mmc partconf dev
EXT_CSD[179], PARTITION_CONFIG:
BOOT_ACK: 0x0
BOOT_PARTITION_ENABLE: 0x7
PARTITION_ACCESS: 0x0

然后再将uboot下烧录uboot固件,并且CPU的boot mode改成emmc启动,可以从emmc boot
uboot>tftp 0x82000000 u-boot.bin
uboot>mmc write 0x82000000 0 0x800

2: 如果要从boot partition1启动BOOT_PARTITION_ENABLE的值设置为0x01

uboot>mmc partconf dev 0 0x01  0

3: 如果要从boot partition2启动BOOT_PARTITION_ENABLE的值设置为0x02

uboot>mmc partconf dev 0 0x02 0

三:mmc工具的使用

mmc-utils工具是用于在linux下用户层访问mmc设备的工具。其详细用法如下:

Usage:
mmc extcsd read <device>
Print extcsd data from <device>.
mmc writeprotect boot get <device>
Print the boot partitions write protect status for <device>.
mmc writeprotect boot set <device>
Set the boot partitions write protect status for <device>.
This sets the eMMC boot partitions to be write-protected until
the next boot.
mmc writeprotect user set <type><start block><blocks><device>
Set the write protect configuration for the specified region
of the user area for <device>.
<type> must be "none|temp|pwron".
"none"  - Clear temporary write protection.
"temp"  - Set temporary write protection.
"pwron" - Set write protection until the next poweron.
<start block> specifies the first block of the protected area.
<blocks> 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 <device>
Print the user areas write protect configuration for <device>.
mmc disable 512B emulation <device>
Set the eMMC data sector size to 4KB by disabling emulation on
<device>.
mmc gp create <-y|-n|-c> <length KiB> <partition> <enh_attr> <ext_attr> <device>
Create general purpose partition for the <device>.
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
<enh_attr> to 1 else set it to 0.
To set extended attribute to general partition
set <ext_attr> to 1,2 else set it to 0
mmc enh_area set <-y|-n|-c> <start KiB> <length KiB> <device>
Enable the enhanced user area for the <device>.
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> <partition> <device>
Enable write reliability per partition for the <device>.
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 <device>
Print the response to STATUS_SEND (CMD13).
mmc bootpart enable <boot_partition> <send_ack> <device>
Enable the boot partition for the <device>.
Disable the boot partition for the <device> if <boot_partition> is set to 0.
To receive acknowledgment of boot from the card set <send_ack>
to 1, else set it to 0.
mmc bootbus set <boot_mode> <reset_boot_bus_conditions> <boot_bus_width> <device>
Set Boot Bus Conditions.
<boot_mode> must be "single_backward|single_hs|dual"
<reset_boot_bus_conditions> must be "x1|retain"
<boot_bus_width> must be "x1|x4|x8"
mmc bkops enable <device>
Enable the eMMC BKOPS feature on <device>.
NOTE!  This is a one-time programmable (unreversible) change.
mmc hwreset enable <device>
Permanently enable the eMMC H/W Reset feature on <device>.
NOTE!  This is a one-time programmable (unreversible) change.
mmc hwreset disable <device>
Permanently disable the eMMC H/W Reset feature on <device>.
NOTE!  This is a one-time programmable (unreversible) change.
mmc sanitize <device>
Send Sanitize command to the <device>.
This will delete the unmapped memory region of the device.
mmc rpmb write-key <rpmb device> <key file>
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 <rpmb device>
Counter value for the <rpmb device> will be read to stdout.
mmc rpmb read-block <rpmb device> <address> <blocks count> <output file> [key file]
Blocks of 256 bytes will be read from <rpmb device> 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 <rpmb device> <address> <256 byte data file> <key file>
Block of 256 bytes will be written from data file to
<rpmb device>. 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 <device>
Enable the eMMC cache feature on <device>.
NOTE! The cache is an optional feature on devices >= eMMC4.5.
mmc cache disable <device>
Disable the eMMC cache feature on <device>.
NOTE! The cache is an optional feature on devices >= eMMC4.5.
mmc csd read <device path>
Print CSD data from <device path>.
The device path should specify the csd file directory.
mmc cid read <device path>
Print CID data from <device path>.
The device path should specify the cid file directory.
mmc scr read <device path>
Print SCR data from <device path>.
The device path should specify the scr file directory.
mmc ffu <image name> <device>
Run Field Firmware Update with <image name> on <device>.

mmc help|--help|-h
Show the help.

mmc <cmd> --help
Show detailed help for a command or subset of commands.

0.1

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多