Android OTA update: Compile the update package

Source: Internet
Author: User
Tags zipinfo srec

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)

 

 

  1. 1073 # depending on the various images guarantees that the underlying
  2. 1074 # directories are up-to-date.
  3. 1075 $ (built_target_files_package ):/
  4. 1076 $ (installed_bootimage_target )/
  5. 1077 $ (installed_radioimage_target )/
  6. 1078 $ (installed_recoveryimage_target )/
  7. 1079 $ (installed_factoryimage_target )/
  8. 1080 $ (installed_systemimage )/
  9. 1081 $ (installed_userdataimage_target )/
  10. 1082 $ (installed_secroimage_target )/
  11. 1083 $ (installed_android_info_txt_target )/
  12. 1084 $ (built_ota_tools )/
  13. 1085 $ (apkcerts_file )/
  14. 1086 $ (host_out_executables)/fs_config/
  15. 1087 | $ (ACP)
  16. 1088 @ echo "package target files: $ @"
  17. 1089 $ (hide) Rm-RF $ @ $ (zip_root)
  18. 1090 $ (hide) mkdir-p $ (DIR $ @) $ (zip_root)
  19. 1091 @ # components of the recovery Image
  20. 1092 $ (hide) mkdir-p $ (zip_root)/recovery
  21. 1093 $ (hide) $ (call package_files-copy-root ,/
  22. 1094 $ (target_recovery_root_out), $ (zip_root)/recovery/ramdisk)
  23. 1095 ifdef installed_kernel_target
  24. 1096 $ (hide) $ (ACP) $ (installed_kernel_target) $ (zip_root)/recovery/kernel
  25. 1097 $ (hide) $ (ACP) $ (recovery_ramdisk) $ (zip_root)/recovery/ramdisk
  26. 1098 endif
  27. 1099 ifdef installed_2ndbootloader_target
  28. 1100 $ (hide) $ (ACP )/
  29. 1101 $ (installed_2ndbootloader_target) $ (zip_root)/recovery/second
  30. 1102 endif
  31. 1103 ifdef board_kernel_1_line
  32. 1104 $ (hide) echo "$ (board_kernel_cmdline)" >$ (zip_root)/recovery/cmdline
  33. 1105 endif
  34. 1106 ifdef board_kernel_base
  35. 1107 $ (hide) echo "$ (board_kernel_base)"> $ (zip_root)/recovery/base
  36. 1108 endif
  37. 1109 @ # components of the factory Image
  38. 1110 $ (hide) mkdir-p $ (zip_root)/factory
  39. 1111 $ (hide) $ (call package_files-copy-root ,/
  40. 1112 $ (target_factory_root_out), $ (zip_root)/Factory/ramdisk)
  41. 1113 ifdef installed_kernel_target
  42. 1114 $ (hide) $ (ACP) $ (installed_kernel_target) $ (zip_root)/Factory/kernel
  43. 1115 endif
  44. 1116 ifdef installed_2ndbootloader_target
  45. 1117 $ (hide) $ (ACP )/
  46. 1118 $ (installed_2ndbootloader_target) $ (zip_root)/Factory/second
  47. 1119 endif
  48. 1120 ifdef board_kernel_1_line
  49. 1121 $ (hide) echo "$ (board_kernel_cmdline)" >$ (zip_root)/Factory/export line
  50. 1122 endif
  51. 1123 ifdef board_kernel_base
  52. 1124 $ (hide) echo "$ (board_kernel_base)"> $ (zip_root)/Factory/base
  53. 1125 endif
  54. 1126 @ # components of the Boot Image
  55. 1127 $ (hide) mkdir-p $ (zip_root)/boot
  56. 1128 $ (hide) $ (call package_files-copy-root ,/
  57. 1129 $ (target_root_out), $ (zip_root)/boot/ramdisk)
  58. 1130 ifdef installed_kernel_target
  59. 1131 $ (hide) $ (ACP) $ (installed_kernel_target) $ (zip_root)/boot/kernel
  60. 1132 $ (hide) $ (ACP) $ (installed_ramdisk_target) $ (zip_root)/boot/ramdisk
  61. 1133 endif
  62. 1134 ifdef installed_2ndbootloader_target
  63. 1135 $ (hide) $ (ACP )/
  64. 1136 $ (installed_2ndbootloader_target) $ (zip_root)/boot/second
  65. 1137 endif
  66. 1138 ifdef board_kernel_1_line
  67. 1139 $ (hide) echo "$ (board_kernel_cmdline)" >$ (zip_root)/boot/cmdline
  68. 1140 endif
  69. 1141 ifdef board_kernel_base
  70. 1142 $ (hide) echo "$ (board_kernel_base)"> $ (zip_root)/boot/base
  71. 1143 endif
  72. 1144 $ (hide) $ (foreach T, $ (installed_radioimage_target ),/
  73. 1145 mkdir-p $ (zip_root)/Radio ;/
  74. 1146 $ (ACP) $ (t) $ (zip_root)/Radio/$ (notdir $ (t ));)
  75. 1147 @ # contents of the System Image
  76. 1148 $ (hide) $ (call package_files-copy-root ,/
  77. 1149 $ (systemimage_source_dir), $ (zip_root)/System)
  78. 1150 @ # contents of the data image
  79. 1151 $ (hide) $ (call package_files-copy-root ,/
  80. 1152 $ (target_out_data), $ (zip_root)/data)
  81. 1153 @ # extra contents of the OTA package
  82. 1154 $ (hide) mkdir-p $ (zip_root)/OTA/bin
  83. 1155 $ (hide) $ (ACP) $ (installed_android_info_txt_target) $ (zip_root)/OTA/
  84. 1156 $ (hide) $ (ACP) $ (private_ota_tools) $ (zip_root)/OTA/bin/
  85. 1157 @ # files that do not end up in any images, but are necessary
  86. 1158 @ # build them.
  87. 1159 $ (hide) mkdir-p $ (zip_root)/meta
  88. 1160 $ (hide) $ (ACP) $ (apkcerts_file) $ (zip_root)/META/apkcerts.txt
  89. 1161 $ (hide) echo "$ (product_ota_public_keys)" >$ (zip_root)/META/otakeys.txt
  90. 1162 $ (hide) echo "$ (private_recovery_api_version)"> $ (zip_root)/META/recovery-api-version.txt
  91. 1163 $ (hide) echo "blocksize $ (board_flash_block_size)" >$ (zip_root)/META/imagesizes.txt
  92. 1164 $ (hide) echo "Boot $ (call image-size-from-data-size, $ (board_bootimage_partition_size)" >$ (zip_root)/META/imagesizes.txt
  93. 1165 $ (hide) echo "recovery $ (call image-size-from-data-size, $ (board_recoveryimage_partition_size)" >$ (zip_root)/META/imagesizes.txt
  94. 1166 $ (hide) echo "system $ (call image-size-from-data-size, $ (board_systemimage_partition_size)" >$ (zip_root)/META/imagesizes.txt
  95. 1167 $ (hide) echo "secro $ (call image-size-from-data-size, $ (board_secroimage_partition_size)" >$ (zip_root)/META/imagesizes.txt
  96. 1168 $ (hide) echo "userdata $ (call image-size-from-data-size, $ (board_userdataimage_partition_size)" >$ (zip_root)/META/imagesizes.txt
  97. 1169 $ (hide) echo "$ (tool_extensions)"> $ (zip_root)/META/tool-extensions.txt
  98. 1170 @ # zip everything up, preserving symlinks
  99. 1171 $ (hide) (CD $ (zip_root) & zip-qry ../$ (notdir $ @).)
  100. 1172 @ # Run fs_config on all the system files in the zip, and save the output
  101. 1173 $ (hide) zipinfo-1 $ @ | awk-F/'in in {OFS = "/"}/^ system // {$1 = "system "; print} '| $ (host_out_executables)/fs_config> $ (zip_root)/META/filesystem_config.txt
  102. 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)

  1. 1186 name: = $ (target_product)
  2. 1187 ifeq ($ (target_build_type), debug)
  3. 1188 name: = $ (name) _ debug
  4. 1189 endif
  5. 1190 name: = $ (name)-Ota-$ (file_name_tag)
  6. 1191
  7. 1192 internal_ota_package_target: = $ (product_out)/queues (name).zip
  8. 1193
  9. 1194 $ (internal_ota_package_target): key_cert_pair :=$ (default_key_cert_pair)
  10. 1195
  11. 1196 ifeq ($ (target_ota_script_mode ),)
  12. 1197 # default to "Auto"
  13. 1198 $ (internal_ota_package_target): scriptmode: = auto
  14. 1199 else
  15. 1200 $ (internal_ota_package_target): scriptmode :=$ (target_ota_script_mode)
  16. 1201 endif
  17. 1202
  18. 1203 $ (internal_ota_package_target): $ (built_target_files_package) $ (otatools)
  19. 1204 @ echo "package Ota: $ @"
  20. 1205 $ (hide)./build/tools/releasetools/ota_from_target_files/
  21. 1206-M $ (scriptmode )/
  22. 1207-p $ (host_out )/
  23. 1208-K $ (key_cert_pair )/
  24. 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

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.