Original article: http://blog.csdn.net/zjujoe/article/details/6206010
Android OTA update: Compile the update package
Author: Song Lixin
Email: zjujoe@yahoo.com
Preface
OTA update is a standard software upgrade method provided by the Android system. It is powerful and provides full upgrade and incremental upgrade modes. It can be upgraded through the SD card or through the network.
Here, we will first study the simplest situation and complete the upgrade through the SD card.
There is not much to say about how to perform the upgrade. There is a lot of information on the Internet. (For example, how to upgrade HTC mobile phones ). We are interested in how it is implemented and how developers modify it to meet our customization needs.
First, we will study the compilation process of the OTA update package.
Quick Start
Compile Android first, and then execute:
Make otapackage
You can get: Out/target/product/{product_name}/export product_name1_-ota-eng.w.uid=.zip.
Change the file name to update.zip and put it in the TKA root directory to start OTA update in recovery mode.
Compilation process research
There are two main steps. The first step is to 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.
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)
- 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
- 1099 ifdef installed_2ndbootloader_target
- 1100 $ (hide) $ (ACP )/
- 1101 $ (installed_2ndbootloader_target) $ (zip_root)/recovery/second
- 1102 endif
- 1103 ifdef board_kernel_1_line
- 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_1_line
- 1121 $ (hide) echo "$ (board_kernel_cmdline)" >$ (zip_root)/Factory/export line
- 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_1_line
- 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
- 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/'in in {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.
L1089-1090, create a directory.
L1091-1108 that fills 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.g2g 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.hIn the form of hardcoding, permissions and owners of directories and files under the system are set. 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.
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)/queues (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.