From 094984884151d74498876f66b64f9cf576a91ac7 Mon Sep 17 00:00:00 2001 From: Alexandre Roux D'Anzi Date: Thu, 14 Jan 2021 14:07:33 +0100 Subject: [PATCH] new option to flash any raw image from ota zip : BOARD_PACK_IMAGES := image:target for example BOARD_PACK_IMAGES := recovery.img:recovery --- core/Makefile | 3 +++ tools/releasetools/add_img_to_target_files.py | 24 +++++++++++++++++++ tools/releasetools/ota_from_target_files.py | 20 ++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/core/Makefile b/core/Makefile index b2e936e090..ad42b51436 100644 --- a/core/Makefile +++ b/core/Makefile @@ -4180,6 +4180,9 @@ endif # BOARD_PREBUILT_DTBOIMAGE @# INSTALLED_RADIOIMAGE_TARGET. $(hide) $(foreach part,$(BOARD_PACK_RADIOIMAGES), \ echo $(part) >> $(zip_root)/META/pack_radioimages.txt;) + @# Any images specified will be added into ota.zip + $(hide) $(foreach part,$(BOARD_PACK_IMAGES), \ + echo $(part) >> $(zip_root)/META/pack_images.txt;) @# Run fs_config on all the system, vendor, boot ramdisk, @# and recovery ramdisk files in the zip, and save the output ifdef BUILDING_SYSTEM_IMAGE diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py index 5e1cbba39d..e78ed3ee44 100755 --- a/tools/releasetools/add_img_to_target_files.py +++ b/tools/releasetools/add_img_to_target_files.py @@ -920,6 +920,30 @@ def AddImagesToTargetFiles(filename): if os.path.exists(pack_radioimages_txt): with open(pack_radioimages_txt) as f: AddPackRadioImages(output_zip, f.readlines()) + # images that need to be packed into IMAGES/, and product-img.zip. + pack_images = os.path.join( + OPTIONS.input_tmp, "META", "pack_images.txt") + if os.path.exists(pack_images): + banner("images") + with open(pack_images, 'r') as f: + lines = f.readlines() + for line in lines: + img_inf = line.strip().split(":") + img_path = img_inf[0].strip() + print("img_path" +img_path) + img_name = os.path.basename(img_path) + _, 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,)) + continue + if output_zip: + common.ZipWrite(output_zip, prebuilt_path, + os.path.join("IMAGES", img_name)) + else: + shutil.copy(img_path, prebuilt_path) if output_zip: common.ZipClose(output_zip) diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py index b9176cba2f..8c0b7151cf 100755 --- a/tools/releasetools/ota_from_target_files.py +++ b/tools/releasetools/ota_from_target_files.py @@ -715,6 +715,15 @@ def _WriteRecoveryImageToBoot(script, output_zip): # The "recovery.img" entry has been written into package earlier. script.WriteRawImage("/boot", "recovery.img") +def WriteImage(image, dest, script, output_zip): + img_path = os.path.join( + OPTIONS.input_tmp, "IMAGES", image) + common.ZipWrite( + output_zip, img_path, image) + logger.info( + "adding image: using %s", image) + script.WriteRawImage("/"+dest, image) + def HasRecoveryPatch(target_files_zip): namelist = [name for name in target_files_zip.namelist()] @@ -1112,6 +1121,17 @@ else if get_stage("%(bcb_dev)s") == "3/3" then if boot_img != None: script.WriteRawImage("/boot", "boot.img") + pack_images = os.path.join(OPTIONS.input_tmp, "META", "pack_images.txt") + if os.path.exists(pack_images): + with open(pack_images, 'r') as f: + lines = f.readlines() + for line in lines: + print(line) + img_inf = line.strip().split(":") + + WriteImage(os.path.basename(img_inf[0]), img_inf[1], script, output_zip) + + script.ShowProgress(0.1, 10) device_specific.FullOTA_InstallEnd() -- GitLab