日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OTA整包的制作流程(未完)

發(fā)布時間:2025/3/21 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OTA整包的制作流程(未完) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我們知道,在android根目錄下,敲擊make otapackage,out目錄下就會生成ota package包,那么makefile是如何工作的呢?

當(dāng)用戶敲擊make otapackage后,我們看下Makefie的依賴關(guān)系:otapackage依賴INTERNAL_OTA_PACKAGE_TARGET目標(biāo),INTERNAL_OTA_PACKAGE_TARGET又依賴BUILT_TARGET_FILES_PACKAGE目標(biāo)。我們先跳過看BUILT_TARGET_FILES_PACKAGE目標(biāo)目標(biāo),當(dāng)該目標(biāo)存在后,我們看看是如何生成ota package的。

.PHONY: otapackage otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)$(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) \build/tools/releasetools/ota_from_target_files@echo "Package OTA: $@"$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \./build/tools/releasetools/ota_from_target_files -v \--block \--extracted_input_target_files $(patsubst %.zip,%,$(BUILT_TARGET_FILES_PACKAGE)) \-p $(HOST_OUT) \-k $(KEY_CERT_PAIR) \$(if $(OEM_OTA_CONFIG), -o $(OEM_OTA_CONFIG)) \$(BUILT_TARGET_FILES_PACKAGE) $@

由上述代碼可知,調(diào)用了build/tools/releasetools/ota_from_target_files腳本,并跟上了一堆的參數(shù),這里簡單先介紹下這些參數(shù):–block表示是以塊的形式來制作ota,–extracted_input_target_files是解壓后的arget-files文件,-p是目標(biāo)輸出的位置,-k是制作ota包所用的公鑰。我們在來看核心腳本,ota_from_target_files是一個軟鏈接,指向ota_from_target_files.py python腳本。
好了,我們開始好看ota_from_target_files.py

def main(argv):def option_handler(o, a):if o in ("-a", "--add_missing"):OPTIONS.add_missing = Trueelif o in ("-r", "--rebuild_recovery",):OPTIONS.rebuild_recovery = Trueelif o == "--replace_verity_private_key":OPTIONS.replace_verity_private_key = (True, a)elif o == "--replace_verity_public_key":OPTIONS.replace_verity_public_key = (True, a)elif o == "--is_signing":OPTIONS.is_signing = Trueelse:return Falsereturn Trueargs = common.ParseOptions(argv, __doc__, extra_opts="ar",extra_long_opts=["add_missing", "rebuild_recovery","replace_verity_public_key=","replace_verity_private_key=","is_signing"],extra_option_handler=option_handler)if len(args) != 1:common.Usage(__doc__)sys.exit(1)AddImagesToTargetFiles(args[0])print("done.")

在該main函數(shù)中,調(diào)用了兩個函數(shù):
(1)common.ParseOptions 解析參數(shù),其使用了一些標(biāo)準(zhǔn)的python庫getopt,其用法非常具有參考價值,以后寫別的python工具都可以抄一抄的,這里不做介紹,以后在python的章節(jié)中再分享。
(2)AddImagesToTargetFiles(args[0])
以下就具體介紹核心AddImagesToTargetFiles()函數(shù),函數(shù)原型如下:

