如何给Android的OTA包添加校验标识

       

      最近由于工作需要接触 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包添加检测标识结束, 希望本文能给需要的朋友带来帮助    !!!


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

y20082478

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值