2022年11月2日 星期三

[Android] OTA image只更新bootloader

轉貼本網站文章請註明出處 from Awaysu
https://awaysu-programming.blogspot.com 


一般更新軟體方式有以下二種:
1. 透過Bootloader更新:
    通常為晶片廠商給予的更新方式,透過此方式安全機制被關閉沒有限制.

2. 透過OTA更新
    為預設android更新方式,更新前會先檢查必須是相同的fingerprint和sign key才能做更新.


通常已出貨的產品已帶有客戶軟體,並且會把bootloader更新的功能關掉,但是如產品要做RAM時候,會需要更新回工廠測試用的軟體,這時候就必須有一個OTA image是把Bootloader更新開啟的版本,更新後就可以使用Bootloader方式更新.做成OTA image的話其實不需要也更新system和vendor等parition,所以下敘為OTA image只更新bootloader方法. 因Android有recovery mode和A/B system二種方式,下面依據不同方式來做修改:

1. Recovery mode:

diff -Naur a/build/make/tools/releasetools/common.py b/build/make/tools/releasetools/common.py
--- a/build/make/tools/releasetools/common.py   2020-05-26 15:14:31.486036205 +0800
+++ b/build/make/tools/releasetools/common.py   2020-05-26 15:18:31.344028332 +0800
@@ -1579,17 +1579,18 @@
     return self._required_cache

   def WriteScript(self, script, output_zip, progress=None):
-    if not self.src:
+    script.Print("Cancel WriteScript")
+#    if not self.src:
       # write the output unconditionally
-      script.Print("Patching %s image unconditionally..." % (self.partition,))
-    else:
-      script.Print("Patching %s image after verification." % (self.partition,))
-
-    if progress:
-      script.ShowProgress(progress, 0)
-    self._WriteUpdate(script, output_zip)
-    if OPTIONS.verify:
-      self._WritePostInstallVerifyScript(script)
+#      script.Print("Patching %s image unconditionally..." % (self.partition,))
+#    else:
+#      script.Print("Patching %s image after verification." % (self.partition,))
+#
+#    if progress:
+#      script.ShowProgress(progress, 0)
+#    self._WriteUpdate(script, output_zip)
+#    if OPTIONS.verify:
+#      self._WritePostInstallVerifyScript(script)

   def WriteStrictVerifyScript(self, script):
     """Verify all the blocks in the care_map, including clobbered blocks.
diff -Naur a/build/make/tools/releasetools/ota_from_target_files.py b/build/make/tools/releasetools/ota_from_target_files.py
--- a/build/make/tools/releasetools/ota_from_target_files.py    2020-05-26 15:14:24.790092278 +0800
+++ b/build/make/tools/releasetools/ota_from_target_files.py    2020-05-26 15:18:51.279861498 +0800
@@ -846,11 +846,11 @@

   AddCompatibilityArchiveIfTrebleEnabled(input_zip, output_zip, target_info)

-  common.CheckSize(boot_img.data, "boot.img", target_info)
-  common.ZipWriteStr(output_zip, "boot.img", boot_img.data)
+#  common.CheckSize(boot_img.data, "boot.img", target_info)
+#  common.ZipWriteStr(output_zip, "boot.img", boot_img.data)

-  script.ShowProgress(0.05, 5)
-  script.WriteRawImage("/boot", "boot.img")
+#  script.ShowProgress(0.05, 5)
+#  script.WriteRawImage("/boot", "boot.img")

   script.ShowProgress(0.2, 10)
   device_specific.FullOTA_InstallEnd()


2. A/B system mode
--- a/gtv/device/mediatek-stb/common/BoardConfigCommon.mk    2022-10-31 09:06:38.100755542 +0800
+++ b/gtv/device/mediatek-stb/common/BoardConfigCommon.mk    2022-10-31 13:36:00.723097043 +0800
@@ -86,14 +86,14 @@
 BOARD_USES_RECOVERY_AS_BOOT   := $(BOARD_AB_UPDATE_ENABLE)
 ifeq ($(BOARD_AB_UPDATE_ENABLE), true)
 AB_OTA_UPDATER := true
-AB_OTA_PARTITIONS := \
-    vbmeta \
-    boot \
-    system \
-    vendor \
-    dtbo \
-    tvconfig \
-    tvservice
+#AB_OTA_PARTITIONS := \
+#    vbmeta \
+#    boot \
+#    system \
+#    vendor \
+#    dtbo \
+#    tvconfig \
+#    tvservice
 
 endif

--- a/gtv/system/update_engine/scripts/brillo_update_payload      2022-10-31 09:10:11.925108379 +0800
+++ b/gtv/system/update_engine/scripts/brillo_update_payload      2022-10-31 13:36:14.091350529 +0800
@@ -646,17 +646,17 @@
     GENERATOR_ARGS+=( --max_timestamp="${FLAGS_max_timestamp}" )
   fi

-  if [[ -n "${POSTINSTALL_CONFIG_FILE}" ]]; then
-    GENERATOR_ARGS+=(
-      --new_postinstall_config_file="${POSTINSTALL_CONFIG_FILE}"
-    )
-  fi
+ # if [[ -n "${POSTINSTALL_CONFIG_FILE}" ]]; then
+ #   GENERATOR_ARGS+=(
+ #     --new_postinstall_config_file="${POSTINSTALL_CONFIG_FILE}"
+ #   )
+ # fi

-  if [[ -n "{DYNAMIC_PARTITION_INFO_FILE}" ]]; then
-    GENERATOR_ARGS+=(
-      --dynamic_partition_info_file="${DYNAMIC_PARTITION_INFO_FILE}"
-    )
-  fi
+ #if [[ -n "{DYNAMIC_PARTITION_INFO_FILE}" ]]; then
+ #   GENERATOR_ARGS+=(
+ #     --dynamic_partition_info_file="${DYNAMIC_PARTITION_INFO_FILE}"
+ #   )
+ # fi

   echo "Running delta_generator with args: ${GENERATOR_ARGS[@]}"
   "${GENERATOR}" "${GENERATOR_ARGS[@]}" 


另外可以在device/{chip name}/下搜尋*.py檔案,這邊晶片廠商也可能會對OTA步驟做一些修改.


沒有留言:

張貼留言