the value for partition_entry_lba of secondary GPT (last usable lba + 1) is not correct with MTD support as last usable LBA need to be erase size aligned
The correct location of partition entry is always recomputed with the formula : partition_entry_lba = alternate_lba - num_pte * sizeof_partition_entry / lba_size Signed-off-by: Patrick Delaunay <patrick.delau...@st.com> Reviewed-by: Christophe KERELLO <christophe.kere...@st.com> --- the device mapping is 1/ for block case: last_usable_lba -> partition_entry_lba - 1 partition_entry_lba -> PTE table (num * sizeof(PTE)) alternate_lba -> secondary GPT -> end of device 2/ for MTD case : end of the last good block ------------- last_usable_lba -> last good erase block - 1 -------------erase BLOCK aligned XXXXXXXXXXXXXXXXXX -> skipped LBA for MTD case partition_entry_lba -> PTE table (num * sizeof(PTE)) alternate_lba -> secondary GPT -------------erase BLOCK aligned xxxxx skipping bad block ->end of device Changes in v3: None Changes in v2: None disk/part_efi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/disk/part_efi.c b/disk/part_efi.c index 5d0848e..24ebaa0 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -153,7 +153,8 @@ static int validate_gpt_entries(gpt_header *gpt_h, gpt_entry *gpt_e) return 0; } -static void prepare_backup_gpt_header(gpt_header *gpt_h) +static void prepare_backup_gpt_header(gpt_header *gpt_h, + const int pte_blk_cnt) { uint32_t calc_crc32; uint64_t val; @@ -162,8 +163,7 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h) val = le64_to_cpu(gpt_h->alternate_lba); gpt_h->alternate_lba = gpt_h->my_lba; gpt_h->my_lba = cpu_to_le64(val); - gpt_h->partition_entry_lba = - cpu_to_le64(le64_to_cpu(gpt_h->last_usable_lba) + 1); + gpt_h->partition_entry_lba = cpu_to_le64(val - pte_blk_cnt); gpt_h->header_crc32 = 0; calc_crc32 = efi_crc32((const unsigned char *)gpt_h, @@ -380,7 +380,7 @@ int write_gpt_table(struct blk_desc *dev_desc, != pte_blk_cnt) goto err; - prepare_backup_gpt_header(gpt_h); + prepare_backup_gpt_header(gpt_h, pte_blk_cnt); if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba) + 1, pte_blk_cnt, gpt_e) != pte_blk_cnt) @@ -750,7 +750,7 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf) return 1; } - prepare_backup_gpt_header(gpt_h); + prepare_backup_gpt_header(gpt_h, gpt_e_blk_cnt); /* write Backup GPT */ lba = le64_to_cpu(gpt_h->partition_entry_lba); -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot