首页 » 技术分享 » 读懂华为U8825D"updater-script"刷机脚本

读懂华为U8825D"updater-script"刷机脚本

 

U8825D分区表

 ~ # cat proc/partitions
cat proc/partitions
major minor  #blocks  name

179        0    3817472 mmcblk0
179        1         20 mmcblk0p1
179        2        300 mmcblk0p2
179        3     133120 mmcblk0p3
179        4          1 mmcblk0p4
179        5      12288 mmcblk0p5
179        6       4096 mmcblk0p6
179        7       4096 mmcblk0p7
179        8       3072 mmcblk0p8
179        9       3072 mmcblk0p9
179       10       3072 mmcblk0p10
179       11       4096 mmcblk0p11
179       12       8192 mmcblk0p12
179       13      20480 mmcblk0p13
179       14       4096 mmcblk0p14
179       15     196608 mmcblk0p15
179       16      81920 mmcblk0p16
179       17     524288 mmcblk0p17
179       18     655360 mmcblk0p18
179       19    2154496 mmcblk0p19
179       32   15558144 mmcblk1
179       33   15554048 mmcblk1p1

/cache

ex4:/dev/block/mmcblk0p15

/data

ex4:/dev/block/mmcblk0p18

/system

ex4:/dev/block/mmcblk0p17

/cust

ex4:/dev/block/mmcblk0p16

0:root

1000:system

2000:shell

采用注释的办法,初步了解刷机脚本。常用命令和解释贴在文章后面,推荐使用Notepad++编辑脚本。

脚本来源于http://bbs.anzhi.com/thread-6079590-1-1.html

