Rockchip | 固件分区排列

本文详细介绍了Rockchip设备中GPT分区表的应用及配置方法,包括U-boot支持的标准GPT格式、默认存储布局、通过不同工具写入GPT分区表的过程。适用于嵌入式系统开发者。

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

一、介绍

 在开放源代码支持中,Rockchip使用 GPT作为其主要分区表。我们将GPT存储在LBA0〜LBA63中。


二、U-boot中的GPT分区表

U-boot支持标准的 GPT分区表格式


三、默认存储图

PartitionStart SectorNumber of SectorsPartition SizePartNum in GPTRequirements
MBR0000000001000000015120.5KB
Primary GPT100000001630000003F3225631.5KB
loader16400000040710400001bc040960002.5MB1preloader (miniloader or U-Boot SPL)
Vendor Storage716800001c0051200000200262144256KBSN, MAC and etc.
Reserved Space768000001e0038400000180196608192KBNot used
reserved1806400001f80128000000806553664KBlegacy DRM key
U-Boot ENV812800001fc064000000403276832KB
reserved281920000200081920000200041943044MBlegacy parameter
loader2163840000400081920000200041943044MB2U-Boot or UEFI
trust245760000600081920000200041943044MB3trusted-os like ATF, OP-TEE
boot(bootable must be set)327680000800022937600038000117440512112MB4kernel, dtb, extlinux.conf, ramdisk
rootfs26214400040000----MB5Linux system
Secondary GPT1677718300FFFFDF33000000211689616.5KB

注1:如果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分区表

当前的上游u-boot包含fastboot协议支持。此版本的fastboot支持2种修改gpt分区表的方法:

(1)fastboot oem格式

它与u-boot控制台中的“ gpt write mmc 0 $ partitions”相同:

#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
        if (strncmp("format", cmd + 4, 6) == 0) {
                char cmdbuf[32];
                sprintf(cmdbuf, "gpt write mmc %x $partitions",
                        CONFIG_FASTBOOT_FLASH_MMC_DEV);
                if (run_command(cmdbuf, 0))
                        fastboot_tx_write_str("FAIL");
                else
                        fastboot_tx_write_str("OKAY");
        } else
#endif

PC命令:

$ fastboot oem format -i 0x2207
...
OKAY [  0.015s]
finished. total time: 0.015s

(2)fastboot flash gpt <gpt分区映像>

        if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
                printf("%s: updating MBR, Primary and Backup GPT(s)\n",
                       __func__);
                if (is_valid_gpt_buf(dev_desc, download_buffer)) {
                        printf("%s: invalid GPT - refusing to write to flash\n",
                               __func__);
                        fastboot_fail(response_str, "invalid GPT partition");
                        return;
                }
                if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) {
                        printf("%s: writing GPT partitions failed\n", __func__);
                        fastboot_fail(response_str,
                                      "writing GPT partitions failed");
                        return;
                }
                printf("........ success\n");
                fastboot_okay(response_str, "");
                return;

gpt分区映像可以由PC的gdisk工具生成,
例如:

$ dd if=/dev/zero of=disk.img bs=1M count=256
256+0 records in
256+0 records out
268435456 bytes (268 MB) copied, 0.151867 s, 1.8 GB/s

$ gdisk disk.img
GPT fdisk (gdisk) version 0.8.1

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): n
Partition number (1-128, default 1):
First sector (34-524254, default = 34) or {+-}size{KMGTP}:
Information: Moved requested sector from 34 to 2048 in
order to align on 2048-sector boundaries.
Use 'l' on the experts' menu to adjust alignment
Last sector (2048-524254, default = 524254) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT).
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.

$ dd if=disk.img of=gpt.img count=64
64+0 records in
64+0 records out
32768 bytes (33 kB) copied, 0.00075438 s, 43.4 MB/s

PC命令:

$ fastboot flash gpt gpt.img
target reported max download size of 117440512 bytes
sending 'gpt' (32 KB)...
OKAY [  0.006s]
writing 'gpt'...
OKAY [  0.025s]
finished. total time: 0.030s
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值