Detailed OTA upgrade (2)

Blue is taken from blue, and blue is from blue;

Ice is for water, but colder than water.

From Xunzi's "Encouraging Learning"

This chapter explains the
      previous  OTA upgrade detailed explanation (1) mainly talks about some basic knowledge of OTA. The main content of this article is to explain the production process of the OTA upgrade package in detail, sort out the key details of the package, because the package script is longer and there are more files. It will not be displayed in the form of script comments for the time being. The explanation is mainly based on the calling function sequence diagram + the key step text description. The repeated content will be automatically omitted. The steps in the explanation are based on   Android OTA Update  . If the process is different from what the readers have, don’t worry. The overall process looks like the following. The additions are only some details and optimizations. Just follow the actual steps.

Production process description

       Make the upgrade package ota_from_target_files as the entry point, and you can pass in parameters, such as: whether it is a differential package, the original package, and the target version package (the package structure is explained in detail in the first, and it is passed in as a zip package). The following is the basic process of the main function

1. The general process of ota_from_target_files-main, here is mainly some preparatory work, the core work is in the last function:

2、ota_from_target_files - WriteIncrementalOTAPackage()

There are 4 parameters here, namely:

input_zip -> basic package

source_zip -> target package

output_zip -> upgrade package (coming soon)

OPTIONS.fota -> fota tag

WriteIncrementalOTAPackage--The process is as follows:

Important note:

1. The generation of updater-script: comes from the script (list). The content of this list comes from the constant additions during various generation processes, and each one is an execution command.

2. ComputePatch calculates the difference: If the file type is some compressed files, such as: .img, .apk, .jar, .zip, .gz, it will use the imgdiff executable file to calculate, if it is a normal file, it will use it. bsdiff is calculated.

3. File permissions issues: For the system partition, it has a file system. The difference calculated for each file under the file system is not saved in the zip package. The gid, uid, and mode of the new or changed file are not saved. And other attributes, so you need to modify the permissions of the newly added files or the permissions change files. Ensure that the system is running normally or the app has execution permissions. One of the two ways to obtain file permissions is fs_config (a hard-coded method and relatively rigid), which reads the absolute path of the file to obtain this information, and the other is from the original package, located in META/filesystem_config.txt , This requires that when generating the original package, the file permissions are saved to this file, and the file format is consistent with that generated using fs_config. Finally, use set_perm_recursive/set_perm to restore permissions on directories and files.

Format : absolute path gid uid mode   

Example: system/etc/dbus.conf 1000 1000 440           

4. update-binary: from the location in the target package as follows: OTA/bin/updater

5. Where does the sha value come from: the original file and the target file are calculated in the LoadSystemFiles function by matching the has1 value

After the above steps, a differential packet can be generated, the structure is as follows (sample):

The corresponding updater-script is as follows (sample):

The above is the whole process of making OTA differential package using script.

 

       I am not a professional python, and the explanations in some places may not be very reasonable. I also hope that my peers will criticize and give pointers. The bsdiff and imgdiff algorithms have not been studied carefully. The current focus is on the main process.

        After understanding the above content, you can make personalized modifications to this tool, such as adding other new files to the upgrade package, adding process keyword descriptions, and so on. But knowing these contents, many people are still confused about the OTA upgrade. Then we can explain the OTA upgrade process in detail based on the content of this chapter in the next section. After the next chapter, everyone will understand that the details of each file in the upgrade package The role and significance of existence, and recovery uses the core components updater-script and update-binary to complete the upgrade of the entire differential package, so stay tuned. . .

                                  

                                               Long press the QR code to follow [embedded C tribe] for more programming information and essential articles

Guess you like

Origin blog.csdn.net/weixin_35933684/article/details/102849358