Android OTA update (1): Compile the update package.

Source: Internet
Author: User
Tags zipinfo srec

1. Ota features

OTA update is a standard software upgrade method provided by the Android system. It is powerful and provides full upgrade and incremental upgrade modes, which can be upgraded through SD card or USB flash disk or through network. Here, we will first study the simplest situation and complete the upgrade through the SD card.

2. Compile the full OTA update package. 1) Compile the android
2) Make otapackage

You can get: Out/target/product/{product_name}/export product_name1_-ota-eng.w.uid=.zip.

3) change the file name to update.zip and place it in the root directory of the SD card to start OTA update in recovery mode. 3. compilation process research

There are two main steps:
Step 1: Prepare a package containing the content (raw materials) required for the upgrade, such as the system directory.
Step 2: run the Python script./build/tools/releasetools/ota_from_target_files. Use the zip package prepared in step 1 as the input to generate the required upgrade package.

 

1) Step 1
The compilation script is as follows:
(From: build/CORE/makefile)

1073 # Depending on the various images guarantees that the underlying  1074 # directories are up-to-date.  1075 $(BUILT_TARGET_FILES_PACKAGE): /  1076                 $(INSTALLED_BOOTIMAGE_TARGET) /  1077                 $(INSTALLED_RADIOIMAGE_TARGET) /  1078                 $(INSTALLED_RECOVERYIMAGE_TARGET) /  1079                 $(INSTALLED_FACTORYIMAGE_TARGET) /  1080                 $(INSTALLED_SYSTEMIMAGE) /  1081                 $(INSTALLED_USERDATAIMAGE_TARGET) /  1082                 $(INSTALLED_SECROIMAGE_TARGET) /  1083                 $(INSTALLED_ANDROID_INFO_TXT_TARGET) /  1084                 $(built_ota_tools) /  1085                 $(APKCERTS_FILE) /  1086                 $(HOST_OUT_EXECUTABLES)/fs_config /  1087                 | $(ACP)  1088         @echo "Package target files: $@"  1089         $(hide) rm -rf $@ $(zip_root)  1090         $(hide) mkdir -p $(dir $@) $(zip_root)  1091         @# Components of the recovery image  1092         $(hide) mkdir -p $(zip_root)/RECOVERY  1093         $(hide) $(call package_files-copy-root, /  1094                 $(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/RECOVERY/RAMDISK)  <SPAN style="BACKGROUND-COLOR: #ff0000"><SPAN style="COLOR: #cccccc">1095 ifdef INSTALLED_KERNEL_TARGET  1096         $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/RECOVERY/kernel  1097         $(hide) $(ACP) $(recovery_ramdisk) $(zip_root)/RECOVERY/ramdisk  1098 endif  </SPAN></SPAN>1099 ifdef INSTALLED_2NDBOOTLOADER_TARGET  1100         $(hide) $(ACP) /  1101                 $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/RECOVERY/second  1102 endif  1103 ifdef BOARD_KERNEL_CMDLINE  1104         $(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/RECOVERY/cmdline  1105 endif  1106 ifdef BOARD_KERNEL_BASE  1107         $(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/RECOVERY/base  1108 endif  1109         @# Components of the factory image  1110         $(hide) mkdir -p $(zip_root)/FACTORY  1111         $(hide) $(call package_files-copy-root, /  1112                 $(TARGET_FACTORY_ROOT_OUT),$(zip_root)/FACTORY/RAMDISK)  1113 ifdef INSTALLED_KERNEL_TARGET  1114         $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/FACTORY/kernel  1115 endif  1116 ifdef INSTALLED_2NDBOOTLOADER_TARGET  1117         $(hide) $(ACP) /  1118                 $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/FACTORY/second  1119 endif  1120 ifdef BOARD_KERNEL_CMDLINE  1121         $(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/FACTORY/cmdline  1122 endif  1123 ifdef BOARD_KERNEL_BASE  1124         $(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/FACTORY/base  1125 endif  1126         @# Components of the boot image  1127         $(hide) mkdir -p $(zip_root)/BOOT  1128         $(hide) $(call package_files-copy-root, /  1129                 $(TARGET_ROOT_OUT),$(zip_root)/BOOT/RAMDISK)  1130 ifdef INSTALLED_KERNEL_TARGET  1131         $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/BOOT/kernel  1132         $(hide) $(ACP) $(INSTALLED_RAMDISK_TARGET) $(zip_root)/BOOT/ramdisk  1133 endif  1134 ifdef INSTALLED_2NDBOOTLOADER_TARGET  1135         $(hide) $(ACP) /  1136                 $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second  1137 endif  1138 ifdef BOARD_KERNEL_CMDLINE  1139         $(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline  1140 endif  1141 ifdef BOARD_KERNEL_BASE  1142         $(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base  1143 endif  1144         $(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),/  1145                     mkdir -p $(zip_root)/RADIO; /  1146                     $(ACP) $(t) $(zip_root)/RADIO/$(notdir $(t));)  1147         @# Contents of the system image  1148         $(hide) $(call package_files-copy-root, /  1149                 $(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)  1150         @# Contents of the data image  1151         $(hide) $(call package_files-copy-root, /  1152                 $(TARGET_OUT_DATA),$(zip_root)/DATA)  1153         @# Extra contents of the OTA package  1154         $(hide) mkdir -p $(zip_root)/OTA/bin  1155         $(hide) $(ACP) $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/  1156         $(hide) $(ACP) $(PRIVATE_OTA_TOOLS) $(zip_root)/OTA/bin/  1157         @# Files that do not end up in any images, but are necessary to  1158         @# build them.  1159         $(hide) mkdir -p $(zip_root)/META  1160         $(hide) $(ACP) $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt  1161         $(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt  1162         $(hide) echo "$(PRIVATE_RECOVERY_API_VERSION)" > $(zip_root)/META/recovery-api-version.txt  1163         $(hide) echo "blocksize $(BOARD_FLASH_BLOCK_SIZE)" > $(zip_root)/META/imagesizes.txt  1164         $(hide) echo "boot $(call image-size-from-data-size,$(BOARD_BOOTIMAGE_PARTITION_SIZE))" >> $(zip_root)/META/imagesizes.txt  1165         $(hide) echo "recovery $(call image-size-from-data-size,$(BOARD_RECOVERYIMAGE_PARTITION_SIZE))" >> $(zip_root)/META/imagesizes.txt  1166         $(hide) echo "system $(call image-size-from-data-size,$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))" >> $(zip_root)/META/imagesizes.txt  1167         $(hide) echo "secro $(call image-size-from-data-size,$(BOARD_SECROIMAGE_PARTITION_SIZE))" >> $(zip_root)/META/imagesizes.txt  1168         $(hide) echo "userdata $(call image-size-from-data-size,$(BOARD_USERDATAIMAGE_PARTITION_SIZE))" >> $(zip_root)/META/imagesizes.txt  1169         $(hide) echo "$(tool_extensions)" > $(zip_root)/META/tool-extensions.txt  1170         @# Zip everything up, preserving symlinks  1171         $(hide) (cd $(zip_root) && zip -qry ../$(notdir $@) .)  1172         @# Run fs_config on all the system files in the zip, and save the output  1173         $(hide) zipinfo -1 $@ | awk -F/ 'BEGIN { OFS="/" } /^SYSTEM/// {$$1 = "system"; print}' | $(HOST_OUT_EXECUTABLES)/fs_config > $(zip_root)/META/filesystem_config.txt  1174         $(hide) (cd $(zip_root) && zip -q ../$(notdir $@) META/filesystem_config.txt)

