最近由于工作需要接触 Android , 首要任务就是制作OTA升级包,虽然每天都在接触Android产品,但 Android 开发 对于我来说感觉好陌生,兴庆的是还有这个几乎无所不能的网络,还有热心肠的网民们的帮助,经过不尽的努力,终于对它有些眉目,闲话多说了, 下面以(RK 的 Sofia3GR 方案)来分享一下给OTA添加校验标识经验。
1、首先必须要了解ota升级原理以及phony脚本, 这个我就不多说了,网上资料一大把。
2、给系统添加一个属性字段
Sofia3GR 添加属性字段是在device\rockchip\sofia3gr\sofia3gr.mk里面:我添加 ro.product.author = TangYin 属性。
然后执行make installclean 、 make -j8 、 ./mkimage.sh SF_3GR-cars-mehome-mn34227.dtb ota 编译生成ota 包, 利用SD卡烧写 到板上。
在板上使用getprop 命令可以查看到, 也可cat /system/build.prop文件。
3、添加 ro.product.author 检测标识
主要改动\build\tools\releasetools目录下的两个文件(ota_from_target_files和edify_generator.py)
a、在edify_generator.py 文件中添加如下定义
def AssertUpdateAuthor(self, update_author):
"""Assert that the update_author identifier is the given string."""
cmd = ('getprop("ro.product.author") == "%s" || '
'abort("This package is for \\"%s\\" update_author; '
'this is a \\"" + getprop("ro.product.author") + "\\".");'
) % (update_author, update_author)
self.script.append(cmd)
b、在ota_from_target_files 文件中的 AppendAssertions 函数里面添加如下:
def AppendAssertions(script, info_dict, oem_dict = None):
oem_props = info_dict.get("oem_fingerprint_properties")
if oem_props is None or len(oem_props) == 0:
device = GetBuildProp("ro.product.device", info_dict)
script.AssertDevice(device)
update_author = GetBuildProp("ro.product.author", info_dict)
script.AssertUpdateAuthor(update_author)
else:
if oem_dict is None:
raise common.ExternalError("No OEM file provided to answer expected assertions")
for prop in oem_props.split():
if oem_dict.get(prop) is None:
raise common.ExternalError("The OEM file is missing the property %s" % prop)
script.AssertOemProperty(prop, oem_dict.get(prop))
c、在ota_from_target_files 文件中的 WriteFullOTAPackage函数里面的metdata 字段里面添加如下:
metadata = {"post-build": CalculateFingerprint(
oem_props, oem_dict, OPTIONS.info_dict),
"pre-device": GetOemProperty("ro.product.device", oem_props, oem_dict,
OPTIONS.info_dict),
"post-timestamp": GetBuildProp("ro.build.date.utc",
OPTIONS.info_dict),
"update_author": GetBuildProp("ro.product.author",
OPTIONS.info_dict),
}
修改好这俩个文件之后,执行./mkimage.sh SF_3GR-cars-mehome-mn34227.dtb ota, 于是在生成的OTA包里面的update-script脚 本里会新增了如下语句:
getprop("ro.product.author") == "TangYin" || abort("This package is for \"TangYin\" update_author; this is a \"" +getprop("ro.product.author") + "\".");
这样在进行OTA升级时, 首先回去获取系统里的ro.product.author 属性值来与TangYi属性值比较,如果不一样, 就停止升级。
4、 测试
a、把sofia3gr.mk里面的 ro.product.author = TangYin ,则生成出来的OTA包里面的update-script脚本里有如下语句:
getprop("ro.product.author") == "TangYin" || abort("This package is for \"TangYin\" update_author; this is a \"" + getprop("ro.product.author") + "\".");
因为系统里的 ro.product.author 的属性值也为 "TangYin" ,所以OTA升级成功:
b、把sofia3gr.mk里面的 ro.product.author = XieWenDong ,则生成出来的OTA升级包里的update-script脚本里有如下语句:
getprop("ro.product.author") == "XieWenDong" || abort("This package is for \"XieWenDong\" update_author; this is a \"" + getprop("ro.product.author") + "\".");
因为系统里的 ro.product.author 的属性值为 "TangYin" ,所以OTA升级失败:
到此,给OTA包添加检测标识结束, 希望本文能给需要的朋友带来帮助 !!!