show_progress(0.500000, 0);                                                     显示进度,这个“show_progress”的值依作者不同随意性较大
show_progress(0.1, 0);
ui_print("***************************************");                              双引号之间为显示在屏幕上的英文字符,可随意设定
ui_print("*                                     *");
ui_print("*      Welcome to Lesong vSystem      *");
ui_print("*                                     *");
ui_print("*        huawei U8825D B953  3.0      *");
ui_print("*                                     *");
ui_print("*           URL:http://bbs.shendu.com *");
ui_print("***************************************");
ui_print("Updating data...");
format("ext4", "EMMC", "/dev/block/mmcblk0p18", "0");              格式化"/dev/block/mmcblk0p18"分区,文件系统格式ext4,分区类型emmc,对8825D来说就是ext4,emmc
mount("ext4", "EMMC", "/dev/block/mmcblk0p18", "/data");         挂载“/dev/block/mmcblk0p18”,挂载点为"/data”。操作分区前先要挂载
package_extract_dir("data", "/data");                                          拷贝ROM包里的data目录至手机/data
ui_print("Updating System...");
format("ext4", "EMMC", "/dev/block/mmcblk0p17", "0");               格式化"/dev/block/mmcblk0p17"
mount("ext4", "EMMC", "/dev/block/mmcblk0p17", "/system");     挂载“/dev/block/mmcblk0p17”,挂载点为"/system”
package_extract_dir("system", "/system");                                 拷贝ROM包里的system目录至手机/system
ui_print("Updating cust partition...");
format("ext4", "EMMC", "/dev/block/mmcblk0p16", "0");               格式化"/dev/block/mmcblk0p16"
mount("ext4", "EMMC", "/dev/block/mmcblk0p16", "/cust");          挂载“/dev/block/mmcblk0p16”,挂载点为"/cust”
package_extract_dir("cust", "/cust");                                           拷贝ROM包里的cust目录至手机/cust
show_progress(0.5, 18);                   
symlink("busybox", "/system/xbin/[", "/system/xbin/[[",                “symlink”设置软连接,后边的这一堆指向"/system/xbin/busybox" ,
        "/system/xbin/arp", "/system/xbin/ash", "/system/xbin/awk",                                     - -“可以理解为将B指向A,你以为用的是B,其实用的是A,
        "/system/xbin/basename", "/system/xbin/bbconfig", "/system/xbin/brctl",                     - -有点像windows里的快捷方式 。
        "/system/xbin/bunzip2", "/system/xbin/bzcat", "/system/xbin/bzip2",
        "/system/xbin/cal", "/system/xbin/cat", "/system/xbin/catv",
        "/system/xbin/chgrp", "/system/xbin/chmod", "/system/xbin/chown",
        "/system/xbin/chroot", "/system/xbin/cksum", "/system/xbin/clear",
        "/system/xbin/cmp", "/system/xbin/cp", "/system/xbin/cpio",
        "/system/xbin/cut", "/system/xbin/date", "/system/xbin/dc",
        "/system/xbin/dd", "/system/xbin/depmod", "/system/xbin/devmem",
        "/system/xbin/df", "/system/xbin/diff", "/system/xbin/dirname",
        "/system/xbin/dmesg", "/system/xbin/dnsd", "/system/xbin/dos2unix",
        "/system/xbin/du", "/system/xbin/echo", "/system/xbin/ed",
        "/system/xbin/egrep", "/system/xbin/env", "/system/xbin/expr",
        "/system/xbin/false", "/system/xbin/fdisk", "/system/xbin/fgrep",
        "/system/xbin/find", "/system/xbin/fold", "/system/xbin/free",
        "/system/xbin/freeramdisk", "/system/xbin/fuser", "/system/xbin/getopt",
        "/system/xbin/grep", "/system/xbin/gunzip", "/system/xbin/gzip",
        "/system/xbin/head", "/system/xbin/hexdump", "/system/xbin/id",
        "/system/xbin/ifconfig", "/system/xbin/insmod", "/system/xbin/install",
        "/system/xbin/ip", "/system/xbin/kill", "/system/xbin/killall",
        "/system/xbin/killall5", "/system/xbin/length", "/system/xbin/less",
        "/system/xbin/ln", "/system/xbin/losetup", "/system/xbin/ls",
        "/system/xbin/lsmod", "/system/xbin/lspci", "/system/xbin/lsusb",
        "/system/xbin/lzop", "/system/xbin/lzopcat", "/system/xbin/md5sum",
        "/system/xbin/mkdir", "/system/xbin/mke2fs", "/system/xbin/mkfifo",
        "/system/xbin/mkfs.ext2", "/system/xbin/mknod", "/system/xbin/mkswap",
        "/system/xbin/mktemp", "/system/xbin/modprobe", "/system/xbin/more",
        "/system/xbin/mount", "/system/xbin/mountpoint", "/system/xbin/mv",
        "/system/xbin/netstat", "/system/xbin/nice", "/system/xbin/nohup",
        "/system/xbin/nslookup", "/system/xbin/ntpd", "/system/xbin/od",
        "/system/xbin/patch", "/system/xbin/pgrep", "/system/xbin/pidof",
        "/system/xbin/ping", "/system/xbin/pkill", "/system/xbin/printenv",
        "/system/xbin/printf", "/system/xbin/ps", "/system/xbin/pwd",
        "/system/xbin/rdev", "/system/xbin/readlink", "/system/xbin/realpath",
        "/system/xbin/renice", "/system/xbin/reset", "/system/xbin/rm",
        "/system/xbin/rmdir", "/system/xbin/rmmod", "/system/xbin/route",
        "/system/xbin/run-parts", "/system/xbin/sed", "/system/xbin/seq",
        "/system/xbin/setsid", "/system/xbin/sh", "/system/xbin/sha1sum",
        "/system/xbin/sha256sum", "/system/xbin/sha512sum",
        "/system/xbin/sleep", "/system/xbin/sort", "/system/xbin/split",
        "/system/xbin/stat", "/system/xbin/strings", "/system/xbin/stty",
        "/system/xbin/swapoff", "/system/xbin/swapon", "/system/xbin/sync",
        "/system/xbin/sysctl", "/system/xbin/tac", "/system/xbin/tail",
        "/system/xbin/tar", "/system/xbin/tee", "/system/xbin/telnet",
        "/system/xbin/test", "/system/xbin/tftp", "/system/xbin/time",
        "/system/xbin/top", "/system/xbin/touch", "/system/xbin/tr",
        "/system/xbin/traceroute", "/system/xbin/true", "/system/xbin/tty",
        "/system/xbin/tune2fs", "/system/xbin/umount", "/system/xbin/uname",
        "/system/xbin/uniq", "/system/xbin/unix2dos", "/system/xbin/unlzop",
        "/system/xbin/unzip", "/system/xbin/uptime", "/system/xbin/usleep",
        "/system/xbin/uudecode", "/system/xbin/uuencode", "/system/xbin/vi",
        "/system/xbin/watch", "/system/xbin/wc", "/system/xbin/wget",
        "/system/xbin/which", "/system/xbin/whoami", "/system/xbin/xargs",
        "/system/xbin/yes",
        "/system/xbin/zcat");