It can be seen that a lot of content is added to it:
1) L1089-1090, create a directory.
2) L1091-1108, fill in the contents of the recovery subdirectory. Used to generate recovery. IMG. Including: Kernel image, recovery root file system image, and recovery root file system content:

Recovery $ tree-L 2
── Kernel
── Ramdisk
── Ramdisk
── Advanced_meta_init.rc
── Data
── Default. Prop
── Dev
── Etc
── Init
── Init. Factory. RC
── Init. Goldfish. RC
── Init. mt6516.rc
── Init. RC
── Meta_init.rc
── Proc
── Res
── Sbin
── Sys
── System
── TMP
L1109-1125, filling in the contents of the factory subdirectory, not used, including: the image of the kernel
L1126-1143 that fills in the content of the boot subdirectory for generating boot. IMG. Similar to the recovery directory, it includes the image of the kernel, the image of the root file system, and the content of the root file system:
Boot $ tree-L 2
.
── Kernel
── Ramdisk
── Ramdisk
── Advanced_meta_init.rc
── Data
── Default. Prop
── Dev
── Init
── Init. Factory. RC
── Init. Goldfish. RC
── Init. mt6516.rc
── Init. RC
── Meta_init.rc
── Proc
├ ── Res->/system/Res
── Sbin
── Sys
── System
 
