当前位置:   article > 正文

Rockchip | 固件分区排列_rk ota dd

rk ota dd

一、介绍

 在开放源代码支持中,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分区表

  1. rkdeveloptool db rkxx_loader_vx.xx.bin
  2. 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分区表:

  1. gpt - GUID Partition Table
  2. Usage:
  3. gpt <command> <interface> <dev> <partitions_list>
  4. - GUID partition table restoration and validity check
  5. Restore or verify GPT information on a device connected
  6. to interface
  7. Example usage:
  8. gpt write mmc 0 $partitions
  9. gpt verify mmc 0 $partitions</code>

例如:

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

注意:可以在u-boot console(使用“ env set”命令)或在u-boot的源代码中设置分区env
例如:

  1. include/configs/kylin_rk3036.h
  2. #define PARTS_DEFAULT \
  3. "uuid_disk=${uuid_gpt_disk};" \
  4. ...
  5. #undef CONFIG_EXTRA_ENV_SETTINGS
  6. #define CONFIG_EXTRA_ENV_SETTINGS \
  7. "partitions=" PARTS_DEFAULT \

六、通过U-Boot的fastboot写入GPT分区表

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

(1)fastboot oem格式

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

  1. #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
  2. if (strncmp("format", cmd + 4, 6) == 0) {
  3. char cmdbuf[32];
  4. sprintf(cmdbuf, "gpt write mmc %x $partitions",
  5. CONFIG_FASTBOOT_FLASH_MMC_DEV);
  6. if (run_command(cmdbuf, 0))
  7. fastboot_tx_write_str("FAIL");
  8. else
  9. fastboot_tx_write_str("OKAY");
  10. } else
  11. #endif

PC命令:

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

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

  1. if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
  2. printf("%s: updating MBR, Primary and Backup GPT(s)\n",
  3. __func__);
  4. if (is_valid_gpt_buf(dev_desc, download_buffer)) {
  5. printf("%s: invalid GPT - refusing to write to flash\n",
  6. __func__);
  7. fastboot_fail(response_str, "invalid GPT partition");
  8. return;
  9. }
  10. if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) {
  11. printf("%s: writing GPT partitions failed\n", __func__);
  12. fastboot_fail(response_str,
  13. "writing GPT partitions failed");
  14. return;
  15. }
  16. printf("........ success\n");
  17. fastboot_okay(response_str, "");
  18. return;

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

  1. $ dd if=/dev/zero of=disk.img bs=1M count=256
  2. 256+0 records in
  3. 256+0 records out
  4. 268435456 bytes (268 MB) copied, 0.151867 s, 1.8 GB/s
  5. $ gdisk disk.img
  6. GPT fdisk (gdisk) version 0.8.1
  7. Partition table scan:
  8. MBR: not present
  9. BSD: not present
  10. APM: not present
  11. GPT: not present
  12. Creating new GPT entries.
  13. Command (? for help): n
  14. Partition number (1-128, default 1):
  15. First sector (34-524254, default = 34) or {+-}size{KMGTP}:
  16. Information: Moved requested sector from 34 to 2048 in
  17. order to align on 2048-sector boundaries.
  18. Use 'l' on the experts' menu to adjust alignment
  19. Last sector (2048-524254, default = 524254) or {+-}size{KMGTP}:
  20. Current type is 'Linux filesystem'
  21. Hex code or GUID (L to show codes, Enter = 8300):
  22. Changed type of partition to 'Linux filesystem'
  23. Command (? for help): w
  24. Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
  25. PARTITIONS!!
  26. Do you want to proceed? (Y/N): y
  27. OK; writing new GUID partition table (GPT).
  28. Warning: The kernel is still using the old partition table.
  29. The new table will be used at the next reboot.
  30. The operation has completed successfully.
  31. $ dd if=disk.img of=gpt.img count=64
  32. 64+0 records in
  33. 64+0 records out
  34. 32768 bytes (33 kB) copied, 0.00075438 s, 43.4 MB/s

PC命令:

  1. $ fastboot flash gpt gpt.img
  2. target reported max download size of 117440512 bytes
  3. sending 'gpt' (32 KB)...
  4. OKAY [ 0.006s]
  5. writing 'gpt'...
  6. OKAY [ 0.025s]
  7. finished. total time: 0.030s
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/368803
推荐阅读
相关标签
  

闽ICP备14008679号