EMMC && RK Partition Table

  • EMMC && RK Partition Table
    • 物理结构
      • Boot Area Partition
      • RPMB Partition
      • User Data Area
      • General Purpose Area Partitions
    • 总线协议
      • 总线模式
      • HS400
    • GPT (GUID Partition Table)
      • Protective MBR
      • Partition table header (LBA 1)
        • GPT header format
      • Partition entries (LBA 2–33)
        • GUID partition entry format
        • Partition attributes
        • Partition type GUID
    • RK默认存储映射表
      • RK分区表
        • cmdline
  • 参考

物理结构

eMMC (embedded MMC) 标准中,将内部的 Flash Memory 划分为 4 类区域,最多可以支持 8 个硬件分区,如下图所示:

emmcpartitions.png

  • Boot and RPMB Area Partitions' sizes and attributes are defined by the memory manufacturer (read-only), while General Purpose Area Partitions' sizes and attributes can be programmed by the host only once in the device life-cycle (one-time programmable).
    Boot和RPMB Area Partitions的大小和属性由内存制造商定义(只读),而General Purpose Area Partitions的大小和属性只能由主机在设备生命周期中编程一次(一次性可编程)。
  • The embedded device also offers the host the possibility to configure additional local memory partitions with independent address spaces, starting from logical address 0x00000000, for different usage models.
  • 这几个分区在EMMC中都是相互独立的,逻辑地址都是从 0x00 开始。

Boot Area Partition

Boot 1 & Boot 2,这两个分区是由厂家在生产过程中配置好了的,并且其大小是不能进行配置的。

RPMB Partition

RPMB (Replay Protected Memory Block),他的存在目的是用来给系统存放一些特殊的、需要进行访问授权的数据。

User Data Area

User Data Area就是AP及用户可以进行读写存储的区域,通常其大小为整块EMMC表示大小的93%左右,即4GB的eMMC UDA的区域只有4GB*93%=3809MB。

General Purpose Area Partitions

General Purpose Area Partitions (GPAP),主要用于存储系统和应用数据。在很多使用 eMMC 的产品中,GPAP都没有被启用。

eMMC 最多可以支持 4 个 GPAPs,每一个 GPAP的大小可以单独配置。

总线协议

总线模式

Mode Name Data Rate I/O Voltage Bus Width Frequency Max Data Transfer (implies x8 bus width)
Backwards Compatibility with legacy MMC card Single 3 V/1.8 V/1.2 V 1, 4, 8 0-26 MHz 26 MB/s
High Speed SDR Single 3 V/1.8 V/1.2 V 1, 4, 8 0-52 MHz 52 MB/s
High Speed DDR Dual 3 V/1.8 V/1.2 V 4, 8 0-52 MHz 104 MB/s
HS200 Single 1.8 V/1.2 V 4, 8 0-200 MHz 200 MB/s
HS400 Dual 1.8 V/1.2 V 8 0-200 MHz 400 MB/s

HS400

The HS400 mode has the following features HS400模式有以下特性

  • DDR Data sampling method DDR数据采样方法
  • CLK frequency up to 200 MHz, Data rate is up to 400 MB/s 时钟频率提升到200MHz,数据速率提升到400MB/s
  • Only 8-bit bus width supported 总线只支持8bit带宽
  • Signaling levels of 1.8 V and 1.2 V 信号电压1.8V/1.2V
  • Support up to 5 Drive Strengths
  • Data strobe signal is toggled only for Data out, CRC response and CMD Response

Figure 13 shows a typical HS400 Host and Device system. The host has a clock generator that supplies CLK to the Device. For read operations, Data Strobe is generated by device output circuit. Host receives the data, CRC Status, and CMD Response (when Enhanced Strobe is enabled), that are aligned to the edge of Data Strobe.

下图展示了典型的HS400模式下的Host和Device系统。host生成一个clk并传给device。对于读操作,device输出回路会产生 Data Strobe。Host在Data Strobe边沿接收数据、CRC状态和CMD响应(需使能Enhanced Strobe)。

image.png

GPT (GUID Partition Table)

GPT分区:全称为Globally Unique Identifier Partition Table,也叫做GUID分区表,它是UEFI 规范的一部分。下面是GPT的结构图。