L1144-1146, fill in the contents of the radio subdirectory, not used.
L1147-1149 that fills in the contents of the system subdirectory. This is the main content of the upgrade.
L1150-1152 that fills in the content of the data subdirectory. It is not used by default.
L1153-1156, fill in the content of the OTA/bin subdirectory, This is the OTA upgrade your own program. This will happen later.
OTA/bin $ tree
.
── Applypatch
── Applypatch_static
── Check_prereq
── Updater
L1159-1169, fill in the contents of the Meta subdirectory, which contains some additional information required by the OTA script.
L1170-1171 to pack all content. For use in the next stage.
L1173-1174, generate META/filesystem_config.txt and add it to the zip package. This file stores the permissions and owner of the directories and files under the system directory.
$ Head META/filesystem_config.txt
System 0 0 755
System/usr 0 0 755
System/usr/SREC 0 0 755
System/usr/SREC/config 0 0 755
System/usr/SREC/config/en. US 0 0 755
System/usr/SREC/config/en. US/grammars 0 0 755
System/usr/SREC/config/en. US/grammars/phone_type_choice.g2g 0 0 644
System/usr/SREC/config/en. US/grammars/voicedialer. gg 0 0 644
System/usr/SREC/config/en. US/grammars/Boolean. G2G 0 0 644
System/usr/SREC/config/en. US/g2p 0 0 755
 
Here, the directory is provided by zipinfo-l, and the permission is set by fs_config. The source code of this program is: build/tools/fs_config, where fs_config contains a header file:
54 # include "private/android_filesystem_config.h"
This file (System/CORE/include/private/android_filesystem_config.h) sets the permissions and owners of directories and files under the system in the form of hardcoding. For example:
152 {00440, aid_root, aid_shell, "system/etc/init. Goldfish. RC "},
153 {00550, aid_root, aid_shell, "system/etc/init. Goldfish. Sh "},
154 {00440, aid_root, aid_shell, "system/etc/init. Trout. RC "},
155 {00550, aid_root, aid_shell, "system/etc/init. RIL "},
 
If you want to upgrade other content, such as bootloader, you can add it here.
 
2) Step 2
The compilation script is as follows:

(From: build/CORE/makefile)

1186 name := $(TARGET_PRODUCT)  1187 ifeq ($(TARGET_BUILD_TYPE),debug)  1188   name := $(name)_debug  1189 endif  1190 name := $(name)-ota-$(FILE_NAME_TAG)  1191   1192 INTERNAL_OTA_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip  1193   1194 $(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)  1195   1196 ifeq ($(TARGET_OTA_SCRIPT_MODE),)  1197 # default to "auto"  1198 $(INTERNAL_OTA_PACKAGE_TARGET): scriptmode := auto  1199 else  1200 $(INTERNAL_OTA_PACKAGE_TARGET): scriptmode := $(TARGET_OTA_SCRIPT_MODE)  1201 endif  1202   1203 $(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(OTATOOLS)  1204         @echo "Package OTA: $@"  1205         $(hide) ./build/tools/releasetools/ota_from_target_files /  1206            -m $(scriptmode) /  1207            -p $(HOST_OUT) /  1208            -k $(KEY_CERT_PAIR) /  1209            $(BUILT_TARGET_FILES_PACKAGE) $@  

The core is a Python script: ota_from_target_files. It uses the zip package generated in the previous step as the input to generate a zip package that can be used for OTA upgrade. The specific content will be further analyzed later.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.