README.gpt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #
  2. # Copyright (C) 2012 Samsung Electronics
  3. #
  4. # Lukasz Majewski <l.majewski@samsung.com>
  5. #
  6. #
  7. # SPDX-License-Identifier: GPL-2.0+
  8. Glossary:
  9. ========
  10. - UUID -(Universally Unique Identifier)
  11. - GUID - (Globally Unique ID)
  12. - EFI - (Extensible Firmware Interface)
  13. - UEFI - (Unified EFI) - EFI evolution
  14. - GPT (GUID Partition Table) - it is the EFI standard part
  15. - partitions - lists of available partitions (defined at u-boot):
  16. ./include/configs/{target}.h
  17. Introduction:
  18. =============
  19. This document describes the GPT partition table format and usage of
  20. the gpt command in u-boot.
  21. UUID introduction:
  22. ====================
  23. GPT for marking disks/partitions is using the UUID. It is supposed to be a
  24. globally unique value. A UUID is a 16-byte (128-bit) number. The number of
  25. theoretically possible UUIDs is therefore about 3 x 10^38.
  26. More often UUID is displayed as 32 hexadecimal digits, in 5 groups,
  27. separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters
  28. (32 digits and 4 hyphens)
  29. For instance, GUID of Linux data partition: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
  30. Historically there are 5 methods to generate this number. The oldest one is
  31. combining machine's MAC address and timer (epoch) value.
  32. Successive versions are using MD5 hash, random numbers and SHA-1 hash. All major
  33. OSes and programming languages are providing libraries to compute UUID (e.g.
  34. uuid command line tool).
  35. GPT brief explanation:
  36. ======================
  37. Layout:
  38. -------
  39. --------------------------------------------------
  40. LBA 0 |Protective MBR |
  41. ----------------------------------------------------------
  42. LBA 1 |Primary GPT Header | Primary
  43. -------------------------------------------------- GPT
  44. LBA 2 |Entry 1|Entry 2| Entry 3| Entry 4|
  45. --------------------------------------------------
  46. LBA 3 |Entries 5 - 128 |
  47. | |
  48. | |
  49. ----------------------------------------------------------
  50. LBA 34 |Partition 1 |
  51. | |
  52. -----------------------------------
  53. |Partition 2 |
  54. | |
  55. -----------------------------------
  56. |Partition n |
  57. | |
  58. ----------------------------------------------------------
  59. LBA -34 |Entry 1|Entry 2| Entry 3| Entry 4| Backup
  60. -------------------------------------------------- GPT
  61. LBA -33 |Entries 5 - 128 |
  62. | |
  63. | |
  64. LBA -2 | |
  65. --------------------------------------------------
  66. LBA -1 |Backup GPT Header |
  67. ----------------------------------------------------------
  68. For a legacy reasons, GPT's LBA 0 sector has a MBR structure. It is called
  69. "protective MBR".
  70. Its first partition entry ID has 0xEE value, and disk software, which is not
  71. handling the GPT sees it as a storage device without free space.
  72. It is possible to define 128 linearly placed partition entries.
  73. "LBA -1" means the last addressable block (in the mmc subsystem:
  74. "dev_desc->lba - 1")
  75. Primary/Backup GPT header:
  76. ----------------------------
  77. Offset Size Description
  78. 0 8 B Signature ("EFI PART", 45 46 49 20 50 41 52 54)
  79. 8 4 B Revision (For version 1.0, the value is 00 00 01 00)
  80. 12 4 B Header size (in bytes, usually 5C 00 00 00 meaning 92 bytes)
  81. 16 4 B CRC32 of header (0 to header size), with this field zeroed
  82. during calculation
  83. 20 4 B Reserved (ZERO);
  84. 24 8 B Current LBA (location of this header copy)
  85. 32 8 B Backup LBA (location of the other header copy)
  86. 40 8 B First usable LBA for partitions (primary partition table last
  87. LBA + 1)
  88. 48 8 B Last usable LBA (secondary partition table first LBA - 1)
  89. 56 16 B Disk GUID (also referred as UUID on UNIXes)
  90. 72 8 B Partition entries starting LBA (always 2 in primary copy)
  91. 80 4 B Number of partition entries
  92. 84 4 B Size of a partition entry (usually 128)
  93. 88 4 B CRC32 of partition array
  94. 92 * Reserved; must be ZERO (420 bytes for a 512-byte LBA)
  95. TOTAL: 512 B
  96. IMPORTANT:
  97. GPT headers and partition entries are protected by CRC32 (the POSIX CRC32).
  98. Primary GPT header and Backup GPT header have swapped values of "Current LBA"
  99. and "Backup LBA" and therefore different CRC32 check-sum.
  100. CRC32 for GPT headers (field "CRC of header") are calculated up till
  101. "Header size" (92), NOT 512 bytes.
  102. CRC32 for partition entries (field "CRC32 of partition array") is calculated for
  103. the whole array entry ( Number_of_partition_entries *
  104. sizeof(partition_entry_size (usually 128)))
  105. Observe, how Backup GPT is placed in the memory. It is NOT a mirror reflect
  106. of the Primary.
  107. Partition Entry Format:
  108. ----------------------
  109. Offset Size Description
  110. 0 16 B Partition type GUID (Big Endian)
  111. 16 16 B Unique partition GUID in (Big Endian)
  112. 32 8 B First LBA (Little Endian)
  113. 40 8 B Last LBA (inclusive)
  114. 48 8 B Attribute flags [+]
  115. 56 72 B Partition name (text)
  116. Attribute flags:
  117. Bit 0 - System partition
  118. Bit 60 - Read-only
  119. Bit 62 - Hidden
  120. Bit 63 - Not mount
  121. Creating GPT partitions in U-Boot:
  122. ==============
  123. To restore GUID partition table one needs to:
  124. 1. Define partition layout in the environment.
  125. Format of partitions layout:
  126. "partitions=uuid_disk=...;name=u-boot,size=60MiB,uuid=...;
  127. name=kernel,size=60MiB,uuid=...;"
  128. or
  129. "partitions=uuid_disk=${uuid_gpt_disk};name=${uboot_name},
  130. size=${uboot_size},uuid=${uboot_uuid};"
  131. The fields 'name' and 'size' are mandatory for every partition.
  132. The field 'start' is optional.
  133. The fields 'uuid' and 'uuid_disk' are optional if CONFIG_RANDOM_UUID is
  134. enabled. A random uuid will be used if omitted or they point to an empty/
  135. non-existent environment variable. The environment variable will be set to
  136. the generated UUID.
  137. 2. Define 'CONFIG_EFI_PARTITION' and 'CONFIG_CMD_GPT'
  138. 2. From u-boot prompt type:
  139. gpt write mmc 0 $partitions
  140. Useful info:
  141. ============
  142. Two programs, namely: 'gdisk' and 'parted' are recommended to work with GPT
  143. recovery. Both are able to handle GUID partitions.
  144. Please, pay attention at -l switch for parted.
  145. "uuid" program is recommended to generate UUID string. Moreover it can decode
  146. (-d switch) passed in UUID string. It can be used to generate partitions UUID
  147. passed to u-boot environment variables.
  148. If optional CONFIG_RANDOM_UUID is defined then for any partition which environment
  149. uuid is unset, uuid is randomly generated and stored in correspond environment
  150. variable.
  151. note:
  152. Each string block of UUID generated by program "uuid" is in big endian and it is
  153. also stored in big endian in disk GPT.
  154. Partitions layout can be printed by typing "mmc part". Note that each partition
  155. GUID has different byte order than UUID generated before, this is because first
  156. three blocks of GUID string are in Little Endian.