1.前言
最近在做MTK Android 9.0 的投影项目,使用的是9269芯片,其中有一个功能是投影方位的设定,如正装正投、正装背投。但MTK目前软件架构上,数据耦合度还是很高,没有分离到数据分区,投影方位的设定耦合在/vendor/tvconfig/config/model/customer_1.ini文件中。而公版OTA又不支持差分升级,所以就想到了定制OTA包的方法,大致思路就是解压当前ZIP包,编辑,重新打包,签名。
2.基本步骤
- 1.AOSP编译生成OTA包:mt5862_bga_1g-ota_update.zip
- 2.unzip 解压 mt5862_bga_1g-ota_update.zip
- 3.编辑解压后的文件,例如本文移除了tvconfig.img
- 4.重新压缩打包update.zip
- 5.签名
- 6.验证修改后的ota包
3.详细过程
3.1 解压update.zip到指定目录
- 将编译生成的ota包mt5862_bga_1g-ota_update.zip放置到如下目录,方便操作
- PATH:vendor/mediatek/proprietary_tv/open/common/security
- 选择这个目录,主要是因为所使用的签名文件都在这个路径下,输入命令时候可以少打几个路径
- 创建临时目录: $mkdir ota_dir
- $mv mt5862_bga_1g-ota_update.zip ota_dir/
- $cd ota_dir
- $unzip mt5862_bga_1g-ota_update.zip
builder@android(master):~/code/vendor/mediatek/proprietary_tv/open/common/security$ls
adb media.pk8 mt5862_bga_1g-ota_update.zip platform.pk8 releasekey.pk8 shared.pk8 testkey.pk8 avb_keys media.x509.pem platform.x509.pem releasekey.x509.pem shared.x509.pem testkey.x509.pem
builder@android(master):~/code/vendor/mediatek/proprietary_tv/open/common/security$
builder@android(master):~/code/vendor/mediatek/proprietary_tv/open/common/security$mkdir ota_dir
builder@android(master):~/code/vendor/mediatek/proprietary_tv/open/common/security$mv mt5862_bga_1g-ota_update.zip ota_dir/
builder@android(master):~/code/vendor/mediatek/proprietary_tv/open/common/security/ota_dir$unzip mt5862_bga_1g-ota_update.zip
Archive: mt5862_bga_1g-ota_update.zip
signed by SignApk
extracting: META-INF/com/android/metadata
extracting: compatibility.zip
extracting: system.new.dat.br
extracting: system.patch.dat
extracting: vendor.new.dat.br
extracting: vendor.patch.dat
inflating: 3rd_a.img
inflating: 3rd_rw.img
inflating: FRC-R2.bin
inflating: META-INF/com/google/android/update-binary
inflating: META-INF/com/google/android/updater-script
inflating: RT_PM.bin
inflating: bl31.aes
inflating: boot.img
inflating: dtb.bin
inflating: factory_a.img
inflating: linux_rootfs_a.img
inflating: mboot.bin
inflating: rom_emmc_boot.bin
inflating: system.transfer.list
inflating: tee.aes
inflating: tvcertificate.img
inflating: tvconfig.img
inflating: tvservice.img
inflating: vendor.transfer.list
inflating: META-INF/com/android/otacert
builder@mm-android(master):~/code/vendor/mediatek/proprietary_tv/open/common/security/ota_dir$
mv mt5862_bga_1g-ota_update.zip ../
3.2 编辑OTA文件
目标:移除tvconfig文件,即OTA不升级此分区
3.2.1 编辑 updater-script
- 路径:ota_dir\META-INF\com\google\android\updater-script
- 移除升级脚本中关于tvconfig的部分
package_extract_file("tvconfig.img", "/dev/block/platform/mstar_mci.0/by-name/tvconfig");
3.2.2 删除tvconfig.img文件
- 删除 ota_dir\tvconfig.img 文件
3.2.3 确认OTA签名文件
打开如下文件,后续重新签名后,签名文件要和此文件一致,否则OTA升级时候验证会失败
- ota_dir\META-INF\com\android\otacert
-----BEGIN CERTIFICATE-----
……省略……
XXXXXXXXXXXXXXXXXXXXXX/LfA==
-----END CERTIFICATE-----
3.3 重新打包OTA ZIP包
- 压缩:$zip -qry update.unsigned.zip ota_dir/*
builder@android(master):~/code/vendor/mediatek/proprietary_tv/open/common/security$zip -qry update.unsigned.zip ota_dir/
builder@android(master):~/code/vendor/mediatek/proprietary_tv/open/common/security$ls
adb media.x509.pem platform.pk8 releasekey.x509.pem testkey.pk8
avb_keys mt5862_bga_1g-ota_update.zip platform.x509.pem shared.pk8 testkey.x509.pem
media.pk8 ota_dir releasekey.pk8 shared.x509.pem update.unsigned.zip
builder@android(master):~/code/vendor/mediatek/proprietary_tv/open/common/security$
3.4 重新签名
3.4.1 签名
- 命令:$java -Xmx512m -jar -Djava.library.path=“/home/code/out/host/linux-x86/lib64/” /home/code/out/host/linux-x86/framework/signapk.jar -w releasekey.x509.pem releasekey.pk8 update.unsigned.zip update.signed.zip
builder@android(master):~/code/vendor/mediatek/proprietary_tv/open/common/security$java -Xmx512m -jar -Djava.library.path="/home/code/out/host/linux-x86/lib64/" /home/code/out/host/linux-x86/framework/signapk.jar -w releasekey.x509.pem releasekey.pk8 update.unsigned.zip update.signed.zip
3.4.2 比对otacert签名文件
- 打开update.signed.zip的otacert文件,和3.2.3节的同名文件做对比
- 确认二者一致,则说明你用对了签名文件
3.5 验证OTA文件
3.5.1 说明
am start -n com.android.tv.settings/.MainSettings
本文使用原生Android settings的ota local update功能验证
- 手动修改下/vendor/tvconfig/config/model/customer_1.ini文件,或者复制一份
- 升级完成,验证,修改的文件依旧存在,验证通过,OK~
3.5.2 图示
-打开AOSP原生settings
- 根据升级提示,需要将zip包命名为: update_signed.zip
- 出现 [UPDATE] 按钮后,点击即可测试OTA本地升级
4.结束语
关键的动作来袭……
- 解压缩的命令,需严格按本文提示操作:unzip mt5862_bga_1g-ota_update.zip