Tian haili @ csdn
OTA update is supported in the android native system. OTA update obtains the update package through the air interface and then updates the system firmware. Generally, an update package is called an OTA update, regardless of how it is obtained.
An OTA update package is used to generate an OTA update package. The update package is divided into the upgrade package and the upgrade package (or incremental package ). The upgrade package is the software package obtained by compiling the current system. This package is large and has hundreds of megabytes, but does not depend on the software version in the current mobile phone. The upgrade package is used to differentiate the two software versions of the mobile phone, patch the first version to obtain the second upgrade package. Therefore, the differential package can only upgrade the machine of the first version.
This article describes how to generate an all-inclusive update.
Compile and upgrade all-inclusive. Run the following command:
# Make otapackage
Final generationInternal_ota_package_target, That is, $ (product_out)/templates (name).zip.
1. Upgrade the generation of all-inclusive ($ (product_out)/packages (name).zip)
Internal_ota_package_targetDependent on built_target_files_package
Generate rules in build/CORE/makefile ]:
$(INTERNAL_OTA_PACKAGE_TARGET):$(BUILT_TARGET_FILES_PACKAGE) $(OTATOOLS) @echo"Package OTA: $@" $(hide)./build/tools/releasetools/ota_from_target_files -v \ -p $(HOST_OUT) \ -k $(KEY_CERT_PAIR) \ $(BUILT_TARGET_FILES_PACKAGE) $@
Ota_from_target_files is a Python script and requires an intermediate file $ (built_target_files_package ). Therefore, after analyzing the generation of intermediate files, you can see the final upgrade of the all-inclusive process.
Generate the intermediate file package (target_product0000-target_files-0000(file_name_tag0000.zip)
Built_target_files_packageYes $ (intermediates)/$ (target_product0000-target_files-0000(file_name_tag0000.zip
Such as: Out/target/product/<product>/obj/packaging/target_files_intermediates/<product>-target_files-<Eng>. haili. Tian
Generate rules in build/CORE/makefile ]:
$(BUILT_TARGET_FILES_PACKAGE):\ $(INSTALLED_BOOTIMAGE_TARGET) \ $(INSTALLED_RADIOIMAGE_TARGET) \ $(INSTALLED_RECOVERYIMAGE_TARGET)\ $(INSTALLED_SYSTEMIMAGE) \ $(INSTALLED_USERDATAIMAGE_TARGET)\ $(INSTALLED_ANDROID_INFO_TXT_TARGET)\ $(built_ota_tools) \ $(APKCERTS_FILE) \ $(HOST_OUT_EXECUTABLES)/fs_config\ | $(ACP) @echo "Package target files:$@" $(hide) rm -rf $@ $(zip_root) $(hide) mkdir -p $(dir $@) $(zip_root) @# Components of the recovery image $(hide) mkdir -p $(zip_root)/RECOVERY $(hide) $(call package_files-copy-root, \ $(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/RECOVERY/RAMDISK)ifdef INSTALLED_KERNEL_TARGET $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET)$(zip_root)/RECOVERY/kernelendififdef INSTALLED_2NDBOOTLOADER_TARGET $(hide) $(ACP) \ $(INSTALLED_2NDBOOTLOADER_TARGET)$(zip_root)/RECOVERY/secondendififdef BOARD_KERNEL_CMDLINE $(hide) echo"$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/RECOVERY/cmdlineendififdef BOARD_KERNEL_BASE $(hide) echo"$(BOARD_KERNEL_BASE)" > $(zip_root)/RECOVERY/baseendififdef BOARD_KERNEL_PAGESIZE $(hide) echo "$(BOARD_KERNEL_PAGESIZE)"> $(zip_root)/RECOVERY/pagesizeendif @# Components of the boot image $(hide) mkdir -p $(zip_root)/BOOT $(hide) $(call package_files-copy-root, \ $(TARGET_ROOT_OUT),$(zip_root)/BOOT/RAMDISK)ifdef INSTALLED_KERNEL_TARGET $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET)$(zip_root)/BOOT/kernelendififdef INSTALLED_2NDBOOTLOADER_TARGET $(hide) $(ACP) \ $(INSTALLED_2NDBOOTLOADER_TARGET)$(zip_root)/BOOT/secondendififdef BOARD_KERNEL_CMDLINE $(hide) echo"$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdlineendififdef BOARD_KERNEL_BASE $(hide) echo"$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/baseendififdef BOARD_KERNEL_PAGESIZE $(hide) echo"$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/BOOT/pagesizeendif $(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),\ mkdir -p $(zip_root)/RADIO; \ $(ACP) $(t)$(zip_root)/RADIO/$(notdir $(t));) @# Contents of the system image $(hide) $(call package_files-copy-root, \ $(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM) @# Contents of the data image $(hide) $(call package_files-copy-root, \ $(TARGET_OUT_DATA),$(zip_root)/DATA) @# Extra contents of the OTA package $(hide) mkdir -p $(zip_root)/OTA/bin $(hide) $(ACP)$(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/ $(hide) $(ACP) $(PRIVATE_OTA_TOOLS)$(zip_root)/OTA/bin/ @# Files that do not end up in anyimages, but are necessary to @# build them. $(hide) mkdir -p $(zip_root)/META $(hide) $(ACP) $(APKCERTS_FILE)$(zip_root)/META/apkcerts.txt $(hide) echo"$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt $(hide) echo"recovery_api_version=$(PRIVATE_RECOVERY_API_VERSION)" >$(zip_root)/META/misc_info.txtifdef BOARD_FLASH_BLOCK_SIZE $(hide) echo"blocksize=$(BOARD_FLASH_BLOCK_SIZE)" >> $(zip_root)/META/misc_info.txtendififdef BOARD_BOOTIMAGE_PARTITION_SIZE $(hide) echo"boot_size=$(BOARD_BOOTIMAGE_PARTITION_SIZE)" >>$(zip_root)/META/misc_info.txtendififdef BOARD_RECOVERYIMAGE_PARTITION_SIZE $(hide) echo"recovery_size=$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)" >>$(zip_root)/META/misc_info.txtendififdef BOARD_SYSTEMIMAGE_PARTITION_SIZE $(hide) echo"system_size=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE)" >>$(zip_root)/META/misc_info.txtendififdef BOARD_USERDATAIMAGE_PARTITION_SIZE $(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)">> $(zip_root)/META/misc_info.txtendif $(hide) echo"tool_extensions=$(tool_extensions)" >>$(zip_root)/META/misc_info.txtifdef mkyaffs2_extra_flags $(hide) echo"mkyaffs2_extra_flags=$(mkyaffs2_extra_flags)" >>$(zip_root)/META/misc_info.txtendif @# Zip everything up, preserving symlinks $(hide) (cd $(zip_root) && zip-qry ../$(notdir $@) .) @# Run fs_config on all the system filesin the zip, and save the output $(hide) zipinfo -1 $@ | awk -F/ 'BEGIN {OFS="/" } /^SYSTEM\// {$$1 = "system"; print}' |$(HOST_OUT_EXECUTABLES)/fs_config > $(zip_root)/META/filesystem_config.txt $(hide) (cd $(zip_root) && zip -q../$(notdir $@) META/filesystem_config.txt)
Variable definition:
-Target_recovery_root_outThat is, $ (target_recovery_out)/root; target_recovery_out is $ (product_out)/recovery; product_out is out/target/product/<product>. Therefore, target_recovery_root_out is out/target/product/<product>/recovery/root;
-Zip_rootYes $ (intermediates)/$ (target_product)-target_files-$ (file_name_tag) path, that is, out/target/product/<product>/obj/packaging/target_files_intermediates/<product>-target_files-<Eng>. haili. tian;
-Target_root_outIs $ (product_out)/root, that is, out/target/product/<product>/root;
-Installed_radioimage_target;
-Systemimage_source_dirYes $ (target_out), that is, out/target/product/<product>/system /;
-Target_out_dataIs $ (product_out)/data, that is, out/target/product/<product>/data;
-Installed_android_info_txt_targetIs $ (product_out)/android-info.txt, that is, out/target/product/<product>/android-info.txt;
-Private_ota_toolsYes $ (built_ota_tools), that is, includes:
Out/target/product/<product>/obj/executables/applypatch_intermediates/applypatch
Out/target/product/<product>/obj/executables/applypatch_static_intermediates/applypatch_static
Out/target/product/<product>/obj/executables/check_prereq_intermediates/check_prereq
Out/target/product/<product>/obj/executables/updater_intermediates/Updater
-Apkcerts_fileIs out/target/product/<product>/obj/packaging/apkcerts_intermediates/<product>-apkcerts-<Eng> .haili.tian.txt
-Product_ota_public_keysIt is currently empty;
-Private_recovery_api_versionThat is, the version of recovery_api_version and recoveryapi;
-Tool_extensionsIf target_releasetools_extensions is defined, tool_extensions is also target_releasetools_extensions;
-Default_system_dev_certificateIt is currently empty;
-Host_out_executablesIs $ (host_out)/bin, that is, out/host/linux-x86/bin;
Script Execution:
1. # clear the existing directories and files and create$ (Zip_root)Directory (that is, out/target/product/<product>/obj/packaging/target_files_intermediates/<product>-target_files-<Eng>. haili. Tian );
2. Create $ (zip_root )/RecoveryDirectory to copy all the files and directories under $ (target_recovery_root_out) (that is, out/target/product/<product>/recovery/root) to $ (zip_root )/Recovery/ramdisk;
3. Create $ (zip_root )/BootDirectory, and then copy all the files and directories under $ (target_root_out) (that is, out/target/product/<product>/root) to $ (zip_root )/Boot/ramdisk;
4. Create the $ (zip_root)/Radio directory and copy all the files and directories under $ (installed_radioimage_target) to $ (zip_root)/Radio;
5. Copy all the files and directories under $ (systemimage_source_dir) [that is, out/target/product/<product>/system/] to $ (zip_root )/System;
6. Copy all the files and directories under $ (target_out_data) [that is, out/target/product/<product>/data] to $ (zip_root )/Data;
7. Create $ (zip_root )/OTA/binDirectory, and put installed_android_info_txt_target [that is, out/target/product/<product>/android-info.txt] to $ (zip_root )/OTA/;
8. Set private_ota_tools [that isApplypatch,Applypatch_static,Check_prereq,UpdaterTo $ (zip_root )/OTA/bin.
9. Create $ (zip_root )/MetaDirectory, collectMeta InformationAnd save it to the file:
Put apkcerts_file [out/target/product/<product>/obj/packaging/apkcerts_intermediates/<product>-apkcerts-<Eng> .haili.tian.txt] to $ (zip_root)/META/Apkcerts.txt;
Append $ (product_ota_public_keys) to $ (zip_root)/META/Otakeys.txt;【]
SetRecovery_api_version = $ (private_recovery_api_version)This line is appended to $ (zip_root)/META/Misc_info.txt;
SetTool_extensions = $ (tool_extensions)This line is appended to $ (zip_root)/META/Misc_info.txt;
Append default_system_dev_certificate =$ (default_system_dev_certificate) to $ (zip_root)/META/Misc_info.txt;
10. CopyImage File
Put $ (product_out )/Ramdisk. imgPut it under $ (zip_root;
Put $ (product_out )/Ramdisk-recovery.imgPut it in (zip_root )/
Put $ (product_out)/.../../boot/out/U-boot.binPut it in $ (zip_root )/
Put $ (product_out)/.../../kernel/out/UimagePut it in (zip_root )/
11. Enter $ (zip_root) and put all the content under $ (zip_root) into the zip package.<Product>-target_files-<Eng> .haili.tian.zip;
12. Get the file system information with $ (host_out_executables)/fs_config and save it in the file
The file system information under "system/" is saved in $ (zip_root)/META/Filesystem_config.txtMedium;
The file system information under "Boot/ramdisk/" is saved in $ (zip_root)/META/Boot_filesystem_config.txtMedium;
The file system information under "recovery/ramdisk/" is saved in $ (zip_root)/META/Recovery_filesystem_config.txtMedium;
13. Set META/* Filesystem_config.txtFile to the zip package <product>-target_files-<Eng> .haili.tian.zip.
Iii. ota_from_target_file Analysis
Ota_from_target_file is a Python script, which is analyzed from main.
3.1 generate the total process-Main ()
Main () mainly to do the following work:
1. parse options from parameters and environment;
2. parse the {<key >=< value >}options pair from Meta/misc_info.txt in the middle zip package, for example, recovery_api_version = 3; tool_extensions = device/<company>/<product>/recovery;
3. Find tool_extensions from the options pair and assign it to options. device_specific;
4. input_zip is the intermediate zip package; output_zip is the temporary zip package generated;
5. For the all-inclusive upgrade package, call writefullotapackage (input_zip, output_zip );
6. Sign the temporary package and generate the signed all-inclusive upgrade package.
In the above process, we are most concerned with the work done by writefullotapackage (input_zip, output_zip.
3.2 generate all-inclusive-writefullotapackage ()
Writefullotapackage is defined as follows:
def WriteFullOTAPackage(input_zip, output_zip): # TODO:how to determine this? We don't knowwhat version it will # beinstalled on top of. For now, we expectthe API just won't # changevery often. script =edify_generator.EdifyGenerator(3, OPTIONS.info_dict) metadata= {"post-build": GetBuildProp("ro.build.fingerprint",input_zip), "pre-device": GetBuildProp("ro.product.device",input_zip), "post-timestamp":GetBuildProp("ro.build.date.utc", input_zip), } device_specific = common.DeviceSpecificParams( input_zip=input_zip, input_version=OPTIONS.info_dict["recovery_api_version"], output_zip=output_zip, script=script, input_tmp=OPTIONS.input_tmp, metadata=metadata, info_dict=OPTIONS.info_dict, trusted_boot=OPTIONS.trusted_boot) # if not OPTIONS.omit_prereq:# ts =GetBuildProp("ro.build.date.utc", input_zip)# script.AssertOlderBuild(ts) # AppendAssertions(script, input_zip)# device_specific.FullOTA_Assertions() script.ShowProgress(0.9, 16) if OPTIONS.wipe_user_data: script.FormatPartition("/data") script.FormatPartition("/system") script.Mount("/system")# script.UnpackPackageDir("recovery", "/system") script.UnpackPackageDir("system", "/system") symlinks= CopySystemFiles(input_zip, output_zip) script.MakeSymlinks(symlinks) # boot_img = common.File("boot.img", common.BuildBootableImage(# os.path.join(OPTIONS.input_tmp, "BOOT")))# recovery_img = common.File("recovery.img",common.BuildBootableImage(# os.path.join(OPTIONS.input_tmp, "RECOVERY")))# MakeRecoveryPatch(output_zip, recovery_img, boot_img) Item.GetMetadata(input_zip) Item.Get("system").SetPermissions(script) # common.CheckSize(boot_img.data, "boot.img", OPTIONS.info_dict)# common.ZipWriteStr(output_zip, "boot.img", boot_img.data)# script.ShowProgress(0.2, 0) # script.ShowProgress(0.2, 10)# script.WriteRawImage("/boot", "boot.img") # script.ShowProgress(0.1, 0) device_specific.FullOTA_InstallEnd() if OPTIONS.extra_script is not None: script.AppendExtra(OPTIONS.extra_script) script.UnmountAll() script.AddToZip(input_zip, output_zip) WriteMetadata(metadata,output_zip)
OTA full-outsourcing Generation Process:
1. Script is used to generate the edify script, which is implemented in edify_generator.py;
2. Add a statement to the script to display the progress;
3. Add a statement in the script to erase the "/system" partition;
4. Add the statement to the script: install the system partition to "/system ";
5. Add a statement to the script: copy the content in system to/system;
6. Copy the content in the input_zip package/system to the output_zip package, excluding the link file;
7. For link files, add the link-pointing statement to the script;
8. obtain the permission information of each file in/system from Meta/filesystem_config.txt of the input_zip package;
9. Add a statement to the script: Set the file permissions and owner information under/system;
10. Call the specific device function fullota_installend.
In the main () function, options. device_specific is/device/<company>/<product>/recovery. device_specific is common. devicespecificparams.
In common. py, The releasetools. py script under the directory is used when the options. device_specific directory is determined. Therefore, execute fullota_installend in releasetools. py.
11. If other scripts are specified, add them to the script;
12. Write META-INF through script. addtozip ()
Write all the preceding scripts to the META-INF/COM/Google/Android/In output_zip/Updater-scriptIn this edify script;
Set OTA/bin/In input_zip/UpdaterMETA-INF written into output_zip/COM/Google/Android/Update-binary
13. Write the metadata content to the META-INF/COM/Android/metadata in output_zip
Summary
This article analyzes the compilation process of Android OTA full-outsourcing. First, generate the entire bundle. This package is the basis for the subsequent generation of all-inclusive packages and the basis for the generation of differential packages. Then, the process of generating the final upgrade of all-inclusive packages is analyzed. Update-binary and updateR-The script source is crucial for subsequent analysis of the OTA update process.
After introducing the complete OTA process, the generation of the differential packet will be further elaborated.