symlink("toolbox", "/system/bin/cat", "/system/bin/chmod",                    “symlink”设置软连接,指向"/system/bin/toolbox"
        "/system/bin/chown", "/system/bin/cmp", "/system/bin/date",
        "/system/bin/dd", "/system/bin/df", "/system/bin/dmesg",
        "/system/bin/getevent", "/system/bin/getprop", "/system/bin/hd",
        "/system/bin/id", "/system/bin/ifconfig", "/system/bin/iftop",
        "/system/bin/insmod", "/system/bin/ioctl", "/system/bin/ionice",
        "/system/bin/kill", "/system/bin/ln", "/system/bin/log",
        "/system/bin/ls", "/system/bin/lsmod", "/system/bin/lsof",
        "/system/bin/mkdir", "/system/bin/mount", "/system/bin/mv",
        "/system/bin/nandread", "/system/bin/netstat",
        "/system/bin/newfs_msdos", "/system/bin/notify", "/system/bin/printenv",
        "/system/bin/ps", "/system/bin/r", "/system/bin/reboot",
        "/system/bin/renice", "/system/bin/rm", "/system/bin/rmdir",
        "/system/bin/rmmod", "/system/bin/route", "/system/bin/schedtop",
        "/system/bin/sendevent", "/system/bin/setconsole",
        "/system/bin/setprop", "/system/bin/sleep", "/system/bin/smd",
        "/system/bin/start", "/system/bin/stop", "/system/bin/sync",
        "/system/bin/top", "/system/bin/touch", "/system/bin/umount",
        "/system/bin/uptime", "/system/bin/vmstat", "/system/bin/watchprops",
        "/system/bin/wipe");
        symlink("mksh","/system/bin/sh");
        symlink("Roboto-Bold.ttf", "/system/fonts/DroidSans-Bold.ttf");
        symlink("Roboto-Regular.ttf", "/system/fonts/DroidSans.ttf");
show_progress(0.100000, 0);
symlink("libwiperjni_v01.so","/system/lib/libwiperjni.so");
symlink("wiperiface_v01", "/system/bin/wiperiface");
set_perm_recursive(0, 0, 0755, 0644, "/system");               设置“system”文件夹及其中文件的uid{用户id(user id)}为0(root),Gid{用户组ID(group id)}为0(root组),目录权
set_perm_recursive(0, 0, 0777, 0777, "/system/etc/init.d");                                                                                                 --限为0755,目录内文件权限为0644 。
set_perm_recursive(0, 2000, 0755, 0755, "/system/bin");
set_perm(0, 3003, 06755, "/system/bin/ip");                       设置"/system/bin/ip"文件uid为0,gid为3003,权限为06755,数字都为八进制,实际为6755,前置0。(uid+gid=6)
set_perm(0, 3003, 02750, "/system/bin/netcfg");                                                     
set_perm(0, 3004, 02755, "/system/bin/ping");
set_perm(0, 2000, 06750, "/system/bin/run-as");
set_perm_recursive(1002, 1002, 0755, 0440, "/system/etc/bluetooth");
set_perm(0, 0, 0755, "/system/etc/bluetooth");                          设置"/system/etc/bluetooth"目录uid为0,gid为0,权限为0755
set_perm(1000, 1000, 0640, "/system/etc/bluetooth/auto_pairing.conf");
set_perm(3002, 3002, 0444, "/system/etc/bluetooth/blacklist.conf");
set_perm(1002, 1002, 0440, "/system/etc/dbus.conf");
set_perm(1014, 2000, 0550, "/system/etc/dhcpcd/dhcpcd-run-hooks");
set_perm(0, 2000, 0550, "/system/etc/init.goldfish.sh");
set_perm_recursive(0, 0, 0755, 0555, "/system/etc/ppp");
set_perm_recursive(0, 2000, 0755, 0644, "/system/vendor");
set_perm(0, 2000, 0755, "/system/vendor/lib");
set_perm_recursive(0, 2000, 0755, 0755, "/system/xbin");
set_perm(0, 0, 04755, "/system/bin/bash");
symlink("/system/bin/bash", "/system/bin/sh");
set_perm(0, 1000, 0755, "/system/xbin/busybox");
symlink("/system/xbin/busybox", "/system/bin/busybox");
run_program("/system/xbin/busybox", "--install", "-s", "/system/xbin");       安装busybox到/system/xbin?,参数-s
set_perm(0, 0, 06755, "/system/xbin/su");
show_progress(0.200000, 10);
ui_print("Updating BOOT Image...");
package_extract_file("boot.img", "/dev/block/mmcblk0p12");                      释放"boot.img"到"/dev/block/mmcblk0p12"分区 ,boot.img包含了内核
show_progress(0.1, 0);
unmount("/system");                                                                               卸载"/system"
unmount("/cust");                                                                                    卸载"/cust"
unmount("/data");                                                                                    卸载"/data"
ui_print("***************************************");
ui_print("*                                     *");
ui_print("*                                     *");
ui_print("*                   --Date:2012.12.5  *");
ui_print("***************************************");
ui_print("Installation complete!");
ui_print("Please Reboot!");

