Android upgrades are divided into two types, one is to upgrade a single file in the system, and the other is to upgrade the entire mtd partition. The upgrade package is a signed compressed file compressed in zip format. The main process of the upgrade process is described as follows:
1 boot finds that the user holds down the upgrade button and reads recovery.img into the memory as a ramdisk.
2 The kernel executes the recovery script according to init.rc in the ramdisk. After the Recovery script finds the upgrade file in the sdcard, it calls the recovery program to perform the following operations in sequence:
A Check whether the digital signature of the upgrade file is reliable. Check that the local key used for the signature is /res/keys
B If the signature is legitimate, extract the META-INF/com/google/android/update-binary file in the compressed package and rename it to /tmp/update_binary and execute the file.
C update_binary parses the META-INF/com/google/android/updater-script file in the compressed file and executes it. The upgrade progress is passed back to the recovery program through the pipeline. Upgrade/update can directly overwrite the target file, or use a binary patch to reduce the size of the upgrade file. The tools used are bsdiff and imgdiff. For patch package upgrades, the basis for identifying the reliability of the upgrade data source is SHA1 checksum data length comparison. The specific requirements are: 1. The sha1 value of the target file provided by the upgrade package matches the calculated value of the target file, that is, the target is correct. 2. The sha1 value and length of the patched file must be consistent with the length and sha1 value of the patched target file provided by the upgrade package to ensure that the result is correct. If one of the two items does not match, the upgrade process stops. In order to ensure that the second operation does not damage the final target, the patched file will be temporarily stored in the cache, and the actual writing/replacing of the target file will not be performed until the result comparison is correct. Therefore, this process requires that the cache directory must have enough space to save temporary files.