[U-Boot] [PATCH v4 05/16] disk: part: compute partition_entry_lba
Patrick Delaunay
patrick.delaunay at st.com
Wed Mar 15 14:11:36 UTC 2017
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.delaunay at st.com>
Reviewed-by: Christophe KERELLO <christophe.kerello at 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 v4: None
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 bc9914a..6bc18e5 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,
@@ -387,7 +387,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)
@@ -757,7 +757,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
More information about the U-Boot
mailing list