简单来说就是格式化分区,挂载分区,拷贝文件,设置权限,卸载分区。

 

dsixda's Android Kitchen



以下为引用

这是Android系统来运行updater-scripts的Edify语言的基本介绍。
大部分的Edify命名都是函数,当调用这些函数结束的时候,会返回数据给脚本。当然,你也可以使用这些函数的返 回 值来确认成功与否,例如:
ifelse(mount("yaffs2", "MTD", "system", "/system") == "system", ui_print("Successfully Mounted!"), ui_print("Mount Failed!");
这个命令会尝试去挂载命名为“system”的“MTD”分区到“/system”。如果挂载成功,脚本会显示“Successfully Mounted!”,否则会显示“Mount Failed!”。

现面是用在Edify的Updater-script中的函数例子:

函数名称: set_perm             设置文件权限

函数语法: set_perm(uid, gid, mode, file1, file2, ..., fileN)

参数详解:

uid------------------------用户ID(user id)                                                                        深入理解SetUID     

Gid-----------------------用户组ID(group id)

Mode--------------------权限模式(permission mode)

fileX----------------------要设置许可的文件(file to set permission on)

作用解释: 设置单个文件或一系列文件的权限,最少指定1个文件,前4个参数是必须的

函数示例: set_perm(0,2000,0550, "system/etc/init.goldfish.sh");设置手机system中的etc/init.goldfish.sh的用户为root,用户组为shell,所有者以及所属用户组成员可以进行读取和执行操作,其他用户无操作权限)

这里0代表用户为root

2000代表用户组为shell

我们来说明0550这组数据,这组数据的最后三位550,分别代表“所有者\组用户\其他用户”的权限,也就是我们在RE管理中“用户\群组\其他”三行。 我们以XXX来表示这三组权限,其中:

×=4 读的权限

×=2 写的权限

×=1 执行的权限

我们必须首先了解用数字表示的属性的含义:0表示没有权限,1表示可执行权限,2表示可写权限,4表示可读权限,然后将其相加。所以数字属性的格式应为3个从0到7的八进制数。

例如,如果想让某个文件的属主有"读/写"二种权限,需要把4(可读)+2(可写)=6(读/写)。若要rwx属性则4+2+1=7;若要rw-属性则4+2=6;若要r-x属性则4+1=5。

常用修改权限的命令:

Set_perm 0 0 0600 ××× (只有所有者有读和写的权限)

Set_perm 0 0 0644 ××× (所有者有读和写的权限,组用户只有读的权限)

Set_perm 0 0 0700 ××× (只有所有者有读和写以及执行的权限)

Set_perm 0 0 0666 ××× (每个人都有读和写的权限)

Set_perm 0 0 0777 ××× (每个人都有读和写以及执行的权限)

 

函数名称: set_perm_recursive               设置文件目录及目录中文件的权限

函数语法: set_perm_recursive(uid, gid, dirmode, filemode, dir1, dir2, ...dirN)

参数详解:

uid----------------------用户ID(user id)

Gid----------------------用户组ID(group id)

Dirmode---------------指定目录内的目录的权限

Filemode--------------指定目录内的文件的权限

dirX----------------------要设置权限的目标

作用解释: 设置单个目录或一系列目录的里面的所有文件的权限,最少指定1个目录,5个参数都是必须的

函数示例: set_perm_recursive 0 0 0755 0644 SYSTEM:app;设置手机system/app文件夹及其中文件的用户为root,用户组为root,app文件夹权限为所有者可以进行读、写、执行操作,其他用户可以进行读取和执行操作,其中的文件的权限为所有者可以进行读写操作,其他用户可以进行读取操作

 

