Merge branch 'master' of git://git.denx.de/u-boot-net
[oweals/u-boot.git] / disk / part_efi.c
index 2945892a24d225d910e16720295e88dd01b8666e..3e026697dbe9911002db37635fa610dc75338ba5 100644 (file)
@@ -14,7 +14,6 @@
 #include <command.h>
 #include <fdtdec.h>
 #include <ide.h>
-#include <inttypes.h>
 #include <malloc.h>
 #include <memalign.h>
 #include <part_efi.h>
@@ -67,7 +66,7 @@ static char *print_efiname(gpt_entry *pte)
        return name;
 }
 
-static efi_guid_t system_guid = PARTITION_SYSTEM_GUID;
+static const efi_guid_t system_guid = PARTITION_SYSTEM_GUID;
 
 static inline int is_bootable(gpt_entry *p)
 {
@@ -83,11 +82,11 @@ static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba,
        uint32_t calc_crc32;
 
        /* Check the GPT header signature */
-       if (le64_to_cpu(gpt_h->signature) != GPT_HEADER_SIGNATURE) {
+       if (le64_to_cpu(gpt_h->signature) != GPT_HEADER_SIGNATURE_UBOOT) {
                printf("%s signature is wrong: 0x%llX != 0x%llX\n",
                       "GUID Partition Table Header",
                       le64_to_cpu(gpt_h->signature),
-                      GPT_HEADER_SIGNATURE);
+                      GPT_HEADER_SIGNATURE_UBOOT);
                return -1;
        }
 
@@ -210,6 +209,8 @@ int get_disk_guid(struct blk_desc * dev_desc, char *guid)
        guid_bin = gpt_head->disk_guid.b;
        uuid_bin_to_str(guid_bin, guid, UUID_STR_FORMAT_GUID);
 
+       /* Remember to free pte */
+       free(gpt_pte);
        return 0;
 }
 
@@ -312,8 +313,8 @@ int part_get_info_efi(struct blk_desc *dev_desc, int part,
                     - info->start;
        info->blksz = dev_desc->blksz;
 
-       sprintf((char *)info->name, "%s",
-                       print_efiname(&gpt_pte[part - 1]));
+       snprintf((char *)info->name, sizeof(info->name), "%s",
+                print_efiname(&gpt_pte[part - 1]));
        strcpy((char *)info->type, "U-Boot");
        info->bootable = is_bootable(&gpt_pte[part - 1]);
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
@@ -604,7 +605,7 @@ static uint32_t partition_entries_offset(struct blk_desc *dev_desc)
 int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h,
                char *str_guid, int parts_count)
 {
-       gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE);
+       gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE_UBOOT);
        gpt_h->revision = cpu_to_le32(GPT_HEADER_REVISION_V1);
        gpt_h->header_size = cpu_to_le32(sizeof(gpt_header));
        gpt_h->my_lba = cpu_to_le64(1);
@@ -697,6 +698,10 @@ int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head,
                       __func__);
                return -1;
        }
+
+       /* Free pte before allocating again */
+       free(*gpt_pte);
+
        if (is_gpt_valid(dev_desc, (dev_desc->lba - 1),
                         gpt_head, gpt_pte) != 1) {
                printf("%s: *** ERROR: Invalid Backup GPT ***\n",