ac8257 android 9 lk upgrade升级后分区表错误问题

news/2024/11/8 4:00:34 标签: android

问题描述

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!

--print

# 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);


http://www.niftyadmin.cn/n/5743205.html

相关文章

xftp连接中不成功 + sudo vim 修改sshd_config不成功的解决方法

我们使用sudo vim不成功,但是我们使用sudo su就可以 了! root用户权利更大! 喵的,终于成功了,一个xftp连接半天不成功。(添加上面的内容就可以连接成功了↑)

Vue3父传子

1. App.vue - 父组件 咱们先来看左边的 App.vue&#xff0c;它扮演的是“父亲”角色——你可以想象它是一位热心的老爸&#xff0c;手里拿着一条消息&#xff0c;正准备把这条消息送到“儿子”那里。 <script setup> // 这个 setup 就像一个神奇的开关&#xff0c;一开…

OneRestore: A Universal Restoration Framework for Composite Degradation 论文阅读笔记

这是武汉大学一作单位的一篇发表在ECCV2024上的论文&#xff0c;文章代码开源&#xff0c;文章首页图如下所示&#xff0c;做混合图像干扰去除&#xff0c;还能分别去除&#xff0c;看起来很牛逼。文章是少见的做混合图像干扰去除的&#xff0c;不过可惜只包含了3种degradation…

解决CORS (跨源资源共享) 错误

问题引入 前端代码 <template><div id"hello-vue" class"demo">{{ message }}</div><el-button type"primary" click"handleClick">我是一个按钮</el-button></template><script setup>//加…

linux资源优化

1.思考步骤 查看资源使用的详细情况根据使用情况决定分配策略修改资源分配 2.如何查看运行中的使用的详细情况&#xff1f; 进程跟踪&#xff1a;top查看打开的文件&#xff1a;lsof lsof的输出、包含以下字段。  COMMAND&#xff1a;拥有文件描述符的的进程对应的命令…

CORS(跨域资源共享)和SOP(同源策略)

CORS&#xff08;跨域资源共享&#xff09;和SOP&#xff08;同源策略&#xff09;不是同一个东西&#xff0c;但它们紧密相关&#xff0c;并且常常一起讨论&#xff0c;因为 CORS 是为了解决同源策略带来的跨域问题而引入的。 同源策略&#xff08;Same-Origin Policy&#x…

【QT】Qt文件和多线程

个人主页~ Qt系统内容 一、Qt文件1、文件读写读写 2、文件和目录信息 二、多线程1、线程使用timethread.hwidget.htimethread.cppwidget.cpp 2、线程安全&#xff08;1&#xff09;互斥锁QMutexQMutexLocker一个例子mythread.hmythread.cppwidget.cpp QReadWriteLocker、QReadL…

MySQL表转移数据的三种方式

说明&#xff1a;在一些情况&#xff0c;像大表修改表结构&#xff0c;重新建立分区&#xff08;对已有表建立分区&#xff0c;对历史数据是不生效的&#xff09;&#xff0c;或者表备份&#xff0c;我们需要将表的数据&#xff0c;从一张表转移到另外一张表里。本文介绍&#…