函数名称: ui_print

函数语法: ui_print(msg1, ..., msgN)

参数详解: msg----------------------字符串,要处理过程中输出给用户的信息

作用解释: 在脚本运行的时候,在控制台显示的信息。最少要指定1个参数,你可以指定额外的msg参数,并且它们会连接起来输了

函数示例: ui_print("It's ready!");屏幕打印It's ready!

 

函数名称: run_program

函数语法: run_program(prog, arg1, .., argN)

参数详解:

prog---------------------字符串,要执行的程序

argN--------------------字符串,要执行的程序的运行参数

作用解释: 以指定的参执行程序

函数示例: run_program("/system/xbin/installbusybox.sh");运行installbusybox.sh脚本文件

 

函数名称: symlink

函数语法: symlink(target, src1, src2, ..., srcN)

参数详解:

target--------------------字符串,符号链接的目标

srcX ---------------------字符串,要创建的符号链接的目标点

在创建新的符号链接之前,要断开已经存在的符号链接

函数示例: symlink("toolbox", "/system/bin/ps");建立指向toolbox的符号链接/system/bin/ps

 

函数名称: package_extract_dir

函数语法: package_extract_dir(package_path, destination_path)

参数详解:

package_path----------字符串,升级包内要提取的目录

destination_path-------字符串,提取文件的目标目录

作用解释: 提取升级包内目录中的所有文件到指定的目标目录

函数示例: package_extract_dir("system", "/system");释放ROM包里system文件夹下所有文件和子文件夹至/system

 

函数名称: package_extract_file

函数语法: package_extract_file(package_path) 或 package_extract_file(package_path, destination_path)

参数详解:

package_path----------字符串,升级包内要提取的文件

destination_path-------字符串,提取文件的目标目录

作用解释: 提取升级包内的单个文件到指定的目标目录

函数示例: package_extract_file("my.zip", "/system");解压ROM包里的my.zip文件至/system

 

函数名称: mount

函数语法: mount(fs_type, partition_type, location, mount_point)

参数详解:

fs_type-------------------"yaffs2" 或 "ext4"

partition_type----------"MTD" 或 "EMMC"

location------------------分区(partition) 或 驱动器(device)

mount_poin------------挂载文件系统的目标文件夹(target folder to mount FS)

作用解释: 挂载一个文件系统到指定的挂载点

返 回 值: 挂载成功则返回挂载点,失败返回null

函数示例: mount("MTD", "system", "/system");挂载system分区,设置返回指针"/system”

mount("vfat", "/dev/block/mmcblk1p2", "/system"); 挂载/dev/block/mmcblk1p2,返回指针"/system”

 

函数名称: unmount

函数语法: unmount(mount_point)

参数详解: mount_point-----------字符串,要解除挂载的挂载点

作用解释: 解除文件系统挂载

返 回 值: 解除挂载成功则返回挂载点,失败返回null

函数示例: unmount("/system"); 卸载/system分区


函数名称: format

函数语法: format(fs_type, partition_type, location)

参数详解:

fs_type-----------------字符串,数据为"yaffs2" 或 "ext4"

partition_type----------字符串, "MTD" 或 "EMMC"

location-----------------字符串, 分区(partition) 或 驱动器(device)

作用解释: 格式化为指定的文件系统

函数示例: format("MTD", "system");格式化system分区


函数名称: delete
函数语法: delete(file1, file2, ..., fileN)
参数详解: 字符串,要删除的文件
作用解释: 删除一个文件。最少指定一个文件;多个文件可以做为多个参数指定
函数示例: delete("/data/zipalign.log");删除文件/data/zipalign.log


函数名称: delete_recursive
函数语法: delete_recursive(dir1, dir2,...,dirN)
参数详解: 字符串,要递归删除的目录
作用解释: 删除文件夹及其包含的所有内容。最少指定1个目录;多个目录可以做为多个参数指定
函数示例: delete_recursive("/data/dalvik-cache");删除文件夹/data/dalvik-cache

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的属性值。


补充

U8825D官方recovery.fstab

