Android OTA 系统升级方案概述

1,200 阅读3分钟

OTA概述

Android 系统升级方案主要分为两类,分别是 单分区升级 和 双分区升级。

  • 单分区升级:Android 7.0 之前主要采用Recovery升级方案。这种方案需要有较大cache和data分区,用于存储下载的rom包。
  • 双分区升级:android 7.0 之后,开始使用A/B双分区升级方案。这种方案本质上就是把单分区中需要升级的分区分为两个分区。例如,将system分区分为system_a和system_b两个分区,两个分区是等价的。
  • Android 8.1 以上还有一个时区更新(Rime Zone updates),但是我对此知之甚少,就不班门弄斧了。

系统分区情况

Android Recovery分区情况

Android recovery更新方式都是单分区,单分区的主要分区以及分区功能如下所示:

分区作用
bootloader存放用于引导的linux的bootloader
boot存放Android系统的linux kernel文件和用于挂载分区的ramdisk
systemAndroid系统主分区,存储系统应用和库文件
vendorAndroid系统主分区,一般用于存储厂商定制的应用
userdata用户数据分区,存放用户相关的数据和三方应用及相关数据
cache临时数据分区,可用于存放升级包
recovery存放recovery系统的linux kernel和ramdisk
misc存放Android系统和recovery系统和bootloader通信的数据

Android A/B双分区分区情况

Android 双分区的主要分区情况和分区功能如下所示:

分区作用
bootloader存放用于引导的linux的bootloader
boot_a存放Android系统的linux kernel文件和用于挂载分区的ramdisk
boot_b存放Android系统的linux kernel文件和用于挂载分区的ramdisk
system_aAndroid系统主分区,存储系统应用和库文件
system_bAndroid系统主分区,存储系统应用和库文件
vendor_aAndroid系统主分区,一般用于存储厂商定制的应用
vendor_bAndroid系统主分区,一般用于存储厂商定制的应用
misc存放Android系统和recovery系统和bootloader通信的数据

从以上表格可以简单看出,双分区a/b分区是等价的,互相为对方的备份。

分区变化

Android系统分区变化如下所示:

image.png

主要变化有以下几点:

  1. boot、system、vendor、dtbo、tee等分区从单分区变为双分区
  2. 双分区不需要recovery分区和cache分区

采用A/B双分区主要有以下优点:

A/B system updates provide the following benefits:

  • OTA updates can occur while the system is running, without interrupting the user. Users can continue to use their devices during an OTA—the only downtime during an update is when the device reboots into the updated disk partition.
  • After an update, rebooting takes no longer than a regular reboot.
  • If an OTA fails to apply (for example, because of a bad flash), the user will not be affected. The user will continue to run the old OS, and the client is free to re-attempt the update.
  • If an OTA update is applied but fails to boot, the device will reboot back into the old partition and remains usable. The client is free to re-attempt the update.
  • Any errors (such as I/O errors) affect only the unused partition set and can be retried. Such errors also become less likely because the I/O load is deliberately low to avoid degrading the user experience.
  • Updates can be streamed to A/B devices, removing the need to download the package before installing it. Streaming means it's not necessary for the user to have enough free space to store the update package on /data or /cache.
  • The cache partition is no longer used to store OTA update packages, so there is no need to ensure that the cache partition is large enough for future updates.
  • dm-verity guarantees a device will boot an uncorrupted image. If a device doesn't boot due to a bad OTA or dm-verity issue, the device can reboot into an old image. (Android Verified Boot does not require A/B updates.)

来源:source.android.com/docs/core/o…

简单来说,双分区可以影响用户的使用,同时降低设备故障导致无法使用的概率。

双分区本质上做了类似于备份的操作,如果原先运行的分区是system_a,system分区更新时会优先更新system_b。如果system_b分区更新成功,系统切换到system_b运行;如果更新失败,则继续运行在system_a分区。这样保证了故障发生时,仍有可用的版本。