本文转载自:http://blog.csdn.net/mu0206mu/article/details/7465603

      Android系统Recovery工作原理之使用update.zip升级过程分析(九)---updater-script脚本语法简介以及执行流程

 

 

目前update-script脚本格式是edify,其与amend有何区别,暂不讨论,我们只分析其中主要的语法,以及脚本的流程控制。

一、update-script脚本语法简介:

我们顺着所生成的脚本来看其中主要涉及的语法。

1.assert(condition):如果condition参数的计算结果为False,则停止脚本执行,否则继续执行脚本。

2.show_progress(frac,sec):frac表示进度完成的数值,sec表示整个过程的总秒数。主要用与显示UI上的进度条。

3.format(fs_type,partition_type,location):fs_type,文件系统类型,取值一般为“yaffs2”或“ext4”。Partition_type,分区类型,一般取值为“MTD”或则“EMMC”。主要用于格式化为指定的文件系统。事例如下:format(”yaffs2”,”MTD”,”system”)。

4.mount(fs_type,partition_type,location,mount_point):前两个参数同上,location要挂载的设备,mount_point挂载点。作用:挂载一个文件系统到指定的挂载点。

5.package_extract_dir(src_path,destination_path):src_path,要提取的目录,destination_path目标目录。作用:从升级包内,提取目录到指定的位置。示例:package_extract_dir(“system”,”/system”)。

6.symlink(target,src1,src2,……,srcN):target,字符串类型,是符号连接的目标。SrcX代表要创建的符号连接的目标点。示例:symlink(“toolbox”,”/system/bin/ps”),建立指向toolbox符号连接/system/bin/ps,值得注意的是,在建立新的符号连接之前,要断开已经存在的符号连接。

7.set_perm(uid,gid,mode,file1,file2,……,fileN):作用是设置单个文件或则一系列文件的权限,最少要指定一个文件。

8.set_perm_recursive(uid,gid,mode,dir1,dir2,……,dirN):作用同上,但是这里同时改变的是一个或多个目录及其文件的权限。

9.package_extract_file(srcfile_path,desfile_paht):srcfile_path,要提取的文件,desfile_path,提取文件的目标位置。示例:package_extract_file(“boot.img”,”/tmp/boot.img”)将升级包中的boot.img文件拷贝到内存文件系统的/tmp下。

10.write_raw_image(src-image,partition):src-image源镜像文件,partition,目标分区。作用:将镜像写入目标分区。示例:write_raw_image(“/tmp/boot.img”,”boot”)将boot.img镜像写入到系统的boot分区。

11.getprop(key):通过指定key的值来获取对应的属性信息。示例:getprop(“ro.product.device”)获取ro.product.device的属性值。

二、updater-script脚本执行流程分析:

