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 <[email protected]> Reviewed-by: Christophe KERELLO <[email protected]> Reviewed-by: Simon Glass <[email protected]> --- 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 v6: - add comment for function prepare_backup_gpt_header Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None disk/part_efi.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/disk/part_efi.c b/disk/part_efi.c index 181a748..23a582a 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -155,7 +155,14 @@ 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) +/* + * prepare_backup_gpt_header() - change primary GPT header to backup GPT header + * + * @param gpt_h - pointer to GPT header (in=primary, out=secondary) + * @param pte_blk_cnt - number of block for size of partition entry array (PTE) + */ +static void prepare_backup_gpt_header(gpt_header *gpt_h, + const int pte_blk_cnt) { uint32_t calc_crc32; uint64_t val; @@ -164,8 +171,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, @@ -409,7 +415,7 @@ int write_gpt_table(struct blk_desc *dev_desc, pte_blk_cnt, gpt_e) != 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) @@ -824,7 +830,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 [email protected] https://lists.denx.de/listinfo/u-boot