def AddImagesToTargetFiles(filename):if os.path.isdir(filename):OPTIONS.input_tmp = os.path.abspath(filename)input_zip = Noneelse:OPTIONS.input_tmp, input_zip = common.UnzipTemp(filename)if not OPTIONS.add_missing:if os.path.isdir(os.path.join(OPTIONS.input_tmp, "IMAGES")):print("target_files appears to already contain images.")sys.exit(1)# vendor.img is unlike system.img or system_other.img. Because it could be# built from source, or dropped into target_files.zip as a prebuilt blob. We# consider either of them as vendor.img being available, which could be used# when generating vbmeta.img for AVB.has_vendor = (os.path.isdir(os.path.join(OPTIONS.input_tmp, "VENDOR")) oros.path.exists(os.path.join(OPTIONS.input_tmp, "IMAGES","vendor.img")))has_oem = (os.path.isdir(os.path.join(OPTIONS.input_tmp, "OEM")) oros.path.exists(os.path.join(OPTIONS.input_tmp, "IMAGES","oem.img")))has_system_other = os.path.isdir(os.path.join(OPTIONS.input_tmp,"SYSTEM_OTHER"))if input_zip:OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.input_tmp)common.ZipClose(input_zip)output_zip = zipfile.ZipFile(filename, "a",compression=zipfile.ZIP_DEFLATED,allowZip64=True)else:OPTIONS.info_dict = common.LoadInfoDict(filename, filename)output_zip = Noneimages_dir = os.path.join(OPTIONS.input_tmp, "IMAGES")if not os.path.isdir(images_dir):os.makedirs(images_dir)images_dir = Nonehas_recovery = (OPTIONS.info_dict.get("no_recovery") != "true")if OPTIONS.info_dict.get("avb_enable") == "true":fp = Noneif "build.prop" in OPTIONS.info_dict:build_prop = OPTIONS.info_dict["build.prop"]if "ro.build.fingerprint" in build_prop:fp = build_prop["ro.build.fingerprint"]elif "ro.build.thumbprint" in build_prop:fp = build_prop["ro.build.thumbprint"]if fp:OPTIONS.info_dict["avb_salt"] = hashlib.sha256(fp).hexdigest()def banner(s):print("\n\n++++ " + s + " ++++\n\n")prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", "boot.img.sig")boot_image = Noneif os.path.exists(prebuilt_path):banner("boot")print("boot.img already exists in IMAGES/, no need to rebuild...")if OPTIONS.rebuild_recovery:boot_image = common.GetBootableImage("IMAGES/boot.img.sig", "boot.img.sig", OPTIONS.input_tmp, "BOOT")else:banner("boot")boot_image = common.GetBootableImage("IMAGES/boot.img.sig", "boot.img.sig", OPTIONS.input_tmp, "BOOT")if boot_image:if output_zip:boot_image.AddToZip(output_zip)else:boot_image.WriteToDir(OPTIONS.input_tmp)recovery_image = Noneif has_recovery:banner("recovery")prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", "recovery.img.sig")if os.path.exists(prebuilt_path):print("recovery.img already exists in IMAGES/, no need to rebuild...")if OPTIONS.rebuild_recovery:recovery_image = common.GetBootableImage("IMAGES/recovery.img.sig", "recovery.img.sig", OPTIONS.input_tmp,"RECOVERY")else:recovery_image = common.GetBootableImage("IMAGES/recovery.img.sig", "recovery.img.sig", OPTIONS.input_tmp, "RECOVERY")if recovery_image:if output_zip:recovery_image.AddToZip(output_zip)else:recovery_image.WriteToDir(OPTIONS.input_tmp)banner("recovery (two-step image)")# The special recovery.img for two-step package use.recovery_two_step_image = common.GetBootableImage("IMAGES/recovery-two-step.img", "recovery-two-step.img",OPTIONS.input_tmp, "RECOVERY", two_step_image=True)if recovery_two_step_image:if output_zip:recovery_two_step_image.AddToZip(output_zip)else:recovery_two_step_image.WriteToDir(OPTIONS.input_tmp)banner("system")system_img_path = AddSystem(output_zip, recovery_img=recovery_image, boot_img=boot_image)vendor_img_path = Noneoem_img_path = Noneif has_vendor:banner("vendor")vendor_img_path = AddVendor(output_zip)if has_oem:banner("oem")oem_img_path = AddOem(output_zip)if has_system_other:banner("system_other")AddSystemOther(output_zip)if not OPTIONS.is_signing:banner("userdata")AddUserdata(output_zip)banner("cache")AddCache(output_zip)if OPTIONS.info_dict.get("board_bpt_enable") == "true":banner("partition-table")AddPartitionTable(output_zip)dtbo_img_path = Noneif OPTIONS.info_dict.get("has_dtbo") == "true":banner("dtbo")dtbo_img_path = AddDtbo(output_zip)if OPTIONS.info_dict.get("avb_enable") == "true":banner("vbmeta")boot_contents = boot_image.WriteToTemp()AddVBMeta(output_zip, boot_contents.name, system_img_path,vendor_img_path, oem_img_path, dtbo_img_path)# For devices using A/B update, copy over images from RADIO/ and/or# VENDOR_IMAGES/ to IMAGES/ and make sure we have all the needed# images ready under IMAGES/. All images should have '.img' as extension.banner("radio")ab_partitions = os.path.join(OPTIONS.input_tmp, "META", "ab_partitions.txt")if os.path.exists(ab_partitions):with open(ab_partitions, 'r') as f:lines = f.readlines()# For devices using A/B update, generate care_map for system and vendor# partitions (if present), then write this file to target_files package.care_map_list = []for line in lines:if line.strip() == "system" and ("system_verity_block_device" in OPTIONS.info_dict orOPTIONS.info_dict.get("avb_system_hashtree_enable") == "true"):assert os.path.exists(system_img_path)care_map_list += GetCareMap("system", system_img_path)if line.strip() == "vendor" and ("vendor_verity_block_device" in OPTIONS.info_dict orOPTIONS.info_dict.get("avb_vendor_hashtree_enable") == "true"):assert os.path.exists(vendor_img_path)care_map_list += GetCareMap("vendor", vendor_img_path)if line.strip() == "oem" and ("oem_verity_block_device" in OPTIONS.info_dict orOPTIONS.info_dict.get("avb_oem_hashtree_enable") == "true"):assert os.path.exists(oem_img_path)care_map_list += GetCareMap("oem", oem_img_path)img_name = line.strip() + ".img"prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", img_name)if os.path.exists(prebuilt_path):print("%s already exists, no need to overwrite..." % (img_name,))continueimg_radio_path = os.path.join(OPTIONS.input_tmp, "RADIO", img_name)img_vendor_dir = os.path.join(OPTIONS.input_tmp, "VENDOR_IMAGES")img_oem_dir = os.path.join(OPTIONS.input_tmp, "OEM_IMAGES")if os.path.exists(img_radio_path):if output_zip:common.ZipWrite(output_zip, img_radio_path,os.path.join("IMAGES", img_name))else:shutil.copy(img_radio_path, prebuilt_path)else:for root, _, files in os.walk(img_vendor_dir,img_oem_dir):if img_name in files:if output_zip:common.ZipWrite(output_zip, os.path.join(root, img_name),os.path.join("IMAGES", img_name))else:shutil.copy(os.path.join(root, img_name), prebuilt_path)breakif output_zip:# Zip spec says: All slashes MUST be forward slashes.img_path = 'IMAGES/' + img_nameassert img_path in output_zip.namelist(), "cannot find " + img_nameelse:img_path = os.path.join(OPTIONS.input_tmp, "IMAGES", img_name)assert os.path.exists(img_path), "cannot find " + img_nameif care_map_list:care_map_path = "META/care_map.txt"if output_zip and care_map_path not in output_zip.namelist():common.ZipWriteStr(output_zip, care_map_path, '\n'.join(care_map_list))else:with open(os.path.join(OPTIONS.input_tmp, care_map_path), 'w') as fp:fp.write('\n'.join(care_map_list))if output_zip:OPTIONS.replace_updated_files_list.append(care_map_path)# Radio images that need to be packed into IMAGES/, and product-img.zip.pack_radioimages = os.path.join(OPTIONS.input_tmp, "META", "pack_radioimages.txt")if os.path.exists(pack_radioimages):with open(pack_radioimages, 'r') as f:lines = f.readlines()for line in lines:img_name = line.strip()_, ext = os.path.splitext(img_name)if not ext:img_name += ".img"prebuilt_path = os.path.join(OPTIONS.input_tmp, "IMAGES", img_name)if os.path.exists(prebuilt_path):print("%s already exists, no need to overwrite..." % (img_name,))continueimg_radio_path = os.path.join(OPTIONS.input_tmp, "RADIO", img_name)assert os.path.exists(img_radio_path), \"Failed to find %s at %s" % (img_name, img_radio_path)if output_zip:common.ZipWrite(output_zip, img_radio_path,os.path.join("IMAGES", img_name))else:shutil.copy(img_radio_path, prebuilt_path)if output_zip:common.ZipClose(output_zip)if OPTIONS.replace_updated_files_list:ReplaceUpdatedFiles(output_zip.filename,OPTIONS.replace_updated_files_list)

