众所周知,OTA更新有两种方式,一种是网上直接download的线上模式,一种是SD卡升级模式,在MTK中,升级ota的时候传进来的路径需要通过转换成外部SD卡或者内部EMMC的路径,然后recovery会去通过判断command里的参数来执行对应的OTA升级包:
对应的,在bootable/recovery/mt_recovery.cpp中找到:
这个函数,这个函数的作用就是做路径转换。
const char * mt_main_init_sys_fw_upgrade(const char *update_package)
比如我要转换成内部EMMC的路径(一般线上升级的升级包就下载到相应的目录下,这个自己去定制)
printf("yyx modify mkdir :%s : %s\n",__DATE__,__TIME__); if (strncmp(update_package, "/storage/emulated/0/", 20) == 0) { int len = strlen(update_package) + 15; char* modified_path = (char*)malloc(len); strlcpy(modified_path, "/data/media/0/", len); strlcat(modified_path, update_package+20, len); printf("==>(replacing path \"%s\" with \"%s\")\n", update_package, modified_path); update_package = modified_path; }
最终这个update_package字符串指针就是我们要更新OTA包的路径。
如果是外部SD卡,我可以自己定义一个路径:
if ( strncmp(update_package, "/mnt/external_sd/", 17) == 0) { int len = strlen(update_package) + 17; char* modified_path = (char*)malloc(len); strlcpy(modified_path, "/sdcard/", len); strlcat(modified_path, update_package+17, len); printf("==>(replacing path \"%s\" with \"%s\")\n", update_package, modified_path); update_package = modified_path; }
当然,我也可以对OTA包加密后,再传进来,然后在对应的程序段进行解密后再升级,这些需要自己定制recovery的源代码。