1920pxGUIDPartitionTableScheme.svg.png

GPT Disk的结构中,第一个LBA (Logical Block Address) 位置(LBA 0)存放的是Protective MBR,随后LBA1的位置才是GPT的GUID分区表头。

LBA2-LBA33为分区表,从LBA34开始是具体分区。磁盘最后为备份信息,包含分区表及分区表头。

ps: rockchip U-boot中对GPT的描述 GPT partition table format

Protective MBR

  • Protective MBR 的作用是为了兼容性考虑,阻止一些遗留的MBR磁盘工具破坏GUID分区表。
  • 这种在LBA 0的位置存放Protective MBR的结构是基于Extensible Firmware Interface(EFI)规格。
  • Protective MBR和MBR拥有同样的结构,同时还包括一条包含值为0xEE的System ID的分区记录(如下图所示),这个值标注了该分区为GPT分区,如果包含该分区的磁盘被移动到Windows 2000中或者被一些遗留的磁盘工具访问,则该分区会被标注晨GPT Protective分区,不能被删除。
    Windows GPT磁盘GUID结构详解_Windows

Partition table header (LBA 1)

  • Primary GPT Header位于磁盘的LBA1位置,紧跟着Protective MBR。
  • GPT Header定义了分区记录所用到的Logical Block Address的区域。同时还定义了分区在磁盘上的位置、它自身的GUID、以及一组CRC32的校验值。
  • Backup GPT Header位于磁盘最后一个磁道之上。

GPT header format

