点击打开链接
一、update.zip包目录结构详解
     1、boot.img是更新boot分区所需要的文件。这个boot.img主要包括kernel+ramdisk。
     2、system/目录的内容在升级后会放在系统的system分区。主要用来更新系统的一些应用或则应用会用到的一些库等等。可以将Android源码编译out/target/product/tcc8800/system/中的所有文件拷贝到这个目录来代替。
     3、recovery/目录中的recovery-from-boot.p是boot.img和recovery.img的补丁(patch),主要用来更新recovery分区,其中etc/目录下的install-recovery.sh是更新脚本。
     4、update-binary是一个二进制文件,相当于一个脚本解释器,能够识别updater-script中描述的操作。该文件在Android源码编译后out/target/product/tcc8800/system bin/updater生成,可将updater重命名为update-binary得到。该文件在具体的更新包中的名字由源码中bootable/recovery/install.c中的宏ASSUMED_UPDATE_BINARY_NAME的值而定。
     5、updater-script:此文件是一个脚本文件,具体描述了更新过程。我们可以根据具体情况编写该脚本来适应我们的具体需求。该文件的命名由源码中bootable/recovery/updater/updater.c文件中的宏SCRIPT_NAME的值而定。
     6、metadata文件是描述设备信息及环境变量的元数据。主要包括一些编译选项,签名公钥,时间戳以及设备型号等。
     7、我们还可以在包中添加userdata目录,来更新系统中的用户数据部分。这部分内容在更新后会存放在系统的/data目录下。
     8、update.zip包的签名:update.zip更新包在制作完成后需要对其签名,否则在升级时会出现认证失败的错误提示。而且签名要使用和目标板一致的加密公钥。加密公钥及加密需要的三个文件在Android源码编译后生成的具体路径为:
         out/host/Linux-x86/framework/signapk.jar 
         build/target/product/security/testkey.x509.pem         
         build/target/product/security/testkey.pk8 。
         我们用命令make otapackage制作生成的update.zip包是已签过名的,如果自己做update.zip包时必须手动对其签名。
         具体的加密方法:$ java –jar gingerbread/out/host/linux/framework/signapk.jar –w gingerbread/build/target/product/security/testkey.x509.pem                                      gingerbread/build/target/product/security/testkey.pk8 update.zip update_signed.zip
         以上命令在update.zip包所在的路径下执行,其中signapk.jar testkey.x509.pem以及testkey.pk8文件的引用使用绝对路径。update.zip 是我们已经打好的包,update_signed.zip包是命令执行完生成的已经签过名的包。
     9、MANIFEST.MF:这个manifest文件定义了与包的组成结构相关的数据。类似Android应用的mainfest.xml文件。

10、CERT.RSA:与签名文件相关联的签名程序块文件,它存储了用于签名JAR文件的公共签名

11、CERT.SF:这是JAR文件的签名文件,其中前缀CERT代表签名者。


二、Android升级包update.zip的生成过程分析

        1.命令制作。Android源码系统中为我们提供了制作update.zip刷机包的命令,即make otapackage。该命令在编译源码完成后并在源码根目录下执行。 具体操作方式:在源码根目录下执行
                ①$ source build/envsetup.sh。 
                ②$ lunch 然后选择你需要的配置(如17)。
                ③$ make otapackage。
        2.使用make otapackage命令生成update.zip的过程分析。
            在源码根目录下执行make otapackage命令生成update.zip包主要分为两步,第一步是根据Makefile执行编译生成一个update原包(zip格式)。第二步是运行一个python脚本,并以上一步准备的zip包作为输入,最终生成我们需要的升级包。下面进一步分析这两个过程。

