概要
Uboot 是操作系统启动前的运行的一段引导程序,他主要负责初始化部分硬件,包括时钟、内存等等,加载内核、文件系统、设备树等到内存上,启动操作系统。当然uboot作用远不止这些,比如由于uboot是裸机单任务运行,我们也可以在这里面对硬件进行初步的测试、升级系统等等。
嵌入式开发中我们多多少少会涉及到uboot,所以还是有必要对这块做一些功课。我也是最近移植系统,遇到一些麻烦,对uboot做了一些研究,把他记录下来。本篇主要基于rockchip px30平台的uboot。
Rk平台固件概述
固件分区排列
在开放源代码支持中,Rockchip使用 GPT作为其主要分区表。我们将GPT存储在LBA0〜LBA63中。下图为rk的存储图:
| Partition | Start Sector | Number of Sectors | Partition Size | PartNum in GPT | Requirements | |||
|---|---|---|---|---|---|---|---|---|
| MBR | 0 | 00000000 | 1 | 00000001 | 512 | 0.5KB | ||
| Primary GPT | 1 | 00000001 | 63 | 0000003F | 32256 | 31.5KB | ||
| loader1 | 64 | 00000040 | 7104 | 00001bc0 | 4096000 | 2.5MB | 1 | preloader (miniloader or U-Boot SPL) |
| Vendor Storage | 7168 | 00001c00 | 512 | 00000200 | 262144 | 256KB | SN, MAC and etc. | |
| Reserved Space | 7680 | 00001e00 | 384 | 00000180 | 196608 | 192KB | Not used | |
| reserved1 | 8064 | 00001f80 | 128 | 00000080 | 65536 | 64KB | legacy DRM key | |
| U-Boot ENV | 8128 | 00001fc0 | 64 | 00000040 | 32768 | 32KB | ||
| reserved2 | 8192 | 00002000 | 8192 | 00002000 | 4194304 | 4MB | legacy parameter | |
| loader2 | 16384 | 00004000 | 8192 | 00002000 | 4194304 | 4MB | 2 | U-Boot or UEFI |
| trust | 24576 | 00006000 | 8192 | 00002000 | 4194304 | 4MB | 3 | trusted-os like ATF, OP-TEE |
| boot(bootable must be set) | 32768 | 00008000 | 229376 | 00038000 | 117440512 | 112MB | 4 | kernel, dtb, extlinux.conf, ramdisk |
| rootfs | 262144 | 00040000 | - | - | - | -MB | 5 | Linux system |
| Secondary GPT | 16777183 | 00FFFFDF | 33 | 00000021 | 16896 | 16.5KB | ||
如果preloader是miniloader,则loader2分区可用于uboot.img,trust分区可用于trust.img; 如果preloader是不带trust支持的SPL,则loader2分区可用于u-boot.bin,而trust分区不可用;如果preloader是具有trust支持的SPL(ATF或OPTEE),则loader2可用于u-boot.itb(包括u-boot.bin和trust二进制文件),而trust分区不可用。
写入分区表方法
-
通过rkdeveloptool编写GPT分区表
rkdeveloptool db rkxx_loader_vx.xx.bin
rkdeveloptool gpt parameter_gpt.txt
其中parameter_gpt.txt包含分区信息:
CMDLINE:mtdparts=rk29xxnand:0x00001f40@0x00000040(loader1),0x00000080@0x00001f80(reserved1),0x00002000@0x00002000(reserved2),0x00002000@0x00004000(loader2),0x00002000@0x00006000(atf),0x00038000@0x00008000(boot:bootable),@0x0040000(rootfs)
-
通过U-boot写入GPT分区表
在u-boot console中,“ gpt”命令可用于写入gpt分区表:
gpt - GUID Partition Table
Usage:
gpt <command> <interface> <dev> <partitions_list>
- GUID partition table restoration and validity check
Restore or verify GPT information on a device connected
to interface
Example usage:
gpt write mmc 0 $partitions
gpt verify mmc 0 $partitions</code>
例如:
=> env set partitions name=rootfs,size=-,type=system
=> gpt write mmc 0 $partitions
Writing GPT: success!
注意:可以在u-boot console(使用“ env set”命令)或在u-boot的源代码中设置分区env,
例如:
include/configs/kylin_rk3036.h
#define PARTS_DEFAULT \
"uuid_disk=${uuid_gpt_disk};" \
...
#undef CONFIG_EXTRA_ENV_SETTINGS
#define CONFIG_EXTRA_ENV_SETTINGS \
"partitions=" PARTS_DEFAULT \
-
通过U-Boot的fastboot写入GPT分区表
启动介绍
首先,让我们弄清楚这个概念,当我们启动 Linux 操作系统时,有很多启动阶段;
然后,我们需要知道 image 应该如何打包,image 位于何处;
最后,我们将解释如何写入不同的媒体和从那里 boot 。
以下是 Rockchip 预发布的二进制文件,稍后可能会提到:
GitHub - rockchip-linux/rkbin: Firmware and Tool Binarys
1.1 启动流程
本章介绍了 Rockchip 应用处理器的一般启动流程,包括在Rockchip平台上使用什么 image 作为启动路径的细节:
- 使用来自 Upstream 或 Rockchip U-Boot 的 U-Boot TPL/SPL ,它们完全是源代码;
- 使用 Rockchp idbLoader,它由 Rockchip rkbin project 的 Rockchip ddr init bin 和 miniloader bin 组合而成;
+--------+----------------+----------+-------------+---------+
| Boot | Terminology #1 | Actual | Rockchip | Image |
| stage | | program | Image | Location|
| number | | name | Name | (sector)|
+--------+----------------+----------+-------------+---------+
| 1 | Primary | ROM code | BootRom | |
| | Program | | | |
| | Loader | | | |
| | | | | |
| 2 | Secondary | U-Boot |idbloader.img| 0x40 | pre-loader
| | Program | TPL/SPL | | |
| | Loader (SPL) | | | |
| | | | | |
| 3 | - | U-Boot | u-boot.itb | 0x4000 | including u-boot and atf
| | | | uboot.img | | only used with miniloader
| | | | | |
| | | ATF/TEE | trust.img | 0x6000 | only used with miniloader
| | | | | |
| 4 | - | kernel | boot.img | 0x8000 |
| | | | | |
| 5 | -

最低0.47元/天 解锁文章
2373

被折叠的 条评论
为什么被折叠?



