Difference between revisions of "Partitions"

From Rockchip open source Document
Jump to: navigation, search
Line 122: Line 122:
= How to modify GPT partition table through U-boot =
= How to modify GPT partition table through U-boot =
Line 139: Line 140:
for exsample:
for exsample:
<pre><code>=> env set partitions name=rootfs,size=-,type=system
<pre>=> env set partitions name=rootfs,size=-,type=system
=> gpt write mmc 0 $partitions
=> gpt write mmc 0 $partitions
Writing GPT: success!
Writing GPT: success!

Revision as of 06:24, 21 March 2017


Rockchip use GPT as its main partition table in open source support. We store GPT at LBA0 ~ LBA63.

GPT partition table in U-boot

U-boot supports standard GPT partition table format.

Default partition map

Partition Start Sector Number of Sectors Partition Size Mount Point Requirements
MBR 0 00000000 1 00000001 512 0.5KB    
Primary GPT 1 00000001 63 0000003F 32256 31.5KB    
loader1 64 00000040 8000 00001F40 4096000 3.91MB   miniloader or U-Boot SPL
reserved1 8064 00001F80 128 00000080 65536 64KB    
reserved2 8192 00002000 8192 00002000 4194304 4MB   parameter or vendor data
loader2 16384 00004000 8192 00002000 4194304 4MB   U-Boot when using miniloader
atf 24576 00006000 8192 00002000 4194304 4MB   ATF, trusted-os when using miniloader
boot(bootable must be set) 32768 00008000 229376 00038000 117440512 112MB   kernela, kernelb, dts, extlinux.conf, ramdisk
rootfs 262144 00040000 - - - -MB   Linux system
Secondary GPT 16777183 00FFFFDF 33 00000021 16896 16.5KB    


How to modify GPT partition table through U-boot

In u-boot console, the "gpt" command can be used to write the gpt partition table:

gpt - GUID Partition Table

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>

for exsample:

=> env set partitions name=rootfs,size=-,type=system
=> gpt write mmc 0 $partitions
Writing GPT: success!

NOTE: the partitions env can be set in the u-boot console(using "env set" command), or in u-boot's source code,
for exsample:

        "uuid_disk=${uuid_gpt_disk};" \

        "partitions=" PARTS_DEFAULT \


How to modify GPT partition table through U-boot's fastboot

The current upstream u-boot contains fastboot protocol support. And this version of fastboot supports 2 ways to modify gpt partition table:

fastboot oem format

It's the same as "gpt write mmc 0 $partitions" in u-boot console:

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

PC command:

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

fastboot flash gpt <gpt partition image>

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

The gpt partition image can be generated by PC's gdisk tool,
for exsample:

$ 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

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 command:

$ 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