README.gpt 7.1 KB

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