eMMC启动uboot

本文详细介绍了eMMC的分区结构,包括引导分区、重发保护存储器块及通用分区的功能与用途。同时,提供了在Linux环境下读写eMMC分区的方法,以及如何通过修改EXT_CSD寄存器配置来选择不同的启动分区。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

<think>好的,我现在需要帮助用户了解如何配置Zynq从eMMC启动。根据用户提供的引用内容,特别是引用[3],其中提到了在ZYNQ开发中使用eMMC固化程序的方法,适用于需要高稳定性或量产的设备。我需要结合这些信息,给出一个结构清晰的步骤教程。 首先,我应该明确用户的需求。用户可能是在进行嵌入式系统开发,特别是使用Xilinx的Zynq系列芯片,想要将系统或应用程序固化到eMMC存储中,以便设备能够从eMMC启动。这可能涉及到Uboot的配置、镜像文件的生成以及启动参数的设置。 接下来,我需要回忆Zynq启动流程的基本知识。Zynq的启动过程通常分为多个阶段:首先是BootROM,然后是FSBL(First Stage Boot Loader),接着可能由SSBL(如U-Boot)接管,最后加载Linux内核或应用程序。从eMMC启动的话,需要确保启动镜像正确写入eMMC,并且Uboot的环境变量正确指向eMMC中的位置。 根据引用[2],用户提到了修改Uboot启动参数,这可能涉及到设置bootcmd和bootargs,例如指定根文件系统在eMMC中的位置。引用[3]提到了eMMC固化的步骤,可能需要生成BOOT.BIN和镜像文件,并通过工具将其写入eMMC。 现在,我需要将这些信息整理成步骤。首先,生成启动镜像,包括FSBL、比特流和U-Boot。然后,准备根文件系统,可能使用tar解压到某个目录,如引用[2]中的命令。接着,使用dd命令或专用工具将镜像写入eMMC的分区。之后,配置Uboot的环境变量,设置正确的启动命令和参数,确保从eMMC加载内核和根文件系统。最后,测试启动过程。 需要注意的是,用户可能不熟悉如何具体操作这些步骤,比如如何生成BOOT.BIN,如何确定eMMC的设备节点,如何正确分区和格式化eMMC。因此,步骤中需要详细说明这些关键点,可能涉及使用Xilinx的Vivado和Petalinux工具链,以及Linux下的命令如mkfs和dd。 同时,用户提供的引用[1]提到了分区信息,如“Device Boot Start End Blocks Id System”,这可能涉及eMMC的分区布局,需要确保启动分区和根文件系统分区的正确划分。例如,第一个分区可能用于存放BOOT.BIN和镜像,而第二个分区用于根文件系统。 在编写步骤时,要确保逻辑清晰,每个步骤都有明确的目的和操作命令。例如,生成启动镜像可能需要使用Petalinux的构建命令,配置Uboot参数可能涉及修改环境变量或设备树。此外,要提醒用户注意备份数据,因为写入eMMC可能会覆盖原有内容。 可能遇到的问题包括eMMC设备识别不正确、镜像文件路径错误、Uboot参数设置不当等。需要给出一些常见问题的解决方法,或者建议查阅相关文档。 最后,生成相关问题,可能涉及如何验证启动配置、如何优化eMMC的读写速度、在量产中如何批量固化等。</think>### 如何配置Zynq从eMMC启动 以下是配置Zynq从eMMC启动的详细步骤: --- #### **1. 生成启动镜像(BOOT.BIN)** - **步骤说明**:使用Xilinx工具链(Vivado/PetaLinux)生成包含FSBL(First Stage Boot Loader)、硬件比特流(Bitstream)和U-Boot的镜像文件。 - **操作命令**(PetaLinux环境): ```bash petalinux-package --boot --fsbl <fsbl.elf> --fpga <system.bit> --u-boot --force ``` 生成的`BOOT.BIN`将保存在`images/linux/`目录下[^3]。 --- #### **2. 准备根文件系统(RootFS)** - **步骤说明**:将根文件系统打包为`rootfs.tar.gz`,并通过命令解压到目标目录。 - **操作示例**: ```bash tar -xzvf /xxx/images/linux/rootfs.tar.gz -C /xxx/nfs/rootfs/ [^2] ``` 确保文件系统包含Linux内核(`Image`)和设备树(`system.dtb`)。 --- #### **3. 将镜像写入eMMC** - **分区要求**:通常将eMMC分为两个区: - **分区1(FAT32)**:存放`BOOT.BIN`、`Image`、`system.dtb`。 - **分区2(EXT4)**:存放根文件系统。 - **操作命令**(Linux主机): ```bash sudo dd if=BOOT.BIN of=/dev/mmcblk0p1 # 将BOOT.BIN写入eMMC启动分区 sudo mkfs.ext4 /dev/mmcblk0p2 # 格式化根文件系统分区 sudo cp -r rootfs/* /mnt/mmcblk0p2/ # 复制根文件系统 ``` --- #### **4. 配置U-Boot启动参数** - **关键变量**:在U-Boot中设置`bootcmd`和`bootargs`,指定从eMMC加载内核和根文件系统。 - **示例配置**: ```bash setenv bootcmd 'mmc dev 0; fatload mmc 0 0x8000 Image; fatload mmc 0 0x1000 system.dtb; booti 0x8000 - 0x1000' setenv bootargs 'root=/dev/mmcblk0p2 rw rootwait earlyprintk' saveenv ``` 其中`mmc dev 0`选择eMMC设备。 --- #### **5. 固化验证** - **操作步骤**:重启Zynq设备,观察U-Boot日志是否从eMMC加载镜像,并确认Linux成功挂载根文件系统。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值