我們逐段介紹:
(1)

if os.path.isdir(filename):OPTIONS.input_tmp = os.path.abspath(filename)input_zip = Noneelse:OPTIONS.input_tmp, input_zip = common.UnzipTemp(filename)

target-files是目錄,則賦給input_tmp變量,否則(是zip)解壓該zip,解壓后的文件賦給input_temp,從Makefile中的調(diào)用來看,我們這里是目錄。走if語句

(2)

has_vendor = (os.path.isdir(os.path.join(OPTIONS.input_tmp, "VENDOR")) oros.path.exists(os.path.join(OPTIONS.input_tmp, "IMAGES","vendor.img")))has_oem = (os.path.isdir(os.path.join(OPTIONS.input_tmp, "OEM")) oros.path.exists(os.path.join(OPTIONS.input_tmp, "IMAGES","oem.img")))has_system_other = os.path.isdir(os.path.join(OPTIONS.input_tmp,"SYSTEM_OTHER"))

如果input_tmp目錄下有VENDOR目錄 or input_tmp目錄下有IMAGE/vendor.img文件,則has_vendor 為True;
如果input_tmp目錄下有OEM目錄 or input_tmp目錄下有IMAGE/oem.img文件,則has_oem 為True;
如果input_tmp目錄下有SYSTEM_OTHER,則has_system_other 為True

查看target-file(input_tmp)文件,我們發(fā)現(xiàn)has_vendor、has_oem 為True

總結(jié)

以上是生活随笔為你收集整理的OTA整包的制作流程(未完)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。