]> git.sur5r.net Git - u-boot/blobdiff - disk/part_efi.c
part: efi: rework the partition start and size in gpt_fill_pte
[u-boot] / disk / part_efi.c
index 71c3cb3f78d9fbffae660c019cfa54d3bb4ef7e1..fa95ce12329a7b4aafbcb859951d8f1976cefc2f 100644 (file)
@@ -432,7 +432,6 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
                disk_partition_t *partitions, int parts)
 {
        lbaint_t offset = (lbaint_t)le64_to_cpu(gpt_h->first_usable_lba);
-       lbaint_t start;
        lbaint_t last_usable_lba = (lbaint_t)
                        le64_to_cpu(gpt_h->last_usable_lba);
        int i, k;
@@ -448,24 +447,27 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
 
        for (i = 0; i < parts; i++) {
                /* partition starting lba */
-               start = partitions[i].start;
+               lbaint_t start = partitions[i].start;
+               lbaint_t size = partitions[i].size;
+
                if (start && (start < offset)) {
                        printf("Partition overlap\n");
                        return -1;
                }
+
                if (start) {
                        gpt_e[i].starting_lba = cpu_to_le64(start);
-                       offset = start + partitions[i].size;
+                       offset = start + size;
                } else {
                        gpt_e[i].starting_lba = cpu_to_le64(offset);
-                       offset += partitions[i].size;
+                       offset += size;
                }
                if (offset > (last_usable_lba + 1)) {
                        printf("Partitions layout exceds disk size\n");
                        return -1;
                }
                /* partition ending lba */
-               if ((i == parts - 1) && (partitions[i].size == 0))
+               if ((i == parts - 1) && (size == 0))
                        /* extend the last partition to maximuim */
                        gpt_e[i].ending_lba = gpt_h->last_usable_lba;
                else
@@ -525,7 +527,7 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
                debug("%s: name: %s offset[%d]: 0x" LBAF
                      " size[%d]: 0x" LBAF "\n",
                      __func__, partitions[i].name, i,
-                     offset, i, partitions[i].size);
+                     offset, i, size);
        }
 
        return 0;
@@ -534,6 +536,7 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
 static uint32_t partition_entries_offset(struct blk_desc *dev_desc)
 {
        uint32_t offset_blks = 2;
+       uint32_t __maybe_unused offset_bytes;
        int __maybe_unused config_offset;
 
 #if defined(CONFIG_EFI_PARTITION_ENTRIES_OFF)
@@ -545,8 +548,9 @@ static uint32_t partition_entries_offset(struct blk_desc *dev_desc)
         * the disk) for the entries can be set in
         * CONFIG_EFI_PARTITION_ENTRIES_OFF.
         */
-       offset_blks =
+       offset_bytes =
                PAD_TO_BLOCKSIZE(CONFIG_EFI_PARTITION_ENTRIES_OFF, dev_desc);
+       offset_blks = offset_bytes / dev_desc->blksz;
 #endif
 
 #if defined(CONFIG_OF_CONTROL)
@@ -558,8 +562,10 @@ static uint32_t partition_entries_offset(struct blk_desc *dev_desc)
        config_offset = fdtdec_get_config_int(gd->fdt_blob,
                                              "u-boot,efi-partition-entries-offset",
                                              -EINVAL);
-       if (config_offset != -EINVAL)
-               offset_blks = PAD_TO_BLOCKSIZE(config_offset, dev_desc);
+       if (config_offset != -EINVAL) {
+               offset_bytes = PAD_TO_BLOCKSIZE(config_offset, dev_desc);
+               offset_blks = offset_bytes / dev_desc->blksz;
+       }
 #endif
 
        debug("efi: partition entries offset (in blocks): %d\n", offset_blks);