disk: part_efi: add support for the Backup GPT
authorSteve Rae <srae@broadcom.com>
Mon, 5 May 2014 20:00:08 +0000 (13:00 -0700)
committerChanho Park <chanho61.park@samsung.com>
Tue, 11 Aug 2015 13:24:20 +0000 (22:24 +0900)
Check the Backup GPT table if the Primary GPT table is invalid.
Renamed "Secondary GPT" to "Backup GPT" as per:
  UEFI Specification (Version 2.3.1, Errata A)

Signed-off-by: Steve Rae <srae@broadcom.com>
disk/part_efi.c
doc/README.gpt

index 30b43c6e7816db6e40bbf736580c79e7361acdaa..295cbf22c4fc05a2f3cc89fa785d97ec8097e6ff 100644 (file)
@@ -109,7 +109,15 @@ void print_part_efi(block_dev_desc_t * dev_desc)
        if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
                         gpt_head, &gpt_pte) != 1) {
                printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
-               return;
+               if (is_gpt_valid(dev_desc, (dev_desc->lba - 1),
+                                gpt_head, &gpt_pte) != 1) {
+                       printf("%s: *** ERROR: Invalid Backup GPT ***\n",
+                              __func__);
+                       return;
+               } else {
+                       printf("%s: ***        Using Backup GPT ***\n",
+                              __func__);
+               }
        }
 
        debug("%s: gpt-entry at %p\n", __func__, gpt_pte);
@@ -158,7 +166,15 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
        if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
                        gpt_head, &gpt_pte) != 1) {
                printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
-               return -1;
+               if (is_gpt_valid(dev_desc, (dev_desc->lba - 1),
+                                gpt_head, &gpt_pte) != 1) {
+                       printf("%s: *** ERROR: Invalid Backup GPT ***\n",
+                              __func__);
+                       return -1;
+               } else {
+                       printf("%s: ***        Using Backup GPT ***\n",
+                              __func__);
+               }
        }
 
        if (part > le32_to_cpu(gpt_head->num_partition_entries) ||
@@ -268,7 +284,7 @@ int write_gpt_table(block_dev_desc_t *dev_desc,
            != pte_blk_cnt)
                goto err;
 
-       /* recalculate the values for the Second GPT Header */
+       /* recalculate the values for the Backup GPT Header */
        val = le64_to_cpu(gpt_h->my_lba);
        gpt_h->my_lba = gpt_h->alternate_lba;
        gpt_h->alternate_lba = cpu_to_le64(val);
index b4eea70cc3a5a2b27ffd98395278b5192157f0a2..6c762c89ab8d37aa8f4e05a6b948395353ae90b2 100644 (file)
@@ -84,14 +84,14 @@ GPT brief explanation:
                       |Partition n                      |
                       |                                 |
        ----------------------------------------------------------
-       LBA -34        |Entry 1|Entry 2| Entry 3| Entry 4| Secondary
-       -------------------------------------------------- (bkp)
-       LBA -33        |Entries 5 - 128                  | GPT
+       LBA -34        |Entry 1|Entry 2| Entry 3| Entry 4| Backup
+       -------------------------------------------------- GPT
+       LBA -33        |Entries 5 - 128                  |
                       |                                 |
                       |                                 |
        LBA -2         |                                 |
        --------------------------------------------------
-       LBA -1         |Secondary GPT Header             |
+       LBA -1         |Backup GPT Header                |
        ----------------------------------------------------------
 
 
@@ -105,7 +105,7 @@ It is possible to define 128 linearly placed partition entries.
 "LBA -1" means the last addressable block (in the mmc subsystem:
 "dev_desc->lba - 1")
 
-Primary/Secondary GPT header:
+Primary/Backup GPT header:
 ----------------------------
 Offset  Size    Description
 
@@ -135,7 +135,7 @@ IMPORTANT:
 
 GPT headers and partition entries are protected by CRC32 (the POSIX CRC32).
 
-Primary GPT header and Secondary GPT header have swapped values of "Current LBA"
+Primary GPT header and Backup GPT header have swapped values of "Current LBA"
 and "Backup LBA" and therefore different CRC32 check-sum.
 
 CRC32 for GPT headers (field "CRC of header") are calculated up till
@@ -145,7 +145,7 @@ CRC32 for partition entries (field "CRC32 of partition array") is calculated for
 the whole array entry ( Number_of_partition_entries *
 sizeof(partition_entry_size (usually 128)))
 
-Observe, how Secondary GPT is placed in the memory. It is NOT a mirror reflect
+Observe, how Backup GPT is placed in the memory. It is NOT a mirror reflect
 of the Primary.