先看一下在测试过程中用命令make otapackage生成的升级脚本如下:

  1. assert(!less_than_int(1331176658, getprop("ro.build.date.utc")));
  2. assert(getprop("ro.product.device") == "tcc8800" ||
  3. getprop("ro.build.product") == "tcc8800");
  4. show_progress(0.500000, 0);
  5. format("yaffs2", "MTD", "system");
  6. mount("yaffs2", "MTD", "system", "/system");
  7. package_extract_dir("recovery", "/system");
  8. package_extract_dir("system", "/system");
  9. symlink("busybox", "/system/bin/cp", "/system/bin/grep",
  10. "/system/bin/tar", "/system/bin/unzip",
  11. "/system/bin/vi");
  12. symlink("toolbox", "/system/bin/cat", "/system/bin/chmod",
  13. "/system/bin/chown", "/system/bin/cmp", "/system/bin/date",
  14. "/system/bin/dd", "/system/bin/df", "/system/bin/dmesg",
  15. "/system/bin/getevent", "/system/bin/getprop", "/system/bin/hd",
  16. "/system/bin/id", "/system/bin/ifconfig", "/system/bin/iftop",
  17. "/system/bin/insmod", "/system/bin/ioctl", "/system/bin/ionice",
  18. "/system/bin/kill", "/system/bin/ln", "/system/bin/log",
  19. "/system/bin/ls", "/system/bin/lsmod", "/system/bin/lsof",
  20. "/system/bin/mkdir", "/system/bin/mount", "/system/bin/mv",
  21. "/system/bin/nandread", "/system/bin/netstat",
  22. "/system/bin/newfs_msdos", "/system/bin/notify", "/system/bin/printenv",
  23. "/system/bin/ps", "/system/bin/reboot", "/system/bin/renice",
  24. "/system/bin/rm", "/system/bin/rmdir", "/system/bin/rmmod",
  25. "/system/bin/route", "/system/bin/schedtop", "/system/bin/sendevent",
  26. "/system/bin/setconsole", "/system/bin/setprop", "/system/bin/sleep",
  27. "/system/bin/smd", "/system/bin/start", "/system/bin/stop",
  28. "/system/bin/sync", "/system/bin/top", "/system/bin/umount",
  29. "/system/bin/uptime", "/system/bin/vmstat", "/system/bin/watchprops",
  30. "/system/bin/wipe");
  31. set_perm_recursive(0, 0, 0755, 0644, "/system");
  32. set_perm_recursive(0, 2000, 0755, 0755, "/system/bin");
  33. set_perm(0, 3003, 02750, "/system/bin/netcfg");
  34. set_perm(0, 3004, 02755, "/system/bin/ping");
  35. set_perm(0, 2000, 06750, "/system/bin/run-as");
  36. set_perm_recursive(1002, 1002, 0755, 0440, "/system/etc/bluetooth");
  37. set_perm(0, 0, 0755, "/system/etc/bluetooth");
  38. set_perm(1000, 1000, 0640, "/system/etc/bluetooth/auto_pairing.conf");
  39. set_perm(3002, 3002, 0444, "/system/etc/bluetooth/blacklist.conf");
  40. set_perm(1002, 1002, 0440, "/system/etc/dbus.conf");
  41. set_perm(1014, 2000, 0550, "/system/etc/dhcpcd/dhcpcd-run-hooks");
  42. set_perm(0, 2000, 0550, "/system/etc/init.goldfish.sh");
  43. set_perm(0, 0, 0544, "/system/etc/install-recovery.sh");
  44. set_perm_recursive(0, 0, 0755, 0555, "/system/etc/ppp");
  45. set_perm_recursive(0, 2000, 0755, 0755, "/system/xbin");
  46. set_perm(0, 0, 06755, "/system/xbin/librank");
  47. set_perm(0, 0, 06755, "/system/xbin/procmem");
  48. set_perm(0, 0, 06755, "/system/xbin/procrank");
  49. set_perm(0, 0, 06755, "/system/xbin/su");
  50. set_perm(0, 0, 06755, "/system/xbin/tcpdump");
  51. show_progress(0.200000, 0);
  52. show_progress(0.200000, 10);
  53. assert(package_extract_file("boot.img", "/tmp/boot.img"),
  54. write_raw_image("/tmp/boot.img", "boot"),
  55. delete("/tmp/boot.img"));
  56. show_progress(0.100000, 0);
  57. unmount("/system");

下面分析下这个脚本的执行过程:

①比较时间戳:如果升级包较旧则终止脚本的执行。

②匹配设备信息:如果和当前的设备信息不一致,则停止脚本的执行。

③显示进度条:如果以上两步匹配则开始显示升级进度条。

④格式化system分区并挂载。

⑤提取包中的recovery以及system目录下的内容到系统的/system下。

⑥为/system/bin/下的命令文件建立符号连接。

⑦设置/system/下目录以及文件的属性。

⑧将包中的boot.img提取到/tmp/boot.img。

⑨将/tmp/boot.img镜像文件写入到boot分区。

⑩完成后卸载/system。

以上就是updater-script脚本中的语法,及其执行的具体过程。通过分析其执行流程,我们可以发现在执行过程中,并未将升级包另外解压到一个地方,而是需要什么提取什么。值得主要的是在提取recovery和system目录中的内容时,一并放在了/system/下。在操作的过程中,并未删除或改变update.zip包中的任何内容。在实际的更新完成后,我们的update.zip包确实还存在于原来的位置。

三、总结

以上的九篇着重分析了android系统中Recovery模式中的一种,即我们做好的update.zip包在系统更新时所走过的流程。其核心部分就是Recovery服务的工作原理。其他两种FACTORY RESET、ENCRYPTED FILE SYSTEM ENABLE/DISABLE与OTA INSTALL是相通的。重点是要理解Recovery服务的工作原理。另外详细分析其升级过程,对于我们在实际升级时,可以根据我们的需要做出相应的修改。

不足之处,请大家不吝指正!

