ac8257 android 9 lk upgrade升级后分区表错误问题
问题描述
ac8257 Android 9,使用lk upgrade升级功能升级固件,当分区表发生变化时,分区表会出现以下问题:
1、备份分区表错误
2、分区表存在重叠
验证方法
lk upgrade升级后,用sgdisk命令检测分区表是否存在错误。
sgdisk
--verify
# sgdisk --verify /dev/block/mmcblk0
Warning! Main and backup partition tables differ! Use the 'c' and 'e' options
on the recovery & transformation menu to examine the two tables.
Warning! One or more CRCs don't match. You should repair the disk!
Main header: OK
Backup header: OK
Main partition table: OK
Backup partition table: ERROR
****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************
Warning! Main partition table overlaps the first partition by 960 blocks!
Try reducing the partition table size by 3840 entries.
(Use the 's' item on the experts' menu.)
Warning! Secondary partition table overlaps the last partition by
1 blocks!
Try reducing the partition table size by 4 entries.
(Use the 's' item on the experts' menu.)
Caution: The CRC for the backup partition table is invalid. This table may
be corrupt. This program will automatically create a new backup partition
table when you save your partitions.
Problem: main GPT header's size of partition entries (128) doesn't
match the backup GPT header's size of partition entries (0)
You should use the 'b' or 'd' option on the recovery & transformation menu to
select one or the other header.
Warning: There is a gap between the main partition table (ending sector 33)
and the first usable sector (1024). This is helpful in some exotic configurations,
but is unusual. The util-linux fdisk program often creates disks like this.
Using 'j' on the experts' menu can adjust this gap.
Warning! Main partition table overlaps the first partition by 960 blocks!
Try reducing the partition table size by 3840 entries.
(Use the 's' item on the experts' menu.)
Warning! Secondary partition table overlaps the last partition by
1 blocks!
Try reducing the partition table size by 4 entries.
(Use the 's' item on the experts' menu.)
Identified 4 problems!
# sgdisk --print /dev/block/mmcblk0
Warning! Main and backup partition tables differ! Use the 'c' and 'e' options
on the recovery & transformation menu to examine the two tables.
Warning! One or more CRCs don't match. You should repair the disk!
Main header: OK
Backup header: OK
Main partition table: OK
Backup partition table: ERROR
****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************
Warning! Main partition table overlaps the first partition by 960 blocks!
Try reducing the partition table size by 3840 entries.
(Use the 's' item on the experts' menu.)
Warning! Secondary partition table overlaps the last partition by
1 blocks!
Try reducing the partition table size by 4 entries.
(Use the 's' item on the experts' menu.)
Disk /dev/block/mmcblk0: 61112320 sectors, 29.1 GiB
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 00000000-0000-0000-0000-000000000000
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 1024, last usable sector is 61112285
Partitions will be aligned on 1-sector boundaries
Total free space is 0 sectors (0 bytes)
Number Start (sector) End (sector) Size Code Name
1 64 2111 1024.0 KiB 0700 boot_para
2 2112 67647 32.0 MiB 0700 recovery
3 67648 68671 512.0 KiB 0700 para
4 68672 109631 20.0 MiB 0700 expdb
5 109632 175167 32.0 MiB 0700 nvcfg
6 175168 306239 64.0 MiB 0700 nvdata
7 306240 371775 32.0 MiB 0700 metadata
8 371776 388159 8.0 MiB 0700 protect1
9 388160 409599 10.5 MiB 0700 protect2
10 409600 425983 8.0 MiB 0700 seccfg
11 425984 524287 48.0 MiB 0700 persist
12 524288 528383 2.0 MiB 0700 sec1
13 528384 534527 3.0 MiB 0700 proinfo
14 534528 739327 100.0 MiB 0700 md1img
15 739328 741375 1024.0 KiB 0700 spmfw
16 741376 743423 1024.0 KiB 0700 scp1
17 743424 745471 1024.0 KiB 0700 scp2
18 745472 747519 1024.0 KiB 0700 sspm_1
19 747520 749567 1024.0 KiB 0700 sspm_2
20 749568 782335 16.0 MiB 0700 gz1
21 782336 815103 16.0 MiB 0700 gz2
22 815104 946175 64.0 MiB 0700 nvram
23 946176 1011711 32.0 MiB 0700 arm2
24 1011712 1015807 2.0 MiB 0700 lk
25 1015808 1019903 2.0 MiB 0700 lk2
26 1019904 1040383 10.0 MiB 0700 boot
27 1040384 1056767 8.0 MiB 0700 dtbo
28 1056768 1067007 5.0 MiB 0700 tee1
29 1067008 1081343 7.0 MiB 0700 tee2
30 1081344 2719743 800.0 MiB 0700 vendor
31 2719744 9011199 3.0 GiB 0700 system
32 9011200 9027583 8.0 MiB 0700 vbmeta
33 9027584 9093119 32.0 MiB 0700 logo
34 9093120 9158655 32.0 MiB 0700 logo2
35 9158656 9160703 1024.0 KiB 0700 metazone
36 9160704 9160767 32.0 KiB 0700 misc
37 9160768 9207807 23.0 MiB 0700 avm
38 9207808 10092543 432.0 MiB 0700 cache
41 10633216 60991454 24.0 GiB 0700 userdata
42 60991455 61079518 43.0 MiB 0700 otp
43 61079519 61112286 16.0 MiB 0700 flashinfo
补丁
备份分区表错误问题
--- a/platform/common/partition/efi.c
+++ b/platform/common/partition/efi.c
@@ -937,8 +937,7 @@ static void pack_pheader_data(void *data)
header->alternate_lba = last_lba(dev->blkdev->part_user);
header->last_usable_lba = get_gpt_header_last_usable_lba();
header->partition_entry_lba = 0x2;
- if (gpt_count)
- header->num_partition_entries = 128;
+ header->num_partition_entries = 128;
u64 entries_real_size = (u64)header->num_partition_entries * header->sizeof_partition_entry;
//memcpy(header->disk_guid.b, GPT_DISK_GUID, sizeof(GPT_DISK_GUID));
header->partition_entry_array_crc32 = efi_crc32((u8 *)part, (u32)entries_real_size);
@@ -1021,9 +1020,8 @@ static void pack_sheader_data(void *data)
gpt_header *header = (gpt_header *)data;
gpt_entry *part = (gpt_entry *)(data + BLK_SIZE);
- header->sizeof_partition_entry = GPT_ENTRY_SIZE;
-
memset(data, 0x0, BLK_SIZE);
+ header->sizeof_partition_entry = GPT_ENTRY_SIZE;
header->signature = GPT_HEADER_SIGNATURE;
header->revision = 0x00010000;
header->header_size = 0x5C;
@@ -1036,8 +1034,7 @@ static void pack_sheader_data(void *data)
//header->disk_guid
//memcpy(header->disk_guid.b, GPT_DISK_GUID, sizeof(GPT_DISK_GUID));
header->partition_entry_lba = get_gpt_header_last_usable_lba() + 1;
- if (gpt_count)
- header->num_partition_entries = 128;
+ header->num_partition_entries = 128;
u64 entries_real_size = (u64)header->num_partition_entries * header->sizeof_partition_entry;
header->partition_entry_array_crc32 = efi_crc32((u8 *)part, (u32)entries_real_size);
分区表重叠问题
--- a/platform/common/include/efi.h
+++ b/platform/common/include/efi.h
@@ -92,6 +92,8 @@ typedef struct {
#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
#ifdef ATC_AOSP_ENHANCEMENT
#define GPT_ENTRY_SIZE 128
+#define GPT_ENTRY_COUNT 128
+
#define GPT_DISK_GUID "AUTO CHIPS" //10 Bytes
#define GPT_PART_GUID {0xA2, 0xA0, 0xD0, 0xEB, 0xE5, 0xB9, 0x33, 0x44, 0x87, 0xC0, 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7}
@@ -101,7 +103,7 @@ typedef struct {
/*used MBR: 8 bytes*/
#define GPT_MBR_LK_UPG_FOR_ATE 424
#define PART_MAGIC 0x58881688
-#define GPT_PART_SIZE 512*1024
+#define GPT_PART_SIZE (2 * 512 + GPT_ENTRY_COUNT * GPT_ENTRY_SIZE)
int atc_read_gpt(part_dev_t *dev);
--- a/platform/common/partition/efi.c
+++ b/platform/common/partition/efi.c
@@ -82,11 +82,11 @@ static u32 part_num = 0;
int gpt_count = 0;
#define BLK_SIZE (512)
#define GPT_PART_MAX_NUM 40
-#define GPT_PART_LENGTH ((PART_MAX_COUNT*sizeof(gpt_entry))+2*BLK_SIZE)
+#define GPT_PART_LENGTH ((PART_MAX_COUNT*sizeof(gpt_entry))+2*BLK_SIZE)
static u8 gpt_part_temp[GPT_PART_LENGTH];
u8 gpt_part[GPT_PART_LENGTH];
static bool need_resize = false;
-u32 sgpt_partition_lba_size = GPT_PART_LENGTH/BLK_SIZE;
+u32 sgpt_partition_lba_size = (GPT_PART_LENGTH/BLK_SIZE - 1);
/*
********** Definition of CRC32 Calculation **********
@@ -197,7 +197,6 @@ static u64 get_gpt_header_last_usable_lba()
part_dev_t *dev = mt_part_get_device();
return (last_lba(dev->blkdev->part_user)-get_spgt_partition_lba_size());
-
}
static u32 entries_crc32;
@@ -937,7 +936,7 @@ static void pack_pheader_data(void *data)
header->alternate_lba = last_lba(dev->blkdev->part_user);
header->last_usable_lba = get_gpt_header_last_usable_lba();
header->partition_entry_lba = 0x2;
- header->num_partition_entries = 128;
+ header->num_partition_entries = GPT_ENTRY_COUNT;
u64 entries_real_size = (u64)header->num_partition_entries * header->sizeof_partition_entry;
//memcpy(header->disk_guid.b, GPT_DISK_GUID, sizeof(GPT_DISK_GUID));
header->partition_entry_array_crc32 = efi_crc32((u8 *)part, (u32)entries_real_size);
@@ -980,7 +979,7 @@ static void pack_entries_data(void *data)
/* it's last partition (do not have reserved partition ex: no flashinfo, otp), only need to update last partition */
/* may not go to here unless customer remove flashinfo partition */
if (i == nr_parts-1 && !entries[i].starting_lba && !entries[i].ending_lba) {
- entries[i].ending_lba = last_lba(dev->blkdev->part_user) - get_spgt_partition_lba_size() ;
+ entries[i].ending_lba = last_lba(dev->blkdev->part_user) - get_spgt_partition_lba_size();
entries[i].starting_lba = entries[i-1].ending_lba + 1;
break;
}
@@ -991,7 +990,7 @@ static void pack_entries_data(void *data)
/* it's a reserved partition and it's last partition, entries[i].ending_lba not empty(partition size is here) */
if (i == nr_parts-1 && entries[i].ending_lba) {
entries[i].starting_lba = last_lba(dev->blkdev->part_user) - get_spgt_partition_lba_size() - entries[i].ending_lba + 1;
- entries[i].ending_lba = last_lba(dev->blkdev->part_user) - get_spgt_partition_lba_size() ;
+ entries[i].ending_lba = last_lba(dev->blkdev->part_user) - get_spgt_partition_lba_size();
}
/* reserved parttiion but not last one */
/* may not go to here uless there exists more than one reserved partitions (ex: otp + flashinfo)*/
@@ -1034,7 +1033,7 @@ static void pack_sheader_data(void *data)
//header->disk_guid
//memcpy(header->disk_guid.b, GPT_DISK_GUID, sizeof(GPT_DISK_GUID));
header->partition_entry_lba = get_gpt_header_last_usable_lba() + 1;
- header->num_partition_entries = 128;
+ header->num_partition_entries = GPT_ENTRY_COUNT;
u64 entries_real_size = (u64)header->num_partition_entries * header->sizeof_partition_entry;
header->partition_entry_array_crc32 = efi_crc32((u8 *)part, (u32)entries_real_size);