disk: part_efi: re-order partition list printf, change case
[pandora-u-boot.git] / disk / part_efi.c
index e7f2714..b6b2bf5 100644 (file)
@@ -38,7 +38,6 @@
 #include <linux/ctype.h>
 
 #if defined(CONFIG_CMD_IDE) || \
-    defined(CONFIG_CMD_MG_DISK) || \
     defined(CONFIG_CMD_SATA) || \
     defined(CONFIG_CMD_SCSI) || \
     defined(CONFIG_CMD_USB) || \
@@ -130,24 +129,23 @@ void print_part_efi(block_dev_desc_t * dev_desc)
        }
        /* This function validates AND fills in the GPT header and PTE */
        if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
-                        &(gpt_head), &gpt_pte) != 1) {
+                        gpt_head, &gpt_pte) != 1) {
                printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
                return;
        }
 
        debug("%s: gpt-entry at %p\n", __func__, gpt_pte);
 
-       printf("Part\tName\t\t\tStart LBA\tEnd LBA\n");
+       printf("Part\tStart LBA\tEnd LBA\t\tName\n");
        for (i = 0; i < le32_to_int(gpt_head->num_partition_entries); i++) {
-
-               if (is_pte_valid(&gpt_pte[i])) {
-                       printf("%3d\t%-18s\t0x%08llX\t0x%08llX\n", (i + 1),
-                               print_efiname(&gpt_pte[i]),
-                               le64_to_int(gpt_pte[i].starting_lba),
-                               le64_to_int(gpt_pte[i].ending_lba));
-               } else {
-                       break;  /* Stop at the first non valid PTE */
-               }
+               /* Stop at the first non valid PTE */
+               if (!is_pte_valid(&gpt_pte[i]))
+                       break;
+
+               printf("%3d\t0x%08llx\t0x%08llx\t\"%s\"\n", (i + 1),
+                       le64_to_int(gpt_pte[i].starting_lba),
+                       le64_to_int(gpt_pte[i].ending_lba),
+                       print_efiname(&gpt_pte[i]));
        }
 
        /* Remember to free pte */
@@ -155,6 +153,28 @@ void print_part_efi(block_dev_desc_t * dev_desc)
        return;
 }
 
+#ifdef CONFIG_PARTITION_UUIDS
+static void uuid_string(unsigned char *uuid, char *str)
+{
+       static const u8 le[16] = {3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11,
+                                 12, 13, 14, 15};
+       int i;
+
+       for (i = 0; i < 16; i++) {
+               sprintf(str, "%02x", uuid[le[i]]);
+               str += 2;
+               switch (i) {
+               case 3:
+               case 5:
+               case 7:
+               case 9:
+                       *str++ = '-';
+                       break;
+               }
+       }
+}
+#endif
+
 int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
                                disk_partition_t * info)
 {
@@ -169,11 +189,18 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
 
        /* This function validates AND fills in the GPT header and PTE */
        if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA,
-                       &(gpt_head), &gpt_pte) != 1) {
+                       gpt_head, &gpt_pte) != 1) {
                printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
                return -1;
        }
 
+       if (part > le32_to_int(gpt_head->num_partition_entries) ||
+           !is_pte_valid(&gpt_pte[part - 1])) {
+               printf("%s: *** ERROR: Invalid partition number %d ***\n",
+                       __func__, part);
+               return -1;
+       }
+
        /* The ulong casting limits the maximum disk size to 2 TB */
        info->start = (ulong) le64_to_int(gpt_pte[part - 1].starting_lba);
        /* The ending LBA is inclusive, to calculate size, add 1 to it */
@@ -184,6 +211,9 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
        sprintf((char *)info->name, "%s",
                        print_efiname(&gpt_pte[part - 1]));
        sprintf((char *)info->type, "U-Boot");
+#ifdef CONFIG_PARTITION_UUIDS
+       uuid_string(gpt_pte[part - 1].unique_partition_guid.b, info->uuid);
+#endif
 
        debug("%s: start 0x%lX, size 0x%lX, name %s", __func__,
                info->start, info->size, info->name);
@@ -380,7 +410,7 @@ static gpt_entry *alloc_read_gpt_entries(block_dev_desc_t * dev_desc,
 
        /* Allocate memory for PTE, remember to FREE */
        if (count != 0) {
-               pte = memalign(CONFIG_SYS_CACHELINE_SIZE, count);
+               pte = memalign(ARCH_DMA_MINALIGN, count);
        }
 
        if (count == 0 || pte == NULL) {