ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 网络编程 >> Android开发 >> Android Recovery OTA升级(一)—— make otapackage

Android Recovery OTA升级(一)—— make otapackage

来源:网络整理     时间:2015-07-25     关键词:

本篇文章主要介绍了"Android Recovery OTA升级(一)—— make otapackage",主要涉及到方面的内容,对于Android开发感兴趣的同学可以参考一下: 目录目录概述make otapackageBUILT_TARGET_FILES_PACKAGEota_from_target_filesWriteFullOTA...

目录

  • 目录
  • 概述
  • make otapackage
  • BUILT_TARGET_FILES_PACKAGE
  • ota_from_target_files
    • WriteFullOTAPackage
    • SignOutput
  • 总结


概述

make otapackage是Android Build系统支持的命令,用来生成Recovery系统能够进行升级的zip包。因此,想要了解Android的OTA升级机制,我们首先需要学习make otapackage命令的执行过程。

为了防止泄密,以下源码内容都是基于Android4.4.2_r1分支进行分析。


make otapackage

make otapackage是一个.PHONY伪目标。make系统中,伪目标并不是一个文件,只是一个标签,由于伪目标不是文件,所以make无法生成它的依赖关系和决定它是否要执行。我们只能通过显示的指明这个“目标”才能让其生效。需要注意的是,伪目标的取名不能和文件名重名,不然就失去伪目标的意义了。
了解了.PHONY之后,我们来看一下make otapackage的make源码:

.PHONY: otapackage
otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)

通过make代码,我们看到otapackage这个伪目标是依赖于$(INTERNAL_OTA_PACKAGE_TARGET)的,接下来,我会分析一下依赖文件的生成源码:

INTERNAL_OTA_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
$(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
$(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(DISTTOOLS)
    @echo"Package OTA: $@"$(hide) ./build/tools/releasetools/ota_from_target_files -v \
    -p $(HOST_OUT) \
    -k $(KEY_CERT_PAIR) \
    $(BUILT_TARGET_FILES_PACKAGE) $@

可以看到,$(INTERNAL_OTA_PACKAGE_TARGET)依赖于$(KEY_CERT_PAIR),$(HOST_OUT),$(BUILT_TARGET_FILES_PACKAGE)这三个文件和$(DISTTOOLS)所代表的jar包。
而这些所依赖的文件,最后都会作为参数传递给ota_from_target_files这个python脚本,这个python脚本会进一步生成最终的recovery升级包。示例参数如下:

['-v', '-p', 'out/host/linux-x86', '-k', 'build/target/product/security/testkey', 'out/target/product/xxx/obj/PACKAGING/target_files_intermediates/product-target_files-wangzhengyi.zip', 'out/target/product/xxx/product_20150724.1246-ota.zip']

从参数中可以看出,out/target/product/xxx/product_20150724.1246-ota.zip是最终的recovery升级包,而out/target/product/xxx/obj/PACKAGING/target_files_intermediates/product-target_files-wangzhengyi.zip是中间的临时zip包,它其实就是$(BUILT_TARGET_FILES_PACKAGE),接下来我们看一下$(BUILT_TARGET_FILES_PACKAGE)的生成代码。


BUILT_TARGET_FILES_PACKAGE

BUILT_TARGET_FILES_PACKAGE的make源码如下:

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-root
    if [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \
        mkdir -p $(2) && \
        $(ACP) -rd $(strip $(1))/* $(2); \
    fi
endif

built_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)

# 开始构建中间zip包$(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: $@"# 删除之前的zip文件$(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) $(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_PAGESIZE$(hide) echo "$(BOARD_KERNEL_PAGESIZE)" > $(zip_root)/RECOVERY/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) $(
                    以上就介绍了Android Recovery OTA升级(一)—— make otapackage,包括了方面的内容,希望对Android开发有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_153362.html

相关图片

相关文章