Offset Length Contents
0 (0x00) 8 bytes Signature ("EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h or 0x5452415020494645ULL on little-endian machines) 签名
8 (0x08) 4 bytes Revision 1.0 (00h 00h 01h 00h) for UEFI 2.8 版本号
12 (0x0C) 4 bytes Header size in little endian (in bytes, usually 5Ch 00h 00h 00h or 92 bytes) 表头大小
16 (0x10) 4 bytes CRC32 of header (offset +0 up to header size) in little endian, with this field zeroed during calculation 表头的CRC校验
20 (0x14) 4 bytes Reserved; must be zero 保留,必须为0
24 (0x18) 8 bytes Current LBA (location of this header copy) 当前表头的LBA
32 (0x20) 8 bytes Backup LBA (location of the other header copy) 备份表头的LBA
40 (0x28) 8 bytes First usable LBA for partitions (primary partition table last LBA + 1) 分区可用的第一个LBA(LBA34)
48 (0x30) 8 bytes Last usable LBA (secondary partition table first LBA − 1) 分区可用的最后一个LBA
56 (0x38) 16 bytes Disk GUID in mixed endian 磁盘GUID
72 (0x48) 8 bytes Starting LBA of array of partition entries (always 2 in primary copy) 分区表起始分区号
80 (0x50) 4 bytes Number of partition entries in array 分区表总数
84 (0x54) 4 bytes Size of a single partition entry (usually 80h or 128) 单个分区表大小
88 (0x58) 4 bytes CRC32 of partition entries array in little endian 分区表CRC校验
92 (0x5C) * Reserved; must be zeroes for the rest of the block (420 bytes for a sector size of 512 bytes; but can be more with larger sector sizes) 保留 必须全0

Partition entries (LBA 2–33)

  • 分区表长度为128个字节,用来定义单个分区结构。
  • 包含分区的类型GUID(如:EFI系统分区的GUID类型是{C12A7328-F81F-11D2-BA4B-00A0C93EC93B}),该分区的GUID,起始终止位置,分区属性以及分区名称。

GUID partition entry format

Offset Length Contents
0 (0x00) 16 bytes Partition type GUID (mixed endian)
16 (0x10) 16 bytes Unique partition GUID (mixed endian)
32 (0x20) 8 bytes First LBA (little endian)
40 (0x28) 8 bytes Last LBA (inclusive, usually odd)
48 (0x30) 8 bytes Attribute flags (e.g. bit 60 denotes read-only)
56 (0x38) 72 bytes Partition name (36 UTF-16LE code units)

Partition attributes

Bit Content
Bit 0 System partition
Bit 1 Hide from EFI
Bit 2 Legacy BIOS bootable
Bit 48-63 Defined and used by the individual partition type

For Basic data partition :

Bit Content
Bit 60 Read-only
Bit 62 Hidden
Bit 63 Not mount

Partition type GUID

  • For created partition, the used partition type GUID is PARTITION_BASIC_DATA_GUID (EBD0A0A2-B9E5-4433-87C0-68B6B72699C7).

  • If you define CONFIG_PARTITION_TYPE_GUID, a optionnal parameter type
    can specify a other partition type guid:

    1"partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
    2    name=kernel,size=60MiB,uuid=...,
    3    type=0FC63DAF-8483-4772-8E79-3D69D8477DE4;"
    
  • Some strings can be also used at the place of known GUID :

    • "system" = PARTITION_SYSTEM_GUID (C12A7328-F81F-11D2-BA4B-00A0C93EC93B)
    • "mbr" = LEGACY_MBR_PARTITION_GUID (024DEE41-33E7-11D3-9D69-0008C781F39F)
    • "msft" = PARTITION_MSFT_RESERVED_GUID (E3C9E316-0B5C-4DB8-817D-F92DF00215AE)
    • "data" = PARTITION_BASIC_DATA_GUID (EBD0A0A2-B9E5-4433-87C0-68B6B72699C7)
    • "linux" = PARTITION_LINUX_FILE_SYSTEM_DATA_GUID (0FC63DAF-8483-4772-8E79-3D69D8477DE4)
    • "raid" = PARTITION_LINUX_RAID_GUID (A19D880F-05FC-4D3B-A006-743F0F84911E)
    • "swap" = PARTITION_LINUX_SWAP_GUID (0657FD6D-A4AB-43C4-84E5-0933C84B4F4F)
    • "lvm" = PARTITION_LINUX_LVM_GUID (E6D6D379-F507-44C2-A23C-238F2A3DF928)
    1"partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
    2    name=kernel,size=60MiB,uuid=...,type=linux;"
    
  • They are also used to display the type of partition in part list command.

RK默认存储映射表

image.png

Note 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分区不可用。

RK分区表

RK平台的U-Boot支持两种分区表:RK paramter格式(旧)和 标准GPT格式(新),当机器上同时存在两种分区表时,优先使用GPT分区表。无论是 GPT 还是 RK parameter,烧写用的分区表文件都叫parameter.txt。用户可以通过"TYPE: GPT"属性确认是否为 GPT。

 1FIRMWARE_VER:11.0
 2MACHINE_MODEL:rk3568_r
 3MACHINE_ID:007
 4MANUFACTURER: rockchip
 5MAGIC: 0x5041524B
 6ATAG: 0x00200800
 7MACHINE: rk3568_r
 8CHECK_MASK: 0x80
 9PWR_HLD: 0,0,A,0,1
10TYPE: GPT 				###当前是GPT格式的分区表,否则为RK paramter
11CMDLINE:mtdparts=rk29xxnand:0x00002000@0x00002000(uboot),0x00002000@0x00004000(trust),0x00002000@0x00006000(resource),0x00030000@0x00008000(boot_linux:bootable),0x00400000@0x00038000(system),0x00200000@0x00438000(vendor),-@0x00638000(userdata:grow)
12uuid:system=614e0000-0000-4b53-8000-1d28000054a9
13uuid:boot_linux=a2d37d82-51e0-420d-83f5-470db993dd35

cmdline

  • 如果是 RK 格式的分区表,可以在 parameter.txt 里存放 cmdline 信息。
  • 如果是 GPT 格式的分区表,在 parameter.txt 里存放cmdline 信息是无效的。

参考

eMMC Hardware Partitioning:https://www.pengutronix.de/en/blog/2020-10-15-anpassen-einer-emmc.html

eMMC 原理 3 :分区管理:http://www.wowotech.net/basic_tech/emmc_partitions.html

eMMC 总线协议:https://linux.codingbelief.com/zh/storage/flash_memory/emmc/emmc_bus_protocol.html

GUID Partition Table:https://en.wikipedia.org/wiki/GUID_Partition_Table

Windows GPT磁盘GUID结构详解:https://blog.51cto.com/liuhongliang/1916036
https://opensource.rock-chips.com/wiki_Partitions