Android系统Recovery工作原理之使用update.zip升级过程分析(九)---updater-script脚本语法简介以及执行流程【转】的更多相关文章

  1. Android系统Recovery工作原理之使用update.zip升级过程分析(八)---解析并执行升级脚本updater-script【转】

    本文转载自:http://blog.csdn.net/mu0206mu/article/details/7465551  Android系统Recovery工作原理之使用update.zip升级过程分 ...

  2. Android系统Recovery工作原理之使用update.zip升级过程分析(六)---Recovery服务流程细节【转】

    本文转载自:http://blog.csdn.net/mu0206mu/article/details/7465439  Android系统Recovery工作原理之使用update.zip升级过程分 ...

  3. Android系统Recovery工作原理之使用update.zip升级过程分析(一)

    通过分析update.zip包在具体Android系统升级的过程,来理解Android系统中Recovery模式服务的工作原理.我们先从update.zip包的制作开始,然后是Android系统的启动 ...

  4. Android系统Recovery工作原理之使用update.zip升级过程分析(一)---update.zip包的制作【转】

    本文转载自:http://blog.csdn.net/mu0206mu/article/details/7399822 这篇及以后的篇幅将通过分析update.zip包在具体Android系统升级的过 ...

  5. Android系统Recovery工作原理之使用update.zip升级过程分析(七)---Recovery服务的核心install_package函数【转】

    本文转载自:http://blog.csdn.net/mu0206mu/article/details/7465514 一.       Recovery服务的核心install_package(升级 ...

  6. Android系统Recovery工作原理之使用update.zip升级过程分析(三)【转】

    本文转载自:http://blog.csdn.net/mu0206mu/article/details/7464699 以下的篇幅开始分析我们在上两个篇幅中生成的update.zip包在具体更新中所经 ...

  7. Android系统Recovery工作原理之使用update.zip升级过程---updater-script脚本语法简介以及执行流程(转)

    目前update-script脚本格式是edify,其与amend有何区别,暂不讨论,我们只分析其中主要的语法,以及脚本的流程控制. 一.update-script脚本语法简介: 我们顺着所生成的脚本 ...

  8. Android系统Recovery工作原理

    Android系统Recovery工作原理之使用update.zip升级过程分析(一)---update.zip包的制作 http://blog.csdn.net/mu0206mu/article/d ...

  9. (转)Android 系统 root 破解原理分析

    现在Android系统的root破解基本上成为大家的必备技能!网上也有很多中一键破解的软件,使root破解越来越容易.但是你思考过root破解的 原理吗?root破解的本质是什么呢?难道是利用了Lin ...

随机推荐

  1. SAS学习笔记之《SAS编程与数据挖掘商业案例》(3)变量操作、观测值操作、SAS数据集管理

    SAS学习笔记之<SAS编程与数据挖掘商业案例>(3)变量操作.观测值操作.SAS数据集管理 1. SAS变量操作的常用语句 ASSIGNMENT 创建或修改变量 SUM 累加变量或表达式 ...

  2. centos安装指定mysql

    mysql下载地址:http://repo.mysql.com/ nginx下载地址 我下载是这个 http://nginx.org/packages/centos/7/noarch/RPMS/ngi ...

  3. jquery操作元素之间相邻的元素的获取方式

    <!DOCTYPE html><html> <head> <style> .siblings * { display: block; border: 2 ...

  4. HDU 1907 John(博弈)

    题目 参考了博客:http://blog.csdn.net/akof1314/article/details/4447709 //0 1 -2 //1 1 -1 //0 2 -1 //1 2 -1 / ...

  5. 基于jquery的常见函数封装

    /// <reference path="jquery-1.8.0.min.js" />/** DIV或元素居中* @return*/jQuery.fn.mCenter ...

  6. ListView学习(一)

    最近了解了LIstView的用法,在听了孙老师的课程后,终于对Adapter有了一定的理解,特作此文记之. ListView在App当中应用相当广泛,比如QQ好友列表.微博等等,都是某种特定的列表,所 ...

  7. python--(十步代码学会线程)

    python--(十步代码学会线程) 一.线程的创建 Thread实例对象的方法 # isAlive(): 返回线程是否活动的. # getname(): 返回线程名. # setName(): 设置 ...

  8. STM32_NVIC寄存器详解

    在MDK内,与NVIC相关的寄存器,MDK为其定义了如下的结构体:  typedef struct  {        vu32   ISER[2];    //2个32位中断使能寄存器分别对应到60 ...

  9. vue 组件通信传值

    父子组件通信: 子组件 <template> <div> <h3 @click="alerrt"> 我是子组件一</h3> < ...

  10. 费用最少的一款赛门铁克SSL证书

    Symantec Secure Site SSL证书,验证域名所有权和企业信息,属于Symantec Class 3企业(OV)验证 级SSL证书,为40位/56位/128/256位自适应加密,目前连 ...