[python] view plaincopyprint?
  1. <span style="font-size:14px;"># A zip of the directories that map to the target filesystem.
  2. # This zip can be used to create an OTA package or filesystem image
  3. # as a post-build step.
  4. #
  5. name := $(TARGET_PRODUCT)
  6. ifeq ($(TARGET_BUILD_TYPE),debug)
  7. name := $(name)_debug
  8. endif
  9. name := $(name)-target_files-$(FILE_NAME_TAG)
  10. intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
  11. BUILT_TARGET_FILES_PACKAGE := $(intermediates)/$(name).zip
  12. $(BUILT_TARGET_FILES_PACKAGE): intermediates := $(intermediates)
  13. $(BUILT_TARGET_FILES_PACKAGE): \
  14. zip_root := $(intermediates)/$(name)
  15. # $(1): Directory to copy
  16. # $(2): Location to copy it to
  17. # The "ls -A" is to prevent "acp s/* d" from failing if s is empty.
  18. define package_files-copy-root
  19. if [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \
  20. mkdir -p $(2) && \
  21. $(ACP) -rd $(strip $(1))/* $(2); \
  22. fi
  23. endef
  24. built_ota_tools := \
  25. $(call intermediates-dir-for,EXECUTABLES,applypatch)/applypatch \
  26. $(call intermediates-dir-for,EXECUTABLES,applypatch_static)/applypatch_static \
  27. $(call intermediates-dir-for,EXECUTABLES,check_prereq)/check_prereq \
  28. $(call intermediates-dir-for,EXECUTABLES,sqlite3)/sqlite3 \
  29. $(call intermediates-dir-for,EXECUTABLES,updater)/updater
  30. $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_OTA_TOOLS := $(built_ota_tools)
  31. $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_API_VERSION := $(RECOVERY_API_VERSION)
  32. $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_FSTAB_VERSION := $(RECOVERY_FSTAB_VERSION)
  33. ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
  34. # default to common dir for device vendor
  35. $(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_DEVICE_DIR)/../common
  36. else
  37. $(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
  38. endif
  39. # Depending on the various images guarantees that the underlying
  40. # directories are up-to-date.
  41. $(BUILT_TARGET_FILES_PACKAGE): \
  42. $(INSTALLED_BOOTIMAGE_TARGET) \
  43. $(INSTALLED_RADIOIMAGE_TARGET) \
  44. $(INSTALLED_RECOVERYIMAGE_TARGET) \
  45. $(INSTALLED_SYSTEMIMAGE) \
  46. $(INSTALLED_USERDATAIMAGE_TARGET) \
  47. $(INSTALLED_CACHEIMAGE_TARGET) \
  48. $(INSTALLED_VENDORIMAGE_TARGET) \
  49. $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
  50. $(SELINUX_FC) \
  51. $(built_ota_tools) \
  52. $(APKCERTS_FILE) \
  53. $(HOST_OUT_EXECUTABLES)/fs_config \
  54. | $(ACP)
  55. @echo "Package target files: $@"
  56. $(hide) rm -rf $@ $(zip_root)
  57. $(hide) mkdir -p $(dir $@) $(zip_root)
  58. @# Components of the recovery image
  59. $(hide) mkdir -p $(zip_root)/RECOVERY
  60. $(hide) $(call package_files-copy-root, \
  61. $(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/RECOVERY/RAMDISK)
  62. ifdef INSTALLED_KERNEL_TARGET
  63. $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/RECOVERY/kernel
  64. endif
  65. ifdef INSTALLED_2NDBOOTLOADER_TARGET
  66. $(hide) $(ACP) \
  67. $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/RECOVERY/second
  68. endif
  69. ifdef BOARD_KERNEL_CMDLINE
  70. $(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/RECOVERY/cmdline
  71. endif
  72. ifdef BOARD_KERNEL_BASE
  73. $(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/RECOVERY/base
  74. endif
  75. ifdef BOARD_KERNEL_PAGESIZE
  76. $(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/RECOVERY/pagesize
  77. endif
  78. @# Components of the boot image
  79. $(hide) mkdir -p $(zip_root)/BOOT
  80. $(hide) $(call package_files-copy-root, \
  81. $(TARGET_ROOT_OUT),$(zip_root)/BOOT/RAMDISK)
  82. ifdef INSTALLED_KERNEL_TARGET
  83. $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/BOOT/kernel
  84. endif
  85. ifdef INSTALLED_2NDBOOTLOADER_TARGET
  86. $(hide) $(ACP) \
  87. $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second
  88. endif
  89. ifdef BOARD_KERNEL_CMDLINE
  90. $(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
  91. endif
  92. ifdef BOARD_KERNEL_BASE
  93. $(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base
  94. endif
  95. ifdef BOARD_KERNEL_PAGESIZE
  96. $(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/BOOT/pagesize
  97. endif
  98. $(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),\
  99. mkdir -p $(zip_root)/RADIO; \
  100. $(ACP) $(t) $(zip_root)/RADIO/$(notdir $(t));)
  101. @# Contents of the system image
  102. $(hide) $(call package_files-copy-root, \
  103. $(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
  104. @# Contents of the data image
  105. $(hide) $(call package_files-copy-root, \
  106. $(TARGET_OUT_DATA),$(zip_root)/DATA)
  107. ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
  108. @# Contents of the vendor image
  109. $(hide) $(call package_files-copy-root, \
  110. $(TARGET_OUT_VENDOR),$(zip_root)/VENDOR)
  111. endif
  112. @# Extra contents of the OTA package
  113. $(hide) mkdir -p $(zip_root)/OTA/bin
  114. $(hide) $(ACP) $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/
  115. $(hide) $(ACP) $(PRIVATE_OTA_TOOLS) $(zip_root)/OTA/bin/
  116. @# Files that do not end up in any images, but are necessary to
  117. @# build them.
  118. $(hide) mkdir -p $(zip_root)/META
  119. $(hide) $(ACP) $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
  120. $(hide)echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
  121. $(hide) echo "recovery_api_version=$(PRIVATE_RECOVERY_API_VERSION)" > $(zip_root)/META/misc_info.txt
  122. $(hide) echo "fstab_version=$(PRIVATE_RECOVERY_FSTAB_VERSION)" >> $(zip_root)/META/misc_info.txt
  123. ifdef BOARD_FLASH_BLOCK_SIZE
  124. $(hide) echo "blocksize=$(BOARD_FLASH_BLOCK_SIZE)" >> $(zip_root)/META/misc_info.txt
  125. endif
  126. ifdef BOARD_BOOTIMAGE_PARTITION_SIZE
  127. $(hide) echo "boot_size=$(BOARD_BOOTIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
  128. endif
  129. ifdef BOARD_RECOVERYIMAGE_PARTITION_SIZE
  130. $(hide) echo "recovery_size=$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
  131. endif
  132. $(hide) echo "tool_extensions=$(tool_extensions)" >> $(zip_root)/META/misc_info.txt
  133. $(hide) echo "default_system_dev_certificate=$(DEFAULT_SYSTEM_DEV_CERTIFICATE)" >> $(zip_root)/META/misc_info.txt
  134. ifdef PRODUCT_EXTRA_RECOVERY_KEYS
  135. $(hide) echo "extra_recovery_keys=$(PRODUCT_EXTRA_RECOVERY_KEYS)" >> $(zip_root)/META/misc_info.txt
  136. endif
  137. $(hide) echo "mkbootimg_args=$(BOARD_MKBOOTIMG_ARGS)" >> $(zip_root)/META/misc_info.txt
  138. $(hide) echo "use_set_metadata=1" >> $(zip_root)/META/misc_info.txt
  139. $(hide) echo "update_rename_support=1" >> $(zip_root)/META/misc_info.txt
  140. $(call generate-userimage-prop-dictionary, $(zip_root)/META/misc_info.txt)
  141. @# Zip everything up, preserving symlinks
  142. $(hide) (cd $(zip_root) && zip -qry ../$(notdir $@) .)
  143. @# Run fs_config on all the system, boot ramdisk, and recovery ramdisk files in the zip, and save the output
  144. $(hide) zipinfo -1 $@ | awk 'BEGIN { FS="SYSTEM/" } /^SYSTEM\// {print "system/" $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/filesystem_config.txt
  145. $(hide) zipinfo -1 $@ | awk 'BEGIN { FS="BOOT/RAMDISK/" } /^BOOT\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/boot_filesystem_config.txt
  146. $(hide) zipinfo -1 $@ | awk 'BEGIN { FS="RECOVERY/RAMDISK/" } /^RECOVERY\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/recovery_filesystem_config.txt
  147. $(hide) (cd $(zip_root) && zip -q ../$(notdir $@) META/*filesystem_config.txt)
  148. .PHONY: target-files-package
  149. target-files-package: $(BUILT_TARGET_FILES_PACKAGE)
  150. ifneq ($(TARGET_PRODUCT),sdk)
  151. ifeq ($(filter generic%,$(TARGET_DEVICE)),)
  152. ifneq ($(TARGET_NO_KERNEL),true)
  153. ifneq ($(recovery_fstab),)<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">     </span></span>
<span style="font-size:14px;"># A zip of the directories that map to the target filesystem.
# This zip can be used to create an OTA package or filesystem image
# as a post-build step.
#
name := $(TARGET_PRODUCT)
ifeq ($(TARGET_BUILD_TYPE),debug)name := $(name)_debug
endif
name := $(name)-target_files-$(FILE_NAME_TAG)intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
BUILT_TARGET_FILES_PACKAGE := $(intermediates)/$(name).zip
$(BUILT_TARGET_FILES_PACKAGE): intermediates := $(intermediates)
$(BUILT_TARGET_FILES_PACKAGE): \
zip_root := $(intermediates)/$(name)# $(1): Directory to copy
# $(2): Location to copy it to
# The "ls -A" is to prevent "acp s/* d" from failing if s is empty.
define package_files-copy-rootif [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \mkdir -p $(2) && \$(ACP) -rd $(strip $(1))/* $(2); \fi
endefbuilt_ota_tools := \
$(call intermediates-dir-for,EXECUTABLES,applypatch)/applypatch \
$(call intermediates-dir-for,EXECUTABLES,applypatch_static)/applypatch_static \
$(call intermediates-dir-for,EXECUTABLES,check_prereq)/check_prereq \
$(call intermediates-dir-for,EXECUTABLES,sqlite3)/sqlite3 \
$(call intermediates-dir-for,EXECUTABLES,updater)/updater
$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_OTA_TOOLS := $(built_ota_tools)$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_API_VERSION := $(RECOVERY_API_VERSION)
$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_FSTAB_VERSION := $(RECOVERY_FSTAB_VERSION)ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
# default to common dir for device vendor
$(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_DEVICE_DIR)/../common
else
$(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
endif# Depending on the various images guarantees that the underlying
# directories are up-to-date.
$(BUILT_TARGET_FILES_PACKAGE): \
$(INSTALLED_BOOTIMAGE_TARGET) \
$(INSTALLED_RADIOIMAGE_TARGET) \
$(INSTALLED_RECOVERYIMAGE_TARGET) \
$(INSTALLED_SYSTEMIMAGE) \
$(INSTALLED_USERDATAIMAGE_TARGET) \
$(INSTALLED_CACHEIMAGE_TARGET) \
$(INSTALLED_VENDORIMAGE_TARGET) \
$(INSTALLED_ANDROID_INFO_TXT_TARGET) \
$(SELINUX_FC) \
$(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/kernel
endif
ifdef INSTALLED_2NDBOOTLOADER_TARGET
$(hide) $(ACP) \
$(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/RECOVERY/second
endif
ifdef BOARD_KERNEL_CMDLINE
$(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/RECOVERY/cmdline
endif
ifdef BOARD_KERNEL_BASE
$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/RECOVERY/base
endif
ifdef BOARD_KERNEL_PAGESIZE
$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/RECOVERY/pagesize
endif
@# 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/kernel
endif
ifdef INSTALLED_2NDBOOTLOADER_TARGET
$(hide) $(ACP) \
$(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second
endif
ifdef BOARD_KERNEL_CMDLINE
$(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
endif
ifdef BOARD_KERNEL_BASE
$(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base
endif
ifdef BOARD_KERNEL_PAGESIZE
$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/BOOT/pagesize
endif
$(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)
ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
@# Contents of the vendor image
$(hide) $(call package_files-copy-root, \
$(TARGET_OUT_VENDOR),$(zip_root)/VENDOR)
endif
@# 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 any images, 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.txt
$(hide) echo "fstab_version=$(PRIVATE_RECOVERY_FSTAB_VERSION)" >> $(zip_root)/META/misc_info.txt
ifdef BOARD_FLASH_BLOCK_SIZE
$(hide) echo "blocksize=$(BOARD_FLASH_BLOCK_SIZE)" >> $(zip_root)/META/misc_info.txt
endif
ifdef BOARD_BOOTIMAGE_PARTITION_SIZE
$(hide) echo "boot_size=$(BOARD_BOOTIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
endif
ifdef BOARD_RECOVERYIMAGE_PARTITION_SIZE
$(hide) echo "recovery_size=$(BOARD_RECOVERYIMAGE_PARTITION_SIZE)" >> $(zip_root)/META/misc_info.txt
endif
$(hide) echo "tool_extensions=$(tool_extensions)" >> $(zip_root)/META/misc_info.txt
$(hide) echo "default_system_dev_certificate=$(DEFAULT_SYSTEM_DEV_CERTIFICATE)" >> $(zip_root)/META/misc_info.txt
ifdef PRODUCT_EXTRA_RECOVERY_KEYS
$(hide) echo "extra_recovery_keys=$(PRODUCT_EXTRA_RECOVERY_KEYS)" >> $(zip_root)/META/misc_info.txt
endif
$(hide) echo "mkbootimg_args=$(BOARD_MKBOOTIMG_ARGS)" >> $(zip_root)/META/misc_info.txt
$(hide) echo "use_set_metadata=1" >> $(zip_root)/META/misc_info.txt
$(hide) echo "update_rename_support=1" >> $(zip_root)/META/misc_info.txt
$(call generate-userimage-prop-dictionary, $(zip_root)/META/misc_info.txt)
@# Zip everything up, preserving symlinks
$(hide) (cd $(zip_root) && zip -qry ../$(notdir $@) .)
@# Run fs_config on all the system, boot ramdisk, and recovery ramdisk files in the zip, and save the output
$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="SYSTEM/" } /^SYSTEM\// {print "system/" $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/filesystem_config.txt
$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="BOOT/RAMDISK/" } /^BOOT\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/boot_filesystem_config.txt
$(hide) zipinfo -1 $@ | awk 'BEGIN { FS="RECOVERY/RAMDISK/" } /^RECOVERY\/RAMDISK\// {print $$2}' | $(HOST_OUT_EXECUTABLES)/fs_config -C -S $(SELINUX_FC) > $(zip_root)/META/recovery_filesystem_config.txt
$(hide) (cd $(zip_root) && zip -q ../$(notdir $@) META/*filesystem_config.txt).PHONY: target-files-package
target-files-package: $(BUILT_TARGET_FILES_PACKAGE)ifneq ($(TARGET_PRODUCT),sdk)
ifeq ($(filter generic%,$(TARGET_DEVICE)),)
ifneq ($(TARGET_NO_KERNEL),true)
ifneq ($(recovery_fstab),)<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">      </span></span>

根据上面的Makefile可以分析这个包的生成过程:
    首先创建一个root_zip根目录,并依次在此目录下创建所需要的如下其他目录
    1)创建RECOVERY目录,并填充该目录的内容,包括kernel的镜像和recovery根文件系统的镜像。此目录最终用于生成recovery.img。
    2)创建并填充BOOT目录。包含kernel和cmdline以及pagesize大小等,该目录最终用来生成boot.img。
    3)向SYSTEM目录填充system image。
    4)向DATA填充data image。
    5)用于生成OTA package包所需要的额外的内容。主要包括一些bin命令。
    6)创建META目录并向该目录下添加一些文本文件,如apkcerts.txt(描述apk文件用到的认证证书),misc_info.txt(描述Flash内存的块大小以及boot、recovery、system、userdata等分区的大小信息)。
    7)使用保留连接选项压缩我们在上面获得的root_zip目录。
    8)使用fs_config(build/tools/fs_config)配置上面的zip包内所有的系统文件(system/下各目录、文件)的权限属主等信息。fs_config包含了一个头文件#include“private/android_filesystem_config.h”。在这个头文件中以硬编码的方式设定了system目录下各文件的权限、属主。执行完配置后会将配置后的信息以文本方式输出 到META/filesystem_config.txt中。并再一次zip压缩成我们最终需要的原始包。
    然后上面的zip包只是一个编译过程中生成的原始包。这个原始zip包在实际的编译过程中有两个作用,一是用来生成OTA update升级包,二是用来生成系统镜像,在编译过程中若生成OTA update升级包时会调用(具体位置在Makefile的1037行到1058行)一个名为 ota_from_target_files 的Python脚本,位置在/build/tools/releasetools/ota_from_target_files。这个脚本的作用是以第一步生成的zip原始包作为输入,最终生成可用的OTA升级zip包。
    下面我们分析使用这个脚本生成最终OTA升级包的过程。
    首先看一下这个脚本开始部分的帮助文档。代码如下:

[python] view plaincopyprint?
  1. <span style="font-size:14px;"># Copyright (C) 2008 The Android Open Source Project
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. #      http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """
  15. Given a target-files zipfile, produces an OTA package that installs
  16. that build.  An incremental OTA is produced if -i is given, otherwise
  17. a full OTA is produced.
  18. Usage:  ota_from_target_files [flags] input_target_files output_ota_package
  19. -b  (--board_config)  <file>
  20. Deprecated.
  21. -k (--package_key) <key> Key to use to sign the package (default is
  22. the value of default_system_dev_certificate from the input
  23. target-files's META/misc_info.txt, or
  24. "build/target/product/security/testkey" if that value is not
  25. specified).
  26. For incremental OTAs, the default value is based on the source
  27. target-file, not the target build.
  28. -i  (--incremental_from)  <file>
  29. Generate an incremental OTA using the given target-files zip as
  30. the starting build.
  31. -w  (--wipe_user_data)
  32. Generate an OTA package that will wipe the user data partition
  33. when installed.
  34. -n  (--no_prereq)
  35. Omit the timestamp prereq check normally included at the top of
  36. the build scripts (used for developer OTA packages which
  37. legitimately need to go back and forth).
  38. -e  (--extra_script)  <file>
  39. Insert the contents of file at the end of the update script.
  40. -a  (--aslr_mode)  <on|off>
  41. Specify whether to turn on ASLR for the package (on by default).
  42. </span>
<span style="font-size:14px;"># Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License."""
Given a target-files zipfile, produces an OTA package that installs
that build.  An incremental OTA is produced if -i is given, otherwise
a full OTA is produced.Usage:  ota_from_target_files [flags] input_target_files output_ota_package-b  (--board_config)  <file>Deprecated.-k (--package_key) <key> Key to use to sign the package (default isthe value of default_system_dev_certificate from the inputtarget-files's META/misc_info.txt, or"build/target/product/security/testkey" if that value is notspecified).For incremental OTAs, the default value is based on the sourcetarget-file, not the target build.-i  (--incremental_from)  <file>Generate an incremental OTA using the given target-files zip asthe starting build.-w  (--wipe_user_data)Generate an OTA package that will wipe the user data partitionwhen installed.-n  (--no_prereq)Omit the timestamp prereq check normally included at the top ofthe build scripts (used for developer OTA packages whichlegitimately need to go back and forth).-e  (--extra_script)  <file>Insert the contents of file at the end of the update script.-a  (--aslr_mode)  <on|off>Specify whether to turn on ASLR for the package (on by default).</span>

下面简单翻译一下他们的使用方法以及选项的作用。
    Usage: ota_from_target_files [flags] input_target_files output_ota_package
    -b 过时的。
    -k签名所使用的密钥
    -i生成增量OTA包时使用此选项。后面我们会用到这个选项来生成OTA增量包。
    -w是否清除userdata分区
    -n在升级时是否不检查时间戳,缺省要检查,即缺省情况下只能基于旧版本升级。
    -e是否有额外运行的脚本
    -m执行过程中生成脚本(updater-script)所需要的格式,目前有两种即amend和edify。对应上两种版本升级时会采用不同的解释器。缺省会同时生成两种格式的脚 本。
    -p定义脚本用到的一些可执行文件的路径。
    -s定义额外运行脚本的路径。
    -x定义额外运行的脚本可能用的键值对。
    -v执行过程中打印出执行的命令。
    -h命令帮助

下面分析ota_from_target_files这个python脚本是怎样生成最终zip包的。先讲这个脚本的代码贴出来如下:

[python] view plaincopyprint?
  1. <span style="font-size:14px;">import sys
  2. if sys.hexversion < 0x02040000:
  3. print >> sys.stderr, "Python 2.4 or newer is required."
  4. sys.exit(1)
  5. import copy
  6. import errno
  7. import os
  8. import re
  9. import subprocess
  10. import tempfile
  11. import time
  12. import zipfile
  13. try:
  14. from hashlib import sha1 as sha1
  15. except ImportError:
  16. from sha import sha as sha1
  17. import common
  18. import edify_generator
  19. OPTIONS = common.OPTIONS
  20. OPTIONS.package_key = None
  21. OPTIONS.incremental_source = None
  22. OPTIONS.require_verbatim = set()
  23. OPTIONS.prohibit_verbatim = set(("system/build.prop",))
  24. OPTIONS.patch_threshold = 0.95
  25. OPTIONS.wipe_user_data = False
  26. OPTIONS.omit_prereq = False
  27. OPTIONS.extra_script = None
  28. OPTIONS.aslr_mode = True
  29. OPTIONS.worker_threads = 3
  30. def MostPopularKey(d, default):
  31. """Given a dict, return the key corresponding to the largest
  32. value.  Returns 'default' if the dict is empty."""
  33. x = [(v, k) for (k, v) in d.iteritems()]
  34. if not x: return default
  35. x.sort()
  36. return x[-1][1]
  37. def IsSymlink(info):
  38. """Return true if the zipfile.ZipInfo object passed in represents a
  39. symlink."""
  40. return (info.external_attr >> 16) == 0120777
  41. def IsRegular(info):
  42. """Return true if the zipfile.ZipInfo object passed in represents a
  43. symlink."""
  44. return (info.external_attr >> 28) == 010
  45. def ClosestFileMatch(src, tgtfiles, existing):
  46. """Returns the closest file match between a source file and list
  47. of potential matches.  The exact filename match is preferred,
  48. then the sha1 is searched for, and finally a file with the same
  49. basename is evaluated.  Rename support in the updater-binary is
  50. required for the latter checks to be used."""
  51. result = tgtfiles.get("path:" + src.name)
  52. if result is not None:
  53. return result
  54. if not OPTIONS.target_info_dict.get("update_rename_support", False):
  55. return None
  56. if src.size < 1000:
  57. return None
  58. result = tgtfiles.get("sha1:" + src.sha1)
  59. if result is not None and existing.get(result.name) is None:
  60. return result
  61. result = tgtfiles.get("file:" + src.name.split("/")[-1])
  62. if result is not None and existing.get(result.name) is None:
  63. return result
  64. return None
  65. class Item:
  66. """Items represent the metadata (user, group, mode) of files and
  67. directories in the system image."""
  68. ITEMS = {}
  69. def __init__(self, name, dir=False):
  70. self.name = name
  71. self.uid = None
  72. self.gid = None
  73. self.mode = None
  74. self.selabel = None
  75. self.capabilities = None
  76. self.dir = dir
  77. if name:
  78. self.parent = Item.Get(os.path.dirname(name), dir=True)
  79. self.parent.children.append(self)
  80. else:
  81. self.parent = None
  82. if dir:
  83. self.children = []
  84. def Dump(self, indent=0):
  85. if self.uid is not None:
  86. print "%s%s %d %d %o" % ("  "*indent, self.name, self.uid, self.gid, self.mode)
  87. else:
  88. print "%s%s %s %s %s" % ("  "*indent, self.name, self.uid, self.gid, self.mode)
  89. if self.dir:
  90. print "%s%s" % ("  "*indent, self.descendants)
  91. print "%s%s" % ("  "*indent, self.best_subtree)
  92. for i in self.children:
  93. i.Dump(indent=indent+1)
  94. @classmethod
  95. def Get(cls, name, dir=False):
  96. if name not in cls.ITEMS:
  97. cls.ITEMS[name] = Item(name, dir=dir)
  98. return cls.ITEMS[name]
  99. @classmethod
  100. def GetMetadata(cls, input_zip):
  101. # The target_files contains a record of what the uid,
  102. # gid, and mode are supposed to be.
  103. output = input_zip.read("META/filesystem_config.txt")
  104. for line in output.split("\n"):
  105. if not line: continue
  106. columns = line.split()
  107. name, uid, gid, mode = columns[:4]
  108. selabel = None
  109. capabilities = None
  110. # After the first 4 columns, there are a series of key=value
  111. # pairs. Extract out the fields we care about.
  112. for element in columns[4:]:
  113. key, value = element.split("=")
  114. if key == "selabel":
  115. selabel = value
  116. if key == "capabilities":
  117. capabilities = value
  118. i = cls.ITEMS.get(name, None)
  119. if i is not None:
  120. i.uid = int(uid)
  121. i.gid = int(gid)
  122. i.mode = int(mode, 8)
  123. i.selabel = selabel
  124. i.capabilities = capabilities
  125. if i.dir:
  126. i.children.sort(key=lambda i: i.name)
  127. # set metadata for the files generated by this script.
  128. i = cls.ITEMS.get("system/recovery-from-boot.p", None)
  129. if i: i.uid, i.gid, i.mode, i.selabel, i.capabilities = 0, 0, 0644, None, None
  130. i = cls.ITEMS.get("system/etc/install-recovery.sh", None)
  131. if i: i.uid, i.gid, i.mode, i.selabel, i.capabilities = 0, 0, 0544, None, None
  132. def CountChildMetadata(self):
  133. """Count up the (uid, gid, mode, selabel, capabilities) tuples for
  134. all children and determine the best strategy for using set_perm_recursive and
  135. set_perm to correctly chown/chmod all the files to their desired
  136. values.  Recursively calls itself for all descendants.
  137. Returns a dict of {(uid, gid, dmode, fmode, selabel, capabilities): count} counting up
  138. all descendants of this node.  (dmode or fmode may be None.)  Also
  139. sets the best_subtree of each directory Item to the (uid, gid,
  140. dmode, fmode, selabel, capabilities) tuple that will match the most
  141. descendants of that Item.
  142. """
  143. assert self.dir
  144. d = self.descendants = {(self.uid, self.gid, self.mode, None, self.selabel, self.capabilities): 1}
  145. for i in self.children:
  146. if i.dir:
  147. for k, v in i.CountChildMetadata().iteritems():
  148. d[k] = d.get(k, 0) + v
  149. else:
  150. k = (i.uid, i.gid, None, i.mode, i.selabel, i.capabilities)
  151. d[k] = d.get(k, 0) + 1
  152. # Find the (uid, gid, dmode, fmode, selabel, capabilities)
  153. # tuple that matches the most descendants.
  154. # First, find the (uid, gid) pair that matches the most
  155. # descendants.
  156. ug = {}
  157. for (uid, gid, _, _, _, _), count in d.iteritems():
  158. ug[(uid, gid)] = ug.get((uid, gid), 0) + count
  159. ug = MostPopularKey(ug, (0, 0))
  160. # Now find the dmode, fmode, selabel, and capabilities that match
  161. # the most descendants with that (uid, gid), and choose those.
  162. best_dmode = (0, 0755)
  163. best_fmode = (0, 0644)
  164. best_selabel = (0, None)
  165. best_capabilities = (0, None)
  166. for k, count in d.iteritems():
  167. if k[:2] != ug: continue
  168. if k[2] is not None and count >= best_dmode[0]: best_dmode = (count, k[2])
  169. if k[3] is not None and count >= best_fmode[0]: best_fmode = (count, k[3])
  170. if k[4] is not None and count >= best_selabel[0]: best_selabel = (count, k[4])
  171. if k[5] is not None and count >= best_capabilities[0]: best_capabilities = (count, k[5])
  172. self.best_subtree = ug + (best_dmode[1], best_fmode[1], best_selabel[1], best_capabilities[1])
  173. return d
  174. def SetPermissions(self, script):
  175. """Append set_perm/set_perm_recursive commands to 'script' to
  176. set all permissions, users, and groups for the tree of files
  177. rooted at 'self'."""
  178. self.CountChildMetadata()
  179. def recurse(item, current):
  180. # current is the (uid, gid, dmode, fmode, selabel, capabilities) tuple that the current
  181. # item (and all its children) have already been set to.  We only
  182. # need to issue set_perm/set_perm_recursive commands if we're
  183. # supposed to be something different.
  184. if item.dir:
  185. if current != item.best_subtree:
  186. script.SetPermissionsRecursive("/"+item.name, *item.best_subtree)
  187. current = item.best_subtree
  188. if item.uid != current[0] or item.gid != current[1] or \
  189. item.mode != current[2] or item.selabel != current[4] or \
  190. item.capabilities != current[5]:
  191. script.SetPermissions("/"+item.name, item.uid, item.gid,
  192. item.mode, item.selabel, item.capabilities)
  193. for i in item.children:
  194. recurse(i, current)
  195. else:
  196. if item.uid != current[0] or item.gid != current[1] or \
  197. item.mode != current[3] or item.selabel != current[4] or \
  198. item.capabilities != current[5]:
  199. script.SetPermissions("/"+item.name, item.uid, item.gid,
  200. item.mode, item.selabel, item.capabilities)
  201. recurse(self, (-1, -1, -1, -1, None, None))
  202. def CopySystemFiles(input_zip, output_zip=None,
  203. substitute=None):
  204. """Copies files underneath system/ in the input zip to the output
  205. zip.  Populates the Item class with their metadata, and returns a
  206. list of symlinks.  output_zip may be None, in which case the copy is
  207. skipped (but the other side effects still happen).  substitute is an
  208. optional dict of {output filename: contents} to be output instead of
  209. certain input files.
  210. """
  211. symlinks = []
  212. for info in input_zip.infolist():
  213. if info.filename.startswith("SYSTEM/"):
  214. basefilename = info.filename[7:]
  215. if IsSymlink(info):
  216. symlinks.append((input_zip.read(info.filename),
  217. "/system/" + basefilename))
  218. else:
  219. info2 = copy.copy(info)
  220. fn = info2.filename = "system/" + basefilename
  221. if substitute and fn in substitute and substitute[fn] is None:
  222. continue
  223. if output_zip is not None:
  224. if substitute and fn in substitute:
  225. data = substitute[fn]
  226. else:
  227. data = input_zip.read(info.filename)
  228. output_zip.writestr(info2, data)
  229. if fn.endswith("/"):
  230. Item.Get(fn[:-1], dir=True)
  231. else:
  232. Item.Get(fn, dir=False)
  233. symlinks.sort()
  234. return symlinks
  235. def SignOutput(temp_zip_name, output_zip_name):
  236. key_passwords = common.GetKeyPasswords([OPTIONS.package_key])
  237. pw = key_passwords[OPTIONS.package_key]
  238. common.SignFile(temp_zip_name, output_zip_name, OPTIONS.package_key, pw,
  239. whole_file=True)
  240. def AppendAssertions(script, info_dict):
  241. device = GetBuildProp("ro.product.device", info_dict)
  242. script.AssertDevice(device)
  243. def MakeecoveryPatch(input_tmp, output_zip, recovery_img, boot_img):
  244. """Generate a binary patch that creates the recovery image starting
  245. with the boot image.  (Most of the space in these images is just the
  246. kernel, which is identical for the two, so the resulting patch
  247. should be efficient.)  Add it to the output zip, along with a shell
  248. script that is run from init.rc on first boot to actually do the
  249. patching and install the new recovery image.
  250. recovery_img and boot_img should be File objects for the
  251. corresponding images.  info should be the dictionary returned by
  252. common.LoadInfoDict() on the input target_files.
  253. Returns an Item for the shell script, which must be made
  254. executable.
  255. """
  256. diff_program = ["imgdiff"]
  257. path = os.path.join(input_tmp, "SYSTEM", "etc", "recovery-resource.dat")
  258. if os.path.exists(path):
  259. diff_program.append("-b")
  260. diff_program.append(path)
  261. bonus_args = "-b /system/etc/recovery-resource.dat"
  262. else:
  263. bonus_args = ""
  264. d = common.Difference(recovery_img, boot_img, diff_program=diff_program)
  265. _, _, patch = d.ComputePatch()
  266. common.ZipWriteStr(output_zip, "recovery/recovery-from-boot.p", patch)
  267. Item.Get("system/recovery-from-boot.p", dir=False)
  268. boot_type, boot_device = common.GetTypeAndDevice("/boot", OPTIONS.info_dict)
  269. recovery_type, recovery_device = common.GetTypeAndDevice("/recovery", OPTIONS.info_dict)
  270. sh = """#!/system/bin/sh
  271. if ! applypatch -c %(recovery_type)s:%(recovery_device)s:%(recovery_size)d:%(recovery_sha1)s; then
  272. log -t recovery "Installing new recovery image"
  273. applypatch %(bonus_args)s %(boot_type)s:%(boot_device)s:%(boot_size)d:%(boot_sha1)s %(recovery_type)s:%(recovery_device)s %(recovery_sha1)s %(recovery_size)d %(boot_sha1)s:/system/recovery-from-boot.p
  274. else
  275. log -t recovery "Recovery image already installed"
  276. fi
  277. """ % { 'boot_size': boot_img.size,
  278. 'boot_sha1': boot_img.sha1,
  279. 'recovery_size': recovery_img.size,
  280. 'recovery_sha1': recovery_img.sha1,
  281. 'boot_type': boot_type,
  282. 'boot_device': boot_device,
  283. 'recovery_type': recovery_type,
  284. 'recovery_device': recovery_device,
  285. 'bonus_args': bonus_args,
  286. }
  287. common.ZipWriteStr(output_zip, "recovery/etc/install-recovery.sh", sh)
  288. return Item.Get("system/etc/install-recovery.sh", dir=False)
  289. def WriteFullOTAPackage(input_zip, output_zip):
  290. # TODO: how to determine this?  We don't know what version it will
  291. # be installed on top of.  For now, we expect the API just won't
  292. # change very often.
  293. script = edify_generator.EdifyGenerator(3, OPTIONS.info_dict)
  294. metadata = {"post-build": GetBuildProp("ro.build.fingerprint",
  295. OPTIONS.info_dict),
  296. "pre-device": GetBuildProp("ro.product.device",
  297. OPTIONS.info_dict),
  298. "post-timestamp": GetBuildProp("ro.build.date.utc",
  299. OPTIONS.info_dict),
  300. }
  301. device_specific = common.DeviceSpecificParams(
  302. input_zip=input_zip,
  303. input_version=OPTIONS.info_dict["recovery_api_version"],
  304. output_zip=output_zip,
  305. script=script,
  306. input_tmp=OPTIONS.input_tmp,
  307. metadata=metadata,
  308. info_dict=OPTIONS.info_dict)
  309. if not OPTIONS.omit_prereq:
  310. ts = GetBuildProp("ro.build.date.utc", OPTIONS.info_dict)
  311. ts_text = GetBuildProp("ro.build.date", OPTIONS.info_dict)
  312. script.AssertOlderBuild(ts, ts_text)
  313. AppendAssertions(script, OPTIONS.info_dict)
  314. device_specific.FullOTA_Assertions()
  315. device_specific.FullOTA_InstallBegin()
  316. script.ShowProgress(0.5, 0)
  317. if OPTIONS.wipe_user_data:
  318. script.FormatPartition("/data")
  319. if "selinux_fc" in OPTIONS.info_dict:
  320. WritePolicyConfig(OPTIONS.info_dict["selinux_fc"], output_zip)
  321. script.FormatPartition("/system")
  322. script.Mount("/system")
  323. script.UnpackPackageDir("recovery", "/system")
  324. script.UnpackPackageDir("system", "/system")
  325. symlinks = CopySystemFiles(input_zip, output_zip)
  326. script.MakeSymlinks(symlinks)
  327. boot_img = common.GetBootableImage("boot.img", "boot.img",
  328. OPTIONS.input_tmp, "BOOT")
  329. recovery_img = common.GetBootableImage("recovery.img", "recovery.img",
  330. OPTIONS.input_tmp, "RECOVERY")
  331. MakeRecoveryPatch(OPTIONS.input_tmp, output_zip, recovery_img, boot_img)
  332. Item.GetMetadata(input_zip)
  333. Item.Get("system").SetPermissions(script)
  334. common.CheckSize(boot_img.data, "boot.img", OPTIONS.info_dict)
  335. common.ZipWriteStr(output_zip, "boot.img", boot_img.data)
  336. script.ShowProgress(0.2, 0)
  337. script.ShowProgress(0.2, 10)
  338. script.WriteRawImage("/boot", "boot.img")
  339. script.ShowProgress(0.1, 0)
  340. device_specific.FullOTA_InstallEnd()
  341. if OPTIONS.extra_script is not None:
  342. script.AppendExtra(OPTIONS.extra_script)
  343. script.UnmountAll()
  344. script.AddToZip(input_zip, output_zip)
  345. WriteMetadata(metadata, output_zip)
  346. def WritePolicyConfig(file_context, output_zip):
  347. f = open(file_context, 'r');
  348. basename = os.path.basename(file_context)
  349. common.ZipWriteStr(output_zip, basename, f.read())
  350. def WriteMetadata(metadata, output_zip):
  351. common.ZipWriteStr(output_zip, "META-INF/com/android/metadata",
  352. "".join(["%s=%s\n" % kv
  353. for kv in sorted(metadata.iteritems())]))
  354. def LoadSystemFiles(z):
  355. """Load all the files from SYSTEM/... in a given target-files
  356. ZipFile, and return a dict of {filename: File object}."""
  357. out = {}
  358. for info in z.infolist():
  359. if info.filename.startswith("SYSTEM/") and not IsSymlink(info):
  360. basefilename = info.filename[7:]
  361. fn = "system/" + basefilename
  362. data = z.read(info.filename)
  363. out[fn] = common.File(fn, data)
  364. return out
  365. def GetBuildProp(prop, info_dict):
  366. """Return the fingerprint of the build of a given target-files info_dict."""
  367. try:
  368. return info_dict.get("build.prop", {})[prop]
  369. except KeyError:
  370. raise common.ExternalError("couldn't find %s in build.prop" % (property,))
  371. def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):
  372. source_version = OPTIONS.source_info_dict["recovery_api_version"]
  373. target_version = OPTIONS.target_info_dict["recovery_api_version"]
  374. if source_version == 0:
  375. print ("WARNING: generating edify script for a source that "
  376. "can't install it.")
  377. script = edify_generator.EdifyGenerator(source_version,
  378. OPTIONS.target_info_dict)
  379. metadata = {"pre-device": GetBuildProp("ro.product.device",
  380. OPTIONS.source_info_dict),
  381. "post-timestamp": GetBuildProp("ro.build.date.utc",
  382. OPTIONS.target_info_dict),
  383. }
  384. device_specific = common.DeviceSpecificParams(
  385. source_zip=source_zip,
  386. source_version=source_version,
  387. target_zip=target_zip,
  388. target_version=target_version,
  389. output_zip=output_zip,
  390. script=script,
  391. metadata=metadata,
  392. info_dict=OPTIONS.info_dict)
  393. print "Loading target..."
  394. target_data = LoadSystemFiles(target_zip)
  395. print "Loading source..."
  396. source_data = LoadSystemFiles(source_zip)
  397. verbatim_targets = []
  398. patch_list = []
  399. diffs = []
  400. renames = {}
  401. largest_source_size = 0
  402. matching_file_cache = {}
  403. for fn in source_data.keys():
  404. sf = source_data[fn]
  405. assert fn == sf.name
  406. matching_file_cache["path:" + fn] = sf
  407. # Only allow eligability for filename/sha matching
  408. # if there isn't a perfect path match.
  409. if target_data.get(sf.name) is None:
  410. matching_file_cache["file:" + fn.split("/")[-1]] = sf
  411. matching_file_cache["sha:" + sf.sha1] = sf
  412. for fn in sorted(target_data.keys()):
  413. tf = target_data[fn]
  414. assert fn == tf.name
  415. sf = ClosestFileMatch(tf, matching_file_cache, renames)
  416. if sf is not None and sf.name != tf.name:
  417. print "File has moved from " + sf.name + " to " + tf.name
  418. renames[sf.name] = tf
  419. if sf is None or fn in OPTIONS.require_verbatim:
  420. # This file should be included verbatim
  421. if fn in OPTIONS.prohibit_verbatim:
  422. raise common.ExternalError("\"%s\" must be sent verbatim" % (fn,))
  423. print "send", fn, "verbatim"
  424. tf.AddToZip(output_zip)
  425. verbatim_targets.append((fn, tf.size))
  426. elif tf.sha1 != sf.sha1:
  427. # File is different; consider sending as a patch
  428. diffs.append(common.Difference(tf, sf))
  429. else:
  430. # Target file data identical to source (may still be renamed)
  431. pass
  432. common.ComputeDifferences(diffs)
  433. for diff in diffs:
  434. tf, sf, d = diff.GetPatch()
  435. if d is None or len(d) > tf.size * OPTIONS.patch_threshold:
  436. # patch is almost as big as the file; don't bother patching
  437. tf.AddToZip(output_zip)
  438. verbatim_targets.append((tf.name, tf.size))
  439. else:
  440. common.ZipWriteStr(output_zip, "patch/" + sf.name + ".p", d)
  441. patch_list.append((sf.name, tf, sf, tf.size, common.sha1(d).hexdigest()))
  442. largest_source_size = max(largest_source_size, sf.size)
  443. source_fp = GetBuildProp("ro.build.fingerprint", OPTIONS.source_info_dict)
  444. target_fp = GetBuildProp("ro.build.fingerprint", OPTIONS.target_info_dict)
  445. metadata["pre-build"] = source_fp
  446. metadata["post-build"] = target_fp
  447. script.Mount("/system")
  448. script.AssertSomeFingerprint(source_fp, target_fp)
  449. source_boot = common.GetBootableImage(
  450. "/tmp/boot.img", "boot.img", OPTIONS.source_tmp, "BOOT",
  451. OPTIONS.source_info_dict)
  452. target_boot = common.GetBootableImage(
  453. "/tmp/boot.img", "boot.img", OPTIONS.target_tmp, "BOOT")
  454. updating_boot = (source_boot.data != target_boot.data)
  455. source_recovery = common.GetBootableImage(
  456. "/tmp/recovery.img", "recovery.img", OPTIONS.source_tmp, "RECOVERY",
  457. OPTIONS.source_info_dict)
  458. target_recovery = common.GetBootableImage(
  459. "/tmp/recovery.img", "recovery.img", OPTIONS.target_tmp, "RECOVERY")
  460. updating_recovery = (source_recovery.data != target_recovery.data)
  461. # Here's how we divide up the progress bar:
  462. #  0.1 for verifying the start state (PatchCheck calls)
  463. #  0.8 for applying patches (ApplyPatch calls)
  464. #  0.1 for unpacking verbatim files, symlinking, and doing the
  465. #      device-specific commands.
  466. AppendAssertions(script, OPTIONS.target_info_dict)
  467. device_specific.IncrementalOTA_Assertions()
  468. script.Print("Verifying current system...")
  469. device_specific.IncrementalOTA_VerifyBegin()
  470. script.ShowProgress(0.1, 0)
  471. total_verify_size = float(sum([i[2].size for i in patch_list]) + 1)
  472. if updating_boot:
  473. total_verify_size += source_boot.size
  474. so_far = 0
  475. for fn, tf, sf, size, patch_sha in patch_list:
  476. script.PatchCheck("/"+fn, tf.sha1, sf.sha1)
  477. so_far += sf.size
  478. script.SetProgress(so_far / total_verify_size)
  479. if updating_boot:
  480. d = common.Difference(target_boot, source_boot)
  481. _, _, d = d.ComputePatch()
  482. print "boot      target: %d  source: %d  diff: %d" % (
  483. target_boot.size, source_boot.size, len(d))
  484. common.ZipWriteStr(output_zip, "patch/boot.img.p", d)
  485. boot_type, boot_device = common.GetTypeAndDevice("/boot", OPTIONS.info_dict)
  486. script.PatchCheck("%s:%s:%d:%s:%d:%s" %
  487. (boot_type, boot_device,
  488. source_boot.size, source_boot.sha1,
  489. target_boot.size, target_boot.sha1))
  490. so_far += source_boot.size
  491. script.SetProgress(so_far / total_verify_size)
  492. if patch_list or updating_recovery or updating_boot:
  493. script.CacheFreeSpaceCheck(largest_source_size)
  494. device_specific.IncrementalOTA_VerifyEnd()
  495. script.Comment("---- start making changes here ----")
  496. device_specific.IncrementalOTA_InstallBegin()
  497. if OPTIONS.wipe_user_data:
  498. script.Print("Erasing user data...")
  499. script.FormatPartition("/data")
  500. script.Print("Removing unneeded files...")
  501. script.DeleteFiles(["/"+i[0] for i in verbatim_targets] +
  502. ["/"+i for i in sorted(source_data)
  503. if i not in target_data and
  504. i not in renames] +
  505. ["/system/recovery.img"])
  506. script.ShowProgress(0.8, 0)
  507. total_patch_size = float(sum([i[1].size for i in patch_list]) + 1)
  508. if updating_boot:
  509. total_patch_size += target_boot.size
  510. so_far = 0
  511. script.Print("Patching system files...")
  512. deferred_patch_list = []
  513. for item in patch_list:
  514. fn, tf, sf, size, _ = item
  515. if tf.name == "system/build.prop":
  516. deferred_patch_list.append(item)
  517. continue
  518. script.ApplyPatch("/"+fn, "-", tf.size, tf.sha1, sf.sha1, "patch/"+fn+".p")
  519. so_far += tf.size
  520. script.SetProgress(so_far / total_patch_size)
  521. if updating_boot:
  522. # Produce the boot image by applying a patch to the current
  523. # contents of the boot partition, and write it back to the
  524. # partition.
  525. script.Print("Patching boot image...")
  526. script.ApplyPatch("%s:%s:%d:%s:%d:%s"
  527. % (boot_type, boot_device,
  528. source_boot.size, source_boot.sha1,
  529. target_boot.size, target_boot.sha1),
  530. "-",
  531. target_boot.size, target_boot.sha1,
  532. source_boot.sha1, "patch/boot.img.p")
  533. so_far += target_boot.size
  534. script.SetProgress(so_far / total_patch_size)
  535. print "boot image changed; including."
  536. else:
  537. print "boot image unchanged; skipping."
  538. if updating_recovery:
  539. # Recovery is generated as a patch using both the boot image
  540. # (which contains the same linux kernel as recovery) and the file
  541. # /system/etc/recovery-resource.dat (which contains all the images
  542. # used in the recovery UI) as sources.  This lets us minimize the
  543. # size of the patch, which must be included in every OTA package.
  544. #
  545. # For older builds where recovery-resource.dat is not present, we
  546. # use only the boot image as the source.
  547. MakeRecoveryPatch(OPTIONS.target_tmp, output_zip,
  548. target_recovery, target_boot)
  549. script.DeleteFiles(["/system/recovery-from-boot.p",
  550. "/system/etc/install-recovery.sh"])
  551. print "recovery image changed; including as patch from boot."
  552. else:
  553. print "recovery image unchanged; skipping."
  554. script.ShowProgress(0.1, 10)
  555. target_symlinks = CopySystemFiles(target_zip, None)
  556. target_symlinks_d = dict([(i[1], i[0]) for i in target_symlinks])
  557. temp_script = script.MakeTemporary()
  558. Item.GetMetadata(target_zip)
  559. Item.Get("system").SetPermissions(temp_script)
  560. # Note that this call will mess up the tree of Items, so make sure
  561. # we're done with it.
  562. source_symlinks = CopySystemFiles(source_zip, None)
  563. source_symlinks_d = dict([(i[1], i[0]) for i in source_symlinks])
  564. # Delete all the symlinks in source that aren't in target.  This
  565. # needs to happen before verbatim files are unpacked, in case a
  566. # symlink in the source is replaced by a real file in the target.
  567. to_delete = []
  568. for dest, link in source_symlinks:
  569. if link not in target_symlinks_d:
  570. to_delete.append(link)
  571. script.DeleteFiles(to_delete)
  572. if verbatim_targets:
  573. script.Print("Unpacking new files...")
  574. script.UnpackPackageDir("system", "/system")
  575. if updating_recovery:
  576. script.Print("Unpacking new recovery...")
  577. script.UnpackPackageDir("recovery", "/system")
  578. if len(renames) > 0:
  579. script.Print("Renaming files...")
  580. for src in renames:
  581. print "Renaming " + src + " to " + renames[src].name
  582. script.RenameFile(src, renames[src].name)
  583. script.Print("Symlinks and permissions...")
  584. # Create all the symlinks that don't already exist, or point to
  585. # somewhere different than what we want.  Delete each symlink before
  586. # creating it, since the 'symlink' command won't overwrite.
  587. to_create = []
  588. for dest, link in target_symlinks:
  589. if link in source_symlinks_d:
  590. if dest != source_symlinks_d[link]:
  591. to_create.append((dest, link))
  592. else:
  593. to_create.append((dest, link))
  594. script.DeleteFiles([i[1] for i in to_create])
  595. script.MakeSymlinks(to_create)
  596. # Now that the symlinks are created, we can set all the
  597. # permissions.
  598. script.AppendScript(temp_script)
  599. # Do device-specific installation (eg, write radio image).
  600. device_specific.IncrementalOTA_InstallEnd()
  601. if OPTIONS.extra_script is not None:
  602. script.AppendExtra(OPTIONS.extra_script)
  603. # Patch the build.prop file last, so if something fails but the
  604. # device can still come up, it appears to be the old build and will
  605. # get set the OTA package again to retry.
  606. script.Print("Patching remaining system files...")
  607. for item in deferred_patch_list:
  608. fn, tf, sf, size, _ = item
  609. script.ApplyPatch("/"+fn, "-", tf.size, tf.sha1, sf.sha1, "patch/"+fn+".p")
  610. script.SetPermissions("/system/build.prop", 0, 0, 0644, None, None)
  611. script.AddToZip(target_zip, output_zip)
  612. WriteMetadata(metadata, output_zip)
  613. def main(argv):
  614. def option_handler(o, a):
  615. if o in ("-b", "--board_config"):
  616. pass   # deprecated
  617. elif o in ("-k", "--package_key"):
  618. OPTIONS.package_key = a
  619. elif o in ("-i", "--incremental_from"):
  620. OPTIONS.incremental_source = a
  621. elif o in ("-w", "--wipe_user_data"):
  622. OPTIONS.wipe_user_data = True
  623. elif o in ("-n", "--no_prereq"):
  624. OPTIONS.omit_prereq = True
  625. elif o in ("-e", "--extra_script"):
  626. OPTIONS.extra_script = a
  627. elif o in ("-a", "--aslr_mode"):
  628. if a in ("on", "On", "true", "True", "yes", "Yes"):
  629. OPTIONS.aslr_mode = True
  630. else:
  631. OPTIONS.aslr_mode = False
  632. elif o in ("--worker_threads"):
  633. OPTIONS.worker_threads = int(a)
  634. else:
  635. return False
  636. return True
  637. args = common.ParseOptions(argv, __doc__,
  638. extra_opts="b:k:i:d:wne:a:",
  639. extra_long_opts=["board_config=",
  640. "package_key=",
  641. "incremental_from=",
  642. "wipe_user_data",
  643. "no_prereq",
  644. "extra_script=",
  645. "worker_threads=",
  646. "aslr_mode=",
  647. ],
  648. extra_option_handler=option_handler)
  649. if len(args) != 2:
  650. common.Usage(__doc__)
  651. sys.exit(1)
  652. if OPTIONS.extra_script is not None:
  653. OPTIONS.extra_script = open(OPTIONS.extra_script).read()
  654. print "unzipping target target-files..."
  655. OPTIONS.input_tmp, input_zip = common.UnzipTemp(args[0])
  656. OPTIONS.target_tmp = OPTIONS.input_tmp
  657. OPTIONS.info_dict = common.LoadInfoDict(input_zip)
  658. # If this image was originally labelled with SELinux contexts, make sure we
  659. # also apply the labels in our new image. During building, the "file_contexts"
  660. # is in the out/ directory tree, but for repacking from target-files.zip it's
  661. # in the root directory of the ramdisk.
  662. if "selinux_fc" in OPTIONS.info_dict:
  663. OPTIONS.info_dict["selinux_fc"] = os.path.join(OPTIONS.input_tmp, "BOOT", "RAMDISK",
  664. "file_contexts")
  665. if OPTIONS.verbose:
  666. print "--- target info ---"
  667. common.DumpInfoDict(OPTIONS.info_dict)
  668. if OPTIONS.device_specific is None:
  669. OPTIONS.device_specific = OPTIONS.info_dict.get("tool_extensions", None)
  670. if OPTIONS.device_specific is not None:
  671. OPTIONS.device_specific = os.path.normpath(OPTIONS.device_specific)
  672. print "using device-specific extensions in", OPTIONS.device_specific
  673. temp_zip_file = tempfile.NamedTemporaryFile()
  674. output_zip = zipfile.ZipFile(temp_zip_file, "w",
  675. compression=zipfile.ZIP_DEFLATED)
  676. if OPTIONS.incremental_source is None:
  677. WriteFullOTAPackage(input_zip, output_zip)
  678. if OPTIONS.package_key is None:
  679. OPTIONS.package_key = OPTIONS.info_dict.get(
  680. "default_system_dev_certificate",
  681. "build/target/product/security/testkey")
  682. else:
  683. print "unzipping source target-files..."
  684. OPTIONS.source_tmp, source_zip = common.UnzipTemp(OPTIONS.incremental_source)
  685. OPTIONS.target_info_dict = OPTIONS.info_dict
  686. OPTIONS.source_info_dict = common.LoadInfoDict(source_zip)
  687. if OPTIONS.package_key is None:
  688. OPTIONS.package_key = OPTIONS.source_info_dict.get(
  689. "default_system_dev_certificate",
  690. "build/target/product/security/testkey")
  691. if OPTIONS.verbose:
  692. print "--- source info ---"
  693. common.DumpInfoDict(OPTIONS.source_info_dict)
  694. WriteIncrementalOTAPackage(input_zip, source_zip, output_zip)
  695. output_zip.close()
  696. SignOutput(temp_zip_file.name, args[1])
  697. temp_zip_file.close()
  698. common.Cleanup()
  699. print "done."
  700. if __name__ == '__main__':
  701. try:
  702. common.CloseInheritedPipes()
  703. main(sys.argv[1:])
  704. except common.ExternalError, e:
  705. print
  706. print "   ERROR: %s" % (e,)
  707. print
  708. sys.exit(1)                </span>
<span style="font-size:14px;">import sysif sys.hexversion < 0x02040000:print >> sys.stderr, "Python 2.4 or newer is required."sys.exit(1)import copy
import errno
import os
import re
import subprocess
import tempfile
import time
import zipfiletry:from hashlib import sha1 as sha1
except ImportError:from sha import sha as sha1import common
import edify_generatorOPTIONS = common.OPTIONS
OPTIONS.package_key = None
OPTIONS.incremental_source = None
OPTIONS.require_verbatim = set()
OPTIONS.prohibit_verbatim = set(("system/build.prop",))
OPTIONS.patch_threshold = 0.95
OPTIONS.wipe_user_data = False
OPTIONS.omit_prereq = False
OPTIONS.extra_script = None
OPTIONS.aslr_mode = True
OPTIONS.worker_threads = 3def MostPopularKey(d, default):"""Given a dict, return the key corresponding to the largestvalue.  Returns 'default' if the dict is empty."""x = [(v, k) for (k, v) in d.iteritems()]if not x: return defaultx.sort()return x[-1][1]def IsSymlink(info):"""Return true if the zipfile.ZipInfo object passed in represents asymlink."""return (info.external_attr >> 16) == 0120777def IsRegular(info):"""Return true if the zipfile.ZipInfo object passed in represents asymlink."""return (info.external_attr >> 28) == 010def ClosestFileMatch(src, tgtfiles, existing):"""Returns the closest file match between a source file and listof potential matches.  The exact filename match is preferred,then the sha1 is searched for, and finally a file with the samebasename is evaluated.  Rename support in the updater-binary isrequired for the latter checks to be used."""result = tgtfiles.get("path:" + src.name)if result is not None:return resultif not OPTIONS.target_info_dict.get("update_rename_support", False):return Noneif src.size < 1000:return Noneresult = tgtfiles.get("sha1:" + src.sha1)if result is not None and existing.get(result.name) is None:return resultresult = tgtfiles.get("file:" + src.name.split("/")[-1])if result is not None and existing.get(result.name) is None:return resultreturn Noneclass Item:"""Items represent the metadata (user, group, mode) of files anddirectories in the system image."""ITEMS = {}def __init__(self, name, dir=False):self.name = nameself.uid = Noneself.gid = Noneself.mode = Noneself.selabel = Noneself.capabilities = Noneself.dir = dirif name:self.parent = Item.Get(os.path.dirname(name), dir=True)self.parent.children.append(self)else:self.parent = Noneif dir:self.children = []def Dump(self, indent=0):if self.uid is not None:print "%s%s %d %d %o" % ("  "*indent, self.name, self.uid, self.gid, self.mode)else:print "%s%s %s %s %s" % ("  "*indent, self.name, self.uid, self.gid, self.mode)if self.dir:print "%s%s" % ("  "*indent, self.descendants)print "%s%s" % ("  "*indent, self.best_subtree)for i in self.children:i.Dump(indent=indent+1)@classmethoddef Get(cls, name, dir=False):if name not in cls.ITEMS:cls.ITEMS[name] = Item(name, dir=dir)return cls.ITEMS[name]@classmethoddef GetMetadata(cls, input_zip):# The target_files contains a record of what the uid,# gid, and mode are supposed to be.output = input_zip.read("META/filesystem_config.txt")for line in output.split("\n"):if not line: continuecolumns = line.split()name, uid, gid, mode = columns[:4]selabel = Nonecapabilities = None# After the first 4 columns, there are a series of key=value# pairs. Extract out the fields we care about.for element in columns[4:]:key, value = element.split("=")if key == "selabel":selabel = valueif key == "capabilities":capabilities = valuei = cls.ITEMS.get(name, None)if i is not None:i.uid = int(uid)i.gid = int(gid)i.mode = int(mode, 8)i.selabel = selabeli.capabilities = capabilitiesif i.dir:i.children.sort(key=lambda i: i.name)# set metadata for the files generated by this script.i = cls.ITEMS.get("system/recovery-from-boot.p", None)if i: i.uid, i.gid, i.mode, i.selabel, i.capabilities = 0, 0, 0644, None, Nonei = cls.ITEMS.get("system/etc/install-recovery.sh", None)if i: i.uid, i.gid, i.mode, i.selabel, i.capabilities = 0, 0, 0544, None, Nonedef CountChildMetadata(self):"""Count up the (uid, gid, mode, selabel, capabilities) tuples forall children and determine the best strategy for using set_perm_recursive andset_perm to correctly chown/chmod all the files to their desiredvalues.  Recursively calls itself for all descendants.Returns a dict of {(uid, gid, dmode, fmode, selabel, capabilities): count} counting upall descendants of this node.  (dmode or fmode may be None.)  Alsosets the best_subtree of each directory Item to the (uid, gid,dmode, fmode, selabel, capabilities) tuple that will match the mostdescendants of that Item."""assert self.dird = self.descendants = {(self.uid, self.gid, self.mode, None, self.selabel, self.capabilities): 1}for i in self.children:if i.dir:for k, v in i.CountChildMetadata().iteritems():d[k] = d.get(k, 0) + velse:k = (i.uid, i.gid, None, i.mode, i.selabel, i.capabilities)d[k] = d.get(k, 0) + 1# Find the (uid, gid, dmode, fmode, selabel, capabilities)# tuple that matches the most descendants.# First, find the (uid, gid) pair that matches the most# descendants.ug = {}for (uid, gid, _, _, _, _), count in d.iteritems():ug[(uid, gid)] = ug.get((uid, gid), 0) + countug = MostPopularKey(ug, (0, 0))# Now find the dmode, fmode, selabel, and capabilities that match# the most descendants with that (uid, gid), and choose those.best_dmode = (0, 0755)best_fmode = (0, 0644)best_selabel = (0, None)best_capabilities = (0, None)for k, count in d.iteritems():if k[:2] != ug: continueif k[2] is not None and count >= best_dmode[0]: best_dmode = (count, k[2])if k[3] is not None and count >= best_fmode[0]: best_fmode = (count, k[3])if k[4] is not None and count >= best_selabel[0]: best_selabel = (count, k[4])if k[5] is not None and count >= best_capabilities[0]: best_capabilities = (count, k[5])self.best_subtree = ug + (best_dmode[1], best_fmode[1], best_selabel[1], best_capabilities[1])return ddef SetPermissions(self, script):"""Append set_perm/set_perm_recursive commands to 'script' toset all permissions, users, and groups for the tree of filesrooted at 'self'."""self.CountChildMetadata()def recurse(item, current):# current is the (uid, gid, dmode, fmode, selabel, capabilities) tuple that the current# item (and all its children) have already been set to.  We only# need to issue set_perm/set_perm_recursive commands if we're# supposed to be something different.if item.dir:if current != item.best_subtree:script.SetPermissionsRecursive("/"+item.name, *item.best_subtree)current = item.best_subtreeif item.uid != current[0] or item.gid != current[1] or \item.mode != current[2] or item.selabel != current[4] or \item.capabilities != current[5]:script.SetPermissions("/"+item.name, item.uid, item.gid,item.mode, item.selabel, item.capabilities)for i in item.children:recurse(i, current)else:if item.uid != current[0] or item.gid != current[1] or \item.mode != current[3] or item.selabel != current[4] or \item.capabilities != current[5]:script.SetPermissions("/"+item.name, item.uid, item.gid,item.mode, item.selabel, item.capabilities)recurse(self, (-1, -1, -1, -1, None, None))def CopySystemFiles(input_zip, output_zip=None,substitute=None):"""Copies files underneath system/ in the input zip to the outputzip.  Populates the Item class with their metadata, and returns alist of symlinks.  output_zip may be None, in which case the copy isskipped (but the other side effects still happen).  substitute is anoptional dict of {output filename: contents} to be output instead ofcertain input files."""symlinks = []for info in input_zip.infolist():if info.filename.startswith("SYSTEM/"):basefilename = info.filename[7:]if IsSymlink(info):symlinks.append((input_zip.read(info.filename),"/system/" + basefilename))else:info2 = copy.copy(info)fn = info2.filename = "system/" + basefilenameif substitute and fn in substitute and substitute[fn] is None:continueif output_zip is not None:if substitute and fn in substitute:data = substitute[fn]else:data = input_zip.read(info.filename)output_zip.writestr(info2, data)if fn.endswith("/"):Item.Get(fn[:-1], dir=True)else:Item.Get(fn, dir=False)symlinks.sort()return symlinksdef SignOutput(temp_zip_name, output_zip_name):key_passwords = common.GetKeyPasswords([OPTIONS.package_key])pw = key_passwords[OPTIONS.package_key]common.SignFile(temp_zip_name, output_zip_name, OPTIONS.package_key, pw,whole_file=True)def AppendAssertions(script, info_dict):device = GetBuildProp("ro.product.device", info_dict)script.AssertDevice(device)def MakeecoveryPatch(input_tmp, output_zip, recovery_img, boot_img):"""Generate a binary patch that creates the recovery image startingwith the boot image.  (Most of the space in these images is just thekernel, which is identical for the two, so the resulting patchshould be efficient.)  Add it to the output zip, along with a shellscript that is run from init.rc on first boot to actually do thepatching and install the new recovery image.recovery_img and boot_img should be File objects for thecorresponding images.  info should be the dictionary returned bycommon.LoadInfoDict() on the input target_files.Returns an Item for the shell script, which must be madeexecutable."""diff_program = ["imgdiff"]path = os.path.join(input_tmp, "SYSTEM", "etc", "recovery-resource.dat")if os.path.exists(path):diff_program.append("-b")diff_program.append(path)bonus_args = "-b /system/etc/recovery-resource.dat"else:bonus_args = ""d = common.Difference(recovery_img, boot_img, diff_program=diff_program)_, _, patch = d.ComputePatch()common.ZipWriteStr(output_zip, "recovery/recovery-from-boot.p", patch)Item.Get("system/recovery-from-boot.p", dir=False)boot_type, boot_device = common.GetTypeAndDevice("/boot", OPTIONS.info_dict)recovery_type, recovery_device = common.GetTypeAndDevice("/recovery", OPTIONS.info_dict)sh = """#!/system/bin/sh
if ! applypatch -c %(recovery_type)s:%(recovery_device)s:%(recovery_size)d:%(recovery_sha1)s; thenlog -t recovery "Installing new recovery image"applypatch %(bonus_args)s %(boot_type)s:%(boot_device)s:%(boot_size)d:%(boot_sha1)s %(recovery_type)s:%(recovery_device)s %(recovery_sha1)s %(recovery_size)d %(boot_sha1)s:/system/recovery-from-boot.p
elselog -t recovery "Recovery image already installed"
fi
""" % { 'boot_size': boot_img.size,'boot_sha1': boot_img.sha1,'recovery_size': recovery_img.size,'recovery_sha1': recovery_img.sha1,'boot_type': boot_type,'boot_device': boot_device,'recovery_type': recovery_type,'recovery_device': recovery_device,'bonus_args': bonus_args,}common.ZipWriteStr(output_zip, "recovery/etc/install-recovery.sh", sh)return Item.Get("system/etc/install-recovery.sh", dir=False)def WriteFullOTAPackage(input_zip, output_zip):# TODO: how to determine this?  We don't know what version it will# be installed on top of.  For now, we expect the API just won't# change very often.script = edify_generator.EdifyGenerator(3, OPTIONS.info_dict)metadata = {"post-build": GetBuildProp("ro.build.fingerprint",OPTIONS.info_dict),"pre-device": GetBuildProp("ro.product.device",OPTIONS.info_dict),"post-timestamp": GetBuildProp("ro.build.date.utc",OPTIONS.info_dict),}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)if not OPTIONS.omit_prereq:ts = GetBuildProp("ro.build.date.utc", OPTIONS.info_dict)ts_text = GetBuildProp("ro.build.date", OPTIONS.info_dict)script.AssertOlderBuild(ts, ts_text)AppendAssertions(script, OPTIONS.info_dict)device_specific.FullOTA_Assertions()device_specific.FullOTA_InstallBegin()script.ShowProgress(0.5, 0)if OPTIONS.wipe_user_data:script.FormatPartition("/data")if "selinux_fc" in OPTIONS.info_dict:WritePolicyConfig(OPTIONS.info_dict["selinux_fc"], output_zip)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.GetBootableImage("boot.img", "boot.img",OPTIONS.input_tmp, "BOOT")recovery_img = common.GetBootableImage("recovery.img", "recovery.img",OPTIONS.input_tmp, "RECOVERY")MakeRecoveryPatch(OPTIONS.input_tmp, 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)def WritePolicyConfig(file_context, output_zip):f = open(file_context, 'r');basename = os.path.basename(file_context)common.ZipWriteStr(output_zip, basename, f.read())def WriteMetadata(metadata, output_zip):common.ZipWriteStr(output_zip, "META-INF/com/android/metadata","".join(["%s=%s\n" % kvfor kv in sorted(metadata.iteritems())]))def LoadSystemFiles(z):"""Load all the files from SYSTEM/... in a given target-filesZipFile, and return a dict of {filename: File object}."""out = {}for info in z.infolist():if info.filename.startswith("SYSTEM/") and not IsSymlink(info):basefilename = info.filename[7:]fn = "system/" + basefilenamedata = z.read(info.filename)out[fn] = common.File(fn, data)return outdef GetBuildProp(prop, info_dict):"""Return the fingerprint of the build of a given target-files info_dict."""try:return info_dict.get("build.prop", {})[prop]except KeyError:raise common.ExternalError("couldn't find %s in build.prop" % (property,))def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):source_version = OPTIONS.source_info_dict["recovery_api_version"]target_version = OPTIONS.target_info_dict["recovery_api_version"]if source_version == 0:print ("WARNING: generating edify script for a source that ""can't install it.")script = edify_generator.EdifyGenerator(source_version,OPTIONS.target_info_dict)metadata = {"pre-device": GetBuildProp("ro.product.device",OPTIONS.source_info_dict),"post-timestamp": GetBuildProp("ro.build.date.utc",OPTIONS.target_info_dict),}device_specific = common.DeviceSpecificParams(source_zip=source_zip,source_version=source_version,target_zip=target_zip,target_version=target_version,output_zip=output_zip,script=script,metadata=metadata,info_dict=OPTIONS.info_dict)print "Loading target..."target_data = LoadSystemFiles(target_zip)print "Loading source..."source_data = LoadSystemFiles(source_zip)verbatim_targets = []patch_list = []diffs = []renames = {}largest_source_size = 0matching_file_cache = {}for fn in source_data.keys():sf = source_data[fn]assert fn == sf.namematching_file_cache["path:" + fn] = sf# Only allow eligability for filename/sha matching# if there isn't a perfect path match.if target_data.get(sf.name) is None:matching_file_cache["file:" + fn.split("/")[-1]] = sfmatching_file_cache["sha:" + sf.sha1] = sffor fn in sorted(target_data.keys()):tf = target_data[fn]assert fn == tf.namesf = ClosestFileMatch(tf, matching_file_cache, renames)if sf is not None and sf.name != tf.name:print "File has moved from " + sf.name + " to " + tf.namerenames[sf.name] = tfif sf is None or fn in OPTIONS.require_verbatim:# This file should be included verbatimif fn in OPTIONS.prohibit_verbatim:raise common.ExternalError("\"%s\" must be sent verbatim" % (fn,))print "send", fn, "verbatim"tf.AddToZip(output_zip)verbatim_targets.append((fn, tf.size))elif tf.sha1 != sf.sha1:# File is different; consider sending as a patchdiffs.append(common.Difference(tf, sf))else:# Target file data identical to source (may still be renamed)passcommon.ComputeDifferences(diffs)for diff in diffs:tf, sf, d = diff.GetPatch()if d is None or len(d) > tf.size * OPTIONS.patch_threshold:# patch is almost as big as the file; don't bother patchingtf.AddToZip(output_zip)verbatim_targets.append((tf.name, tf.size))else:common.ZipWriteStr(output_zip, "patch/" + sf.name + ".p", d)patch_list.append((sf.name, tf, sf, tf.size, common.sha1(d).hexdigest()))largest_source_size = max(largest_source_size, sf.size)source_fp = GetBuildProp("ro.build.fingerprint", OPTIONS.source_info_dict)target_fp = GetBuildProp("ro.build.fingerprint", OPTIONS.target_info_dict)metadata["pre-build"] = source_fpmetadata["post-build"] = target_fpscript.Mount("/system")script.AssertSomeFingerprint(source_fp, target_fp)source_boot = common.GetBootableImage("/tmp/boot.img", "boot.img", OPTIONS.source_tmp, "BOOT",OPTIONS.source_info_dict)target_boot = common.GetBootableImage("/tmp/boot.img", "boot.img", OPTIONS.target_tmp, "BOOT")updating_boot = (source_boot.data != target_boot.data)source_recovery = common.GetBootableImage("/tmp/recovery.img", "recovery.img", OPTIONS.source_tmp, "RECOVERY",OPTIONS.source_info_dict)target_recovery = common.GetBootableImage("/tmp/recovery.img", "recovery.img", OPTIONS.target_tmp, "RECOVERY")updating_recovery = (source_recovery.data != target_recovery.data)# Here's how we divide up the progress bar:#  0.1 for verifying the start state (PatchCheck calls)#  0.8 for applying patches (ApplyPatch calls)#  0.1 for unpacking verbatim files, symlinking, and doing the#      device-specific commands.AppendAssertions(script, OPTIONS.target_info_dict)device_specific.IncrementalOTA_Assertions()script.Print("Verifying current system...")device_specific.IncrementalOTA_VerifyBegin()script.ShowProgress(0.1, 0)total_verify_size = float(sum([i[2].size for i in patch_list]) + 1)if updating_boot:total_verify_size += source_boot.sizeso_far = 0for fn, tf, sf, size, patch_sha in patch_list:script.PatchCheck("/"+fn, tf.sha1, sf.sha1)so_far += sf.sizescript.SetProgress(so_far / total_verify_size)if updating_boot:d = common.Difference(target_boot, source_boot)_, _, d = d.ComputePatch()print "boot      target: %d  source: %d  diff: %d" % (target_boot.size, source_boot.size, len(d))common.ZipWriteStr(output_zip, "patch/boot.img.p", d)boot_type, boot_device = common.GetTypeAndDevice("/boot", OPTIONS.info_dict)script.PatchCheck("%s:%s:%d:%s:%d:%s" %(boot_type, boot_device,source_boot.size, source_boot.sha1,target_boot.size, target_boot.sha1))so_far += source_boot.sizescript.SetProgress(so_far / total_verify_size)if patch_list or updating_recovery or updating_boot:script.CacheFreeSpaceCheck(largest_source_size)device_specific.IncrementalOTA_VerifyEnd()script.Comment("---- start making changes here ----")device_specific.IncrementalOTA_InstallBegin()if OPTIONS.wipe_user_data:script.Print("Erasing user data...")script.FormatPartition("/data")script.Print("Removing unneeded files...")script.DeleteFiles(["/"+i[0] for i in verbatim_targets] +["/"+i for i in sorted(source_data)if i not in target_data andi not in renames] +["/system/recovery.img"])script.ShowProgress(0.8, 0)total_patch_size = float(sum([i[1].size for i in patch_list]) + 1)if updating_boot:total_patch_size += target_boot.sizeso_far = 0script.Print("Patching system files...")deferred_patch_list = []for item in patch_list:fn, tf, sf, size, _ = itemif tf.name == "system/build.prop":deferred_patch_list.append(item)continuescript.ApplyPatch("/"+fn, "-", tf.size, tf.sha1, sf.sha1, "patch/"+fn+".p")so_far += tf.sizescript.SetProgress(so_far / total_patch_size)if updating_boot:# Produce the boot image by applying a patch to the current# contents of the boot partition, and write it back to the# partition.script.Print("Patching boot image...")script.ApplyPatch("%s:%s:%d:%s:%d:%s"% (boot_type, boot_device,source_boot.size, source_boot.sha1,target_boot.size, target_boot.sha1),"-",target_boot.size, target_boot.sha1,source_boot.sha1, "patch/boot.img.p")so_far += target_boot.sizescript.SetProgress(so_far / total_patch_size)print "boot image changed; including."else:print "boot image unchanged; skipping."if updating_recovery:# Recovery is generated as a patch using both the boot image# (which contains the same linux kernel as recovery) and the file# /system/etc/recovery-resource.dat (which contains all the images# used in the recovery UI) as sources.  This lets us minimize the# size of the patch, which must be included in every OTA package.## For older builds where recovery-resource.dat is not present, we# use only the boot image as the source.MakeRecoveryPatch(OPTIONS.target_tmp, output_zip,target_recovery, target_boot)script.DeleteFiles(["/system/recovery-from-boot.p","/system/etc/install-recovery.sh"])print "recovery image changed; including as patch from boot."else:print "recovery image unchanged; skipping."script.ShowProgress(0.1, 10)target_symlinks = CopySystemFiles(target_zip, None)target_symlinks_d = dict([(i[1], i[0]) for i in target_symlinks])temp_script = script.MakeTemporary()Item.GetMetadata(target_zip)Item.Get("system").SetPermissions(temp_script)# Note that this call will mess up the tree of Items, so make sure# we're done with it.source_symlinks = CopySystemFiles(source_zip, None)source_symlinks_d = dict([(i[1], i[0]) for i in source_symlinks])# Delete all the symlinks in source that aren't in target.  This# needs to happen before verbatim files are unpacked, in case a# symlink in the source is replaced by a real file in the target.to_delete = []for dest, link in source_symlinks:if link not in target_symlinks_d:to_delete.append(link)script.DeleteFiles(to_delete)if verbatim_targets:script.Print("Unpacking new files...")script.UnpackPackageDir("system", "/system")if updating_recovery:script.Print("Unpacking new recovery...")script.UnpackPackageDir("recovery", "/system")if len(renames) > 0:script.Print("Renaming files...")for src in renames:print "Renaming " + src + " to " + renames[src].namescript.RenameFile(src, renames[src].name)script.Print("Symlinks and permissions...")# Create all the symlinks that don't already exist, or point to# somewhere different than what we want.  Delete each symlink before# creating it, since the 'symlink' command won't overwrite.to_create = []for dest, link in target_symlinks:if link in source_symlinks_d:if dest != source_symlinks_d[link]:to_create.append((dest, link))else:to_create.append((dest, link))script.DeleteFiles([i[1] for i in to_create])script.MakeSymlinks(to_create)# Now that the symlinks are created, we can set all the# permissions.script.AppendScript(temp_script)# Do device-specific installation (eg, write radio image).device_specific.IncrementalOTA_InstallEnd()if OPTIONS.extra_script is not None:script.AppendExtra(OPTIONS.extra_script)# Patch the build.prop file last, so if something fails but the# device can still come up, it appears to be the old build and will# get set the OTA package again to retry.script.Print("Patching remaining system files...")for item in deferred_patch_list:fn, tf, sf, size, _ = itemscript.ApplyPatch("/"+fn, "-", tf.size, tf.sha1, sf.sha1, "patch/"+fn+".p")script.SetPermissions("/system/build.prop", 0, 0, 0644, None, None)script.AddToZip(target_zip, output_zip)WriteMetadata(metadata, output_zip)def main(argv):def option_handler(o, a):if o in ("-b", "--board_config"):pass   # deprecatedelif o in ("-k", "--package_key"):OPTIONS.package_key = aelif o in ("-i", "--incremental_from"):OPTIONS.incremental_source = aelif o in ("-w", "--wipe_user_data"):OPTIONS.wipe_user_data = Trueelif o in ("-n", "--no_prereq"):OPTIONS.omit_prereq = Trueelif o in ("-e", "--extra_script"):OPTIONS.extra_script = aelif o in ("-a", "--aslr_mode"):if a in ("on", "On", "true", "True", "yes", "Yes"):OPTIONS.aslr_mode = Trueelse:OPTIONS.aslr_mode = Falseelif o in ("--worker_threads"):OPTIONS.worker_threads = int(a)else:return Falsereturn Trueargs = common.ParseOptions(argv, __doc__,extra_opts="b:k:i:d:wne:a:",extra_long_opts=["board_config=","package_key=","incremental_from=","wipe_user_data","no_prereq","extra_script=","worker_threads=","aslr_mode=",],extra_option_handler=option_handler)if len(args) != 2:common.Usage(__doc__)sys.exit(1)if OPTIONS.extra_script is not None:OPTIONS.extra_script = open(OPTIONS.extra_script).read()print "unzipping target target-files..."OPTIONS.input_tmp, input_zip = common.UnzipTemp(args[0])OPTIONS.target_tmp = OPTIONS.input_tmpOPTIONS.info_dict = common.LoadInfoDict(input_zip)# If this image was originally labelled with SELinux contexts, make sure we# also apply the labels in our new image. During building, the "file_contexts"# is in the out/ directory tree, but for repacking from target-files.zip it's# in the root directory of the ramdisk.if "selinux_fc" in OPTIONS.info_dict:OPTIONS.info_dict["selinux_fc"] = os.path.join(OPTIONS.input_tmp, "BOOT", "RAMDISK","file_contexts")if OPTIONS.verbose:print "--- target info ---"common.DumpInfoDict(OPTIONS.info_dict)if OPTIONS.device_specific is None:OPTIONS.device_specific = OPTIONS.info_dict.get("tool_extensions", None)if OPTIONS.device_specific is not None:OPTIONS.device_specific = os.path.normpath(OPTIONS.device_specific)print "using device-specific extensions in", OPTIONS.device_specifictemp_zip_file = tempfile.NamedTemporaryFile()output_zip = zipfile.ZipFile(temp_zip_file, "w",compression=zipfile.ZIP_DEFLATED)if OPTIONS.incremental_source is None:WriteFullOTAPackage(input_zip, output_zip)if OPTIONS.package_key is None:OPTIONS.package_key = OPTIONS.info_dict.get("default_system_dev_certificate","build/target/product/security/testkey")else:print "unzipping source target-files..."OPTIONS.source_tmp, source_zip = common.UnzipTemp(OPTIONS.incremental_source)OPTIONS.target_info_dict = OPTIONS.info_dictOPTIONS.source_info_dict = common.LoadInfoDict(source_zip)if OPTIONS.package_key is None:OPTIONS.package_key = OPTIONS.source_info_dict.get("default_system_dev_certificate","build/target/product/security/testkey")if OPTIONS.verbose:print "--- source info ---"common.DumpInfoDict(OPTIONS.source_info_dict)WriteIncrementalOTAPackage(input_zip, source_zip, output_zip)output_zip.close()SignOutput(temp_zip_file.name, args[1])temp_zip_file.close()common.Cleanup()print "done."if __name__ == '__main__':try:common.CloseInheritedPipes()main(sys.argv[1:])except common.ExternalError, e:printprint "   ERROR: %s" % (e,)printsys.exit(1)                   </span>

主函数main是python的入口函数,我们从main函数开始看,大概看一下main函数(脚本最后)里的流程就能知道脚本的执行过程了。
    1) 在main函数的开头,首先将用户设定的option选项存入OPTIONS变量中,它是一个python中的类。紧接着判断有没有额外的脚本,如果有就读入到OPTIONS变量中。
    2) 解压缩输入的zip包,即我们在上文生成的原始zip包。然后判断是否用到device-specific extensions(设备扩展)如果用到,随即读入到OPTIONS变量中。
    3) 判断是否签名,然后判断是否有新内容的增量源,有的话就解压该增量源包放入一个临时变量中(source_zip)。自此,所有的准备工作已完毕,随即会调用该脚本中最主要的函数WriteFullOTAPackage(input_zip,output_zip)
    4) WriteFullOTAPackage函数的处理过程是先获得脚本的生成器。默认格式是edify。然后获得metadata元数据,此数据来至于Android的一些环境变量。然后获得设备配置参数比如api函数的版本。然后判断是否忽略时间戳。
    5) WriteFullOTAPackage函数做完准备工作后就开始生成升级用的脚本文件(updater-script)了。生成脚本文件后将上一步获得的metadata元数据写入到输出包out_zip。

6) 至此一个完整的update.zip升级包就生成了。生成位置在:out/target/product/tcc8800/full_tcc8800_evm-ota-eng.mumu.20120315.155326.zip。将升级包拷贝到SD卡中就可以用来升级了。

安卓升级固件update.zip解析相关推荐

  1. 飞利浦系统服务器更新,简介固件升级准备升级步骤通过内部闪存盘升级固件-Philips.PDF...

    简介固件升级准备升级步骤通过内部闪存盘升级固件-Philips.PDF 简介: 飞利浦将不断努力,让您以最佳的方式体验我们的产品.要获得最佳性能和最新功能,我们强烈建 议您升级平板电脑的固件. 您可以 ...

  2. Android系统Recovery工作原理之使用update.zip升级过程分析(一)

    这篇及以后的篇幅将通过分析update.zip包在具体Android系统升级的过程,来理解Android系统中Recovery模式服务的工作原理.我们先从update.zip包的制作开始,然后是And ...

  3. Android系统Recovery工作原理之使用update.zip升级过程分析(一)---update.zip包的制作【转】...

    本文转载自:http://blog.csdn.net/mu0206mu/article/details/7399822 这篇及以后的篇幅将通过分析update.zip包在具体Android系统升级的过 ...

  4. MTK平台ota升级后不删除u盘的update.zip

    又来了.开始苦逼的自追代码出补丁之路.本人辛苦追代码,原创,因此不怕任何侵权等行为. 故障现象: 把update.zip放入U盘根目录,插入普通usb口(看代码发现好像插入OTG口也可以,而且它升级完 ...

  5. 安卓升级包的制作以及解析升级

    1.安卓升级包目录结构组成 解压安卓升级包后目录结构: (图中是用vs code打开升级包文件结构图,升级包中多出来的arm.img,lk.img等镜像是mtk的一些定制化,安卓原生的升级包一般含有s ...

  6. android 版本更新原理,Android系统Recovery工作原理之使用update.zip升级过程分析(二)...

    Android系统Recovery工作原理之使用update.zip升级过程分析(二)---update.zip差分包问题的解决 在上一篇末尾提到的生成差分包时出现的问题,现已解决,由于最近比较忙,相 ...

  7. Android系统Recovery工作原理之使用update.zip升级过程分析(五)

    Android系统Recovery工作原理之使用update.zip升级过程分析(五)---update.zip包从上层进入Recovery服务文章开头我们就提到update.zip包来源有两种,一个 ...

  8. Android系统Recovery工作原理之使用update.zip升级过程分析(二)---u...

    2019独角兽企业重金招聘Python工程师标准>>>  Android系统Recovery工作原理之使用update.zip升级过程分析(二)---update.zip差分包问题的 ...

  9. Android系统Recovery工作原理之使用update.zip升级过程分析(四)

    Android系统Recovery模式的工作原理在使用update.zip包升级时怎样从主系统(main system)重启进入Recovery模式,进入Recovery模式后怎样判断做何种操作,以及 ...

最新文章

  1. spark streaming 消费 kafka入门采坑解决过程
  2. ORACLE TNS(transparence Network Substrate透明网络底层)
  3. java第三阶段源代码_有效Java第三版的源代码已更新为使用较新的功能
  4. python入门基础语法总结
  5. 结合XML的数据检索技术
  6. Go根据url获取html代码
  7. linux性能监测工具
  8. 单三相STS电能表 键盘表 代码表 预付费表 非洲 东南亚 分体式电表方案
  9. 超过2t硬盘分区_大于2T的磁盘怎么分区呢?
  10. Flutter第7天--字体图标,2021年Android开发进阶课程
  11. 吴晓波:预见2021(跨年演讲 —— 08 超级城市大赛鸣枪)
  12. Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “/zhu“
  13. 指纹识别实战——基于TensorFlow实现(文末送书)
  14. 我的世界网易服务器修改世界,我的世界:1.16改变两个版本更新频率?网易版异常乱封大批账号?...
  15. 多媒体计算机室管理制度,教室多媒体使用管理制度
  16. 比特熊故事汇独家|英特尔“非典型性女博士”的大跨步人生
  17. 如何使用AirPods Pro 更换取下和安装耳塞
  18. ICP配准MATLAB实现
  19. 利用过滤器处理字符,解决中文乱码问题
  20. 最小采样频率计算公式_ShaZam深入分析之从数字声音到频率

热门文章

  1. jstat 内存泄漏_一次Java内存泄漏的排查!要了自己的老命!
  2. 006_logback体系结构
  3. nacos 环境切换_Nacos多环境配置
  4. linux下 发布qt程序,Linux下发布qt程序
  5. mac连接群晖的服务器会自动断开_酷玩家庭数码-mac苹果笔记本电脑如何访问群晖NAS文件?...
  6. Java高并发编程:HandlerThread
  7. Photoshop CC2018软件安装资料及教程
  8. python训练馆_Python训练营 01
  9. mysql为什么用索引_MySql为什么使用B+树做索引
  10. 调用 标签打印软件_标签打印软件如何制作陶瓷标签模板