如何使用 Uboot 从 EMMC 的通用分区或引导分区加载文件

如何使用 Uboot 从 EMMC 的通用分区或引导分区加载文件

UBoot 是否能够通过 fatload/ext4load 从 EMMC 的通用分区或引导分区引导?我能够显示用户区域中的文件,但不能显示作为硬件分区创建的分区。这些分区可以使用 UBoot 的“mmc hwpartition”命令创建。奇怪的是 UBoot 可以创建这些分区,但似乎无法使用它们。我使用的是最新版本(2016.4)赛灵思的 UBoot,这是基于启动系统

使用UBoot的“mmc info”命令,UBoot绝对可以看到引导分区和通用分区(GP 1/2/3/4):

zynq-uboot> mmc info
Device: sdhci@e0100000
Manufacturer ID: fe
OEM: 14e
Name: MMC04
Tran Speed: 52000000
Rd Block Len: 512
MMC version 4.4.1
High Capacity: Yes
Capacity: 2.7 GiB
Bus Width: 4-bit
Erase Group Size: 4 MiB
HC WP Group Size: 4 MiB
User Capacity: 2.7 GiB
Boot Capacity: 16 MiB ENH
RPMB Capacity: 128 KiB ENH
GP1 Capacity: 128 MiB
GP2 Capacity: 64 MiB
GP3 Capacity: 128 MiB
GP4 Capacity: 512 MiB

通常,我可以使用 UBoot 命令:fatload/fatls 或 ext4load/ext4ls 来根据文件系统类型显示给定分区的内容。

fatls 命令的工作示例 - 请注意,这显示了用户区域的内容(上面的大小为 2.7GB)。

zynq-uboot> fatls mmc 0:1
    17488   devicetree.dtb
   962589   fpga.bit
       54   uenv.txt
  6709360   uimage
  1555344   boot.bin
       33   image.chk
 83493724   image.tgz

7 file(s), 0 dir(s)

当在 Linux 中挂载时,GP 分区包含我的根文件系统、内核映像等。我希望能够通过 fatload/ext4load 命令从 GP 分区启动,并将用户区域用于存储启动文件的其他目的。

我找到了有关此主题的其他帖子,但是,它们似乎尚未得到答复:https://lists.denx.de/pipermail/u-boot/2014-July/184731.html

任何帮助,将不胜感激!

答案1

我们已经成功从 U-Boot 访问 GP 分区。由于不支持 MMC 5.1 版本,U-boot 2017 无法识别我们的 GP 分区(最后支持 5.0,因此出于某种原因回退到版本 4.0)在我们的 U-Boot 代码中启用版本 5.1 后,它被识别:

=> mmc info
Device: OMAP SD/MMC
Manufacturer ID: 11
OEM: 100
Name: 008G3 
Tran Speed: 52000000
Rd Block Len: 512
MMC version 5.1
High Capacity: Yes
Capacity: 7.3 GiB
Bus Width: 8-bit
Erase Group Size: 4 MiB
HC WP Group Size: 4 MiB
User Capacity: 7.3 GiB
Boot Capacity: 8 MiB ENH
RPMB Capacity: 4 MiB ENH
GP1 Capacity: 4 MiB ENH WRREL
GP2 Capacity: 4 MiB ENH WRREL

现在从 U-Boot(环境或控制台)您可以执行以下操作:(注意;我们的 eMMC 作为 mmc 设备 0 连接

mmc dev 0 #select device 0
mmc partconf-partenable 0; #store the active bootpartition
mmc partconf 0 1 7 4; #configure device 0 (first parameter) to use User partiton (the 7) to GP1 (first GP) (4)
mmc partconf 0 1 7 5; #configure device 0 (first) to use userpartition second (GP2) (parameter 5)
#Now display partition (which won't work, explained below)
=> mmc part

Partition Map for MMC device 0  --   Partition Type: DOS

Part    Start Sector    Num Sectors UUID        Type
bad MBR sector signature 0x0000
=>
#now load a file with filename from the ext4 filesystem (see below)
=> ext4load mmc 0:0 0x80000000 FILE_NAME.txt
15 bytes read in 2 ms (6.8 KiB/s)
#restore active partition
=> mmc partconf 0 1 ${boot_part_enabled} 1 #restore the boot_partition (this parameter boot_part_enabled is set from 'mmc partconf-partenable 0' at the beginning)

为了做到这一点,我们已经从 Linux 预格式化并创建了一次 GP 分区:

mkfs.ext4 /dev/mmcblk1gp1
mount /dev/mmcblk1gp1 /media/gp1
echo "SOMELINEOFTEXT" > /media/gp1/FILE_NAME.txt
reboot

现在你可以从 u-boot 读取它

答案2

是的,您可以从 uboot 访问 GP 分区。

如此处所述http://u-boot.10912.n7.nabble.com/How-to-access-GP-partitions-from-uboot-2015-04-td212394.html您可以使用“mmc partconf”命令的最后一个参数来告诉eMMC带出不同的部分(例如GP而不是用户区域)。运行该命令并执行“mmc read”命令后,您会注意到您正在从不同的区域读取。

不过要小心。至少在我的u-boot版本(2017)中,u-boot不知道必须重新读取分区表,并且出于优化目的,它不会。我必须在 blk_get_device_by_str 中的part.c 中做一个小补丁,以强制part_init 每次执行。然后,当您执行“mmc 部分”时,您还应该看到 GP 分区表,并且可以像平常一样执行任何文件操作。不要忘记,执行“mmc 重新扫描”或对 eMMC 进行任何重置都会丢失 GP 状态,并且您必须再次切换回 GP 才能读取它。

相关内容