#/sys_boot        vfat        /dev/block/mmcblk0p3
#/misc            emmc        /dev/block/mmcblk0p7
/boot            emmc        /dev/block/mmcblk0p12
/recovery        emmc        /dev/block/mmcblk0p13
/cache            ext4        /dev/block/mmcblk0p15
/cust            ext4        /dev/block/mmcblk0p16
/system            ext4        /dev/block/mmcblk0p17
/data            ext4        /dev/block/mmcblk0p18   length=-16384
/emmc            vfat        /dev/block/mmcblk0p19
/sdcard            vfat        /dev/block/mmcblk1p1

recovery_mmc.fstab
# mount point    fstype        device            [device2]

# /* < DTS2012031506621  lishubin 20120321 begin */
#/* use new partition order for some partition */
#/* < DTS2012011906026 chendeng 20120120 begin */
/boot        emmc        /dev/block/mmcblk0p12
/cache        ext4        /dev/block/mmcblk0p15
# /* < DTS2012062603367  lizhigang 20120626 begin */
/data        ext4        /dev/block/mmcblk0p18   length=-16384
#/* < DTS2012062603367 lizhigang 20120626 end */
/recovery       emmc            /dev/block/mmcblk0p13
/misc        emmc        /dev/block/mmcblk0p7
/sdcard        vfat        /dev/block/mmcblk1p1    /dev/block/mmcblk1
/system        ext4        /dev/block/mmcblk0p17
/sys_boot    vfat        /dev/block/mmcblk0p3
/fat            vfat        /dev/block/mmcblk0p3
/HWUserData    vfat        /dev/block/mmcblk0p19
#/*< DTS2012020804291 weizhonghui 20120208 begin */
/cust        ext4        /dev/block/mmcblk0p16
#/* DTS2012020804291 weizhonghui 20120208 end >*/
#/* DTS2012011906026 chendeng 20120120 end > */
# /* DTS2012031506621  lishubin 20120321 end > */

以下内容解释了为什么format加0”

 以下内容解释了为什么format要“加0”

笼统的说update-binary就是为updater-script脚本的解释执行提供一些函数的支持,比如format,mount等等。而update-binary提供的函数支持是以函数调用即函数名+形參的形式呈现给调用者,(学过c的都知道)。我们在updater-script脚本调用这些函数时只需根据函数名即实参即可。
简而言之,我们就可以这样理解,要做好刷机包,一定要确保updater-script脚本中语法的正确,这就必须要知道update-binary提供的函数接口。
    下面以一段的update-binary源码为例进行分析,以下为注释
// format(fs_type, partition_type, location,mount_point)
//
//    fs_type="yaffs2" partition_type="MTD"     location=partition fs_size=<bytes> mount_point=<location>
//    fs_type="ext4"   partition_type="EMMC"    location=device    fs_size=<bytes> mount_point=<location>
//    if fs_size == 0, then make_ext4fs uses the entire partition.
//    if fs_size > 0, that is the size to use
//    if fs_size < 0, then reserve that many bytes at the end of the partition

我们发现,format函数提供了4个接口,fs_type, partition_type, location, fs_size, mount_point分别代表文件系统类型如ext4,存储设备类型如emmc,位置,即类似/dev/block/mmcblk0p19,然后是挂载点,如/system,
这样在updater-script中调用就是format("ext4", "EMMC", "/dev/block/mmcblk0p19", "0");现在懂了吧,
但是不同源码编译出来的update-binary的函数接口不同,我只以4个接口的为例,我也碰到过只有三个接口的,比如format("ext3", "MTD",  "/system");
所以问题就在这,我们一般经过厨房优化的一般情况下format函数调用由
format("ext4", "EMMC", "/dev/block/mmcblk0p19", "0");
变为
format("ext4", "EMMC", "/dev/block/mmcblk0p19");显然错误,因为update-binary提供函数调用时有如下语句
Value* FormatFn(const char* name, State* state, int argc, Expr* argv[]) {
if (argc != 4) {
        return ErrorAbort(state, "%s() expects 5 args, got %d", name, argc);
    }

他就是用于统计接口个素的,argc != 4表示接口个素不为4,就终止。故而无法刷入。
其他函数mount,delete,set_perm等类似。
总之不同源码编译出来的update-binary接口不同,这就要根据接口修改updater-script脚本

引自http://bbs.anzhi.com/thread-6138847-1-1.html


转载自原文链接, 如需删除请联系管理员。

原文链接:读懂华为U8825D"updater-script"刷机脚本,转载请注明来源!

0