安卓OTA升级系统解析下

安卓OTA升级文件的制作中提到updater-script的功能。这里详细介绍脚本是如何生成的。
updater-script是我们升级时所具体使用到的脚本文件,它主要用以控制升级流程的主要逻辑。具体位置位于更新包中/META-INFO/com/google/android/目录下,在我们制作升级包的时候产生。
前面有个介绍。/build/tools/releasetools/目录下的模块edify_generator作为一个抽象的脚本生成器,用来生成edify脚本。这里的edify脚本指的就是updater-script-升级安装脚本,它是一个文本文件。而edify是用于从.zip文件中安装CyanogenMod和其它软件的简单脚本语言。edify脚本不一定是用于更新固件。它可以用来替换/添加/删除特定的文件,甚至格式分区。通常情况下,edify脚本运行于用户在恢复模式中选择“刷写zip”时。
script = edify_generator.EdifyGenerator(3, OPTIONS.info_dict)
那么updater-script中如何自动一步一步生成每一个脚本指令或者脚本语句呢,这里我们简单举几个例子给大家作为一个参考:

  • 对比固件和ota升级包的版本,ota版本低则不升级
    这里写图片描述
    上面的AssertOlderBuild是自己定义的一个方法,主要功能是比较ota升级包的ro.custom.build.version 和系统的ro.custom.build.version版本好,ota版本高则升级,否则提示不能升级
    //从OPTIONS.info_dict中获取当前ota的ro.custom.build.version,ro.custom.build.version为build.prop在前期已经解析到OPTIONS.info_dict中
  custom_version=GetBuildProp("ro.custom.build.version", OPTIONS.info_dict)
  script.AssertUpVersion(custom_version) //调用edify_generator.py中定义的AssertUpVersion

  def AssertUpVersion(self, updateVersion):
    """Assert that the build on the device is older 
    than the given ro.custom.build.version."""
    cmd = (
        '(greater_than_cur_ver("%s", getprop("ro.custom.build.version"))) || '
         'abort("Can\'t install this package \\"%s\\" over upper version '
         'build (" + getprop("ro.custom.build.version") + ").");'
         ) % (updateVersion,updateVersion) #后面为传入的参数
    self.script.append(cmd)

greater_than_cur_ver为在recovery中注册的命令

//bootable\recovery\edify\expr.c

Value* GreaterThanCurrentVersion(const char *name,State *state ,int argc, Expr* argv[]){

    char* currentVersion=NULL;
    char* updateVersion=NULL;
    int len =0,i=0;
    if(argc!=2){
        free(state->errmsg);
        state->errmsg = strdup("GreaterThanCurrentVersion expects 2 arguments");
        return NULL;
    }
    /*
        verson strings is such as :StreamBox_V2.25 
        StreamBox_V2.26 is greater than StreamBox_V2.25 .
        currentVersion and updateVersion must have the same format
    */
    currentVersion=argv[1];
    updateVersion=argv[0];

    printf("currentVersion=%s updateVersion =%s \n", currentVersion,updateVersion);

    len = strlen(currentVersion) ;
    for(i=0 ; i<len ; i++){
        if(currentVersion[i]<updateVersion[i]){
            //break;
            printf( "len=%d updateVersion is greater than currentVersion\n", len);
            return StringValue(strdup("ok"));
        }
    }

    printf("exit GreaterThanCurrentVersion");
    return NULL;

}

void RegisterBuiltins() {
    RegisterFunction("ifelse", IfElseFn);
    RegisterFunction("abort", AbortFn);
    RegisterFunction("assert", AssertFn);
    RegisterFunction("concat", ConcatFn);
    RegisterFunction("is_substring", SubstringFn);
    RegisterFunction("stdout", StdoutFn);
    RegisterFunction("sleep", SleepFn);

    RegisterFunction("less_than_int", LessThanIntFn);
    RegisterFunction("greater_than_int", GreaterThanIntFn);
    RegisterFunction("greater_than_cur_ver",GreaterThanCurrentVersion);//注册命令!
}

最终会在脚本中生成如下语句:
这里写图片描述
StreamBox_V2.26为当前ota包的版本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值