打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
创建一个刷机包,update-script脚本语法说明
目前有好几种方法来安装软件或是库文件到你的Android手机上。你可以使用市场程序来查找并安装软件,也可以使用adb命令行工具来安装或是发送文件到你的Android文件系统中。这些方法对于操作单个文件来说都挺方便的,但是如果你需要一次性安装多个软件或是库文件时,那么最为方便的方法大概就是使用update.zip(也就是刷机包)文件了。Android系统使用恢复工具(recovery)来安装这个update.zip文件中的软件或库文件到Android文件系统中。而一个ROM或是主题开发者通常都是使用这个方式来发布他们的作品(刷机包)。
创建一个update.zip文件是很简单的事情,你所需要做的就是将文件放置到与Android文件系统中相对应的文件夹中,然后编写一个用来复制这些文件到手机对应位置的updater-script, 文件。作为举例,本文会安装Calculator.apk到system/app文件夹,复制libsec-ril.so文件到system/lib文件夹:新建一个空文件夹(本文例:C:\android)新建用来放置Calculator.apk的文件夹C:\android\system\app以及用来放置libsec-ril.so的文件夹C:\android\system\lib。创建用来放置update-script文件的文件夹C:\android\META-INF\com\google\android。
创建一个名为updater-script的文件,其内容如下(高亮部分):
show_progress 0.1 0
copy_dir PACKAGE:system SYSTEM:
show_progress 0.1 10
复制代码
行1和行5:显示进度条
行3:复制刷机包中的system文件夹到Android的/system
注意:你应该在文件的最末尾多添加一个空行(也就是行6)将C:\android压缩中的所有内容压缩为zip包(千万记住:是压缩android这个文件夹中的内容,不是android文件夹本身)为android.zip签名
注意:你可以在[url=http://bbs.gfan.com/android-1154798-1-1.html]这个帖子[/url]中找到为刷机包签名的教程和工具将update.zip文件复制到SD卡中,然后手机进入recovery界面来刷入这个刷机包
一. 基础语法篇
1.copy_dir
语法:copy_dir <src-dir> <dst-dir> [<timestamp>]
< src-dir>表示原文件夹,<dst-dir>表示目的文件夹,[<timestamp>]表示时间戳
作用:将<src-dir>文件夹中的内容复制到<dst-dir>文件夹中。<dst-dir>文件夹中的原始内容将会保存不变,除非<src-dir>文件夹中有相同的内容,这样<dst-dir>中的内容将被覆盖
举例:copy_dir PACKAGE:system SYSTEM:(将升级包中的system文件夹复制到手机中)
2.format
语法:format <root>
< root>表示要格式化的分区
作用:格式化一个分区
举例:format SYSTEM:(将手机/system分区完全格式化)
注意:格式化之后的数据是不可以恢复的
3.delete
语法:delete <file1> [... <fileN>]
< file1> [... <fileN>]表示要格式化的文件,可以是多个文件用空格隔开
作用:删除文件1,2到n
举例:delete SYSTEM:app/Calculator.apk(删除手机systen文件夹中app中的Calculator.apk文件)
4.delete_recursive
语法:delete_recursive <file-or-dir1> [... <file-or-dirN>]
< file-or-dir1> [... <file-or-dirN>]表示要删除的文件或文件夹,可以使多个,中间用空格隔开
作用:删除文件或者目录,删除目录时会将目录中的所有内容全部删除
举例:delete_recursive DATA:dalvik-cache(删除/data/dalvik-cache文件夹下的所有内容)
5.run_program
语法:run_program <program-file> [<args> ...]
< program-file>表示要运行的程序,[<args> ...]表示运行程序所加的参数
作用:运行终端程序
举例:run_program PACKAGE:install_busybox.sh(执行升级包中的install_busybox.sh脚本)
6.set_perm
语法:set_perm <uid> <gid> <mode> <path> [... <pathN>]
< uid>表示用户名称,<gid>表示用户组名称,<mode>,表示权限模式,<path> [... <pathN>]表示文件路径,可以使多个,用空格隔开
作用:设置单个文件或目录的所有者和权限,像linux中的chmod、chown或chgrp命令一样,只是集中在了一个命令当中
举例:set_perm 0 2000 0550 SYSTEM:etc/init.goldfish.sh(设置手机system中的etc/init.goldfish.sh的用户为root,用户组为shell,所有者以及所属用户组成员可以进行读取和执行操作,其他用户无操作权限)
7.set_perm_recursive
语法:set_perm_recursive <uid> <gid> <dir-mode> <file-mode> <path> [... <pathN>]
< uid>表示用户,<gid>表示用户组,<dir-mode>表示文件夹的权限,<file-mode>表示文件的权限,<path> [... <pathN>]表示文件夹的路径,可以多个,用空格分开
作用:设置文件夹及文件夹中的文件的所有者和用户组
举例:set_perm_recursive 0 0 0755 0644 SYSTEM:app(设置手机system/app文件夹及其中文件的用户为root,用户组为root,app文件夹权限为所有者可以进行读、写、执行操作,其他用户可以进行读取和执行操作,其中的文件的权限为所有者可以进行读写操作,其他用户可以进行读取操作)
8.show_progress
语法:show_progress <fraction> <duration>
< 表示一个小部分> <表示一个小部分的持续时间>
作用:为下面进行的程序操作显示进度条,进度条会根据<duration>进行前进,当操作时间是确定的时候会更快
举例:show_progress 0.1 0(显示进度条当操作完成后前进10%)
9.symlink
语法:symlink <link-target> <link-path>
< link-target>表示链接到的目标,<link-path>表示快捷方式的路径
作用:相当于linux中的ln命令,将<link-target>在<link-path>处创建一个软链接,<link-target>的格式应为绝对路径(或许相对路径也可以),<link-path>为“根目录:路径”的形式
举例:symlink /system/bin/su SYSTEM:xbin/su(在手机中system中的xbin中建立一个/system/bin/su的快捷方式)
10.assert
语法:assert <boolexpr>
作用:此命令用来判断表达式boolexpr的正确与否,当表达式错误时程序终止执行※此作用有待验证
11.package_extract_file/dir语法:package_extract_file(file/dir,file/dir)
作用:提取包中文件/路径
举例:package_extract_dir("system", "/system");
package_extract_file("system/bin/modelid_cfg.sh", "/tmp/modelid_cfg.sh");
12.write_radio_image
语法:write_radio_image <src-image>
作用:将基带部分的镜像写入手机,<src-image>表示镜像文件
举例:write_radio_image PACKAGE:radio.img
13.write_hboot_image
语法:write_hboot_image <src-image>
作用:将系统bootloader镜像写入手机,<src-image>表示镜像位置,此命令在直到在所有的程序安装结束之后才会起作用
举例:write_hboot_image PACKAGE:hboot.img
14.write_raw_image语法:write_raw_image <src-image> <dest-root>
作用:将boot.img写入手机,里面包含了内核和ram盘
举例:write_raw_image PACKAGE:boot.img BOOT:
二、根目录以及分区的定义(在Android源代码的root.c文件中定义)
根目录:Linux 块设备/挂载点/文件系统大小描述
BOOT:/dev/mtdblock[?]/(RAM)Raw内核、内存盘和引导配置。
DATA:/dev/mtdblock5/data/yaffs291904kb用户、系统配置,软件配置以及软件(没有a2sd的话)
CACHE:/dev/mtdblock4/cache/yaffs230720kbOTA缓存,recovery/更新配置及临时文件夹
MISC:/dev/mtdblock[?]N/ARaw,[?]kb(等待添加)
PACKAGE:(相对于刷机包)N/A刷机包的伪文件系统。
RECOVERY:/dev/mtdblock[?]/(RAM)Raw,[?]kbrecovery和更新环境的内核和内存盘。类似于BOOT:。
SDCARD:/dev/mmcblk0(p1)/sdcard/fat3232MB-32GBTF卡。通常刷机包就放在这里。
SYSTEM:/dev/mtdblock3/system/yaffs292160kb系统分区,静态且是只读的。
TMP:/tmp/(RAM)标准的Linux临时文件夹在关机/重启时清空。
三. 实例分析进阶篇
呵呵,大家来看看这段代码是不是有种熟悉的感觉啊,这就是在SwiftDroid_v1.8_recovery_BY_mur4ik刷机包中的updater-script文件!
assert(getprop("ro.product.device") == "swift" || getprop("ro.build.product") == "swift" || getprop("ro.product.board") == "swift");
package_extract_file("system/bin/backuptool.sh", "/tmp/backuptool.sh");
set_perm(0, 0, 0777, "/tmp/backuptool.sh");
run_program("/tmp/backuptool.sh", "backup");
show_progress(0.500000, 0);
format("yaffs2", "MTD", "system");
mount("yaffs2", "MTD", "system", "/system");
package_extract_dir("recovery", "/system");
package_extract_dir("system", "/system");
symlink("busybox", "/system/xbin/[", "/system/xbin/[[",
"/system/xbin/arp", "/system/xbin/ash", "/system/xbin/awk",
"/system/xbin/basename", "/system/xbin/bbconfig", "/system/xbin/brctl",
"/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("iwmulticall", "/system/xbin/iwconfig", "/system/xbin/iwgetid",
"/system/xbin/iwlist", "/system/xbin/iwpriv",
"/system/xbin/iwspy");
symlink("toolbox", "/system/bin/cat", "/system/bin/cmp",
"/system/bin/date", "/system/bin/dd", "/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/log", "/system/bin/lsmod",
"/system/bin/mkdir", "/system/bin/nandread", "/system/bin/netstat",
"/system/bin/newfs_msdos", "/system/bin/notify", "/system/bin/printenv",
"/system/bin/ps", "/system/bin/reboot", "/system/bin/renice",
"/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/uptime",
"/system/bin/vmstat", "/system/bin/watchprops",
"/system/bin/wipe");
set_perm_recursive(0, 0, 0755, 0644, "/system");
set_perm_recursive(0, 2000, 0755, 0755, "/system/bin");
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");
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_recursive(0, 2000, 0755, 0750, "/system/etc/init.d");
set_perm(0, 0, 0755, "/system/etc/init.d");
set_perm(0, 2000, 0550, "/system/etc/init.goldfish.sh");
set_perm(0, 0, 0544, "/system/etc/install-recovery.sh");
set_perm_recursive(0, 0, 0755, 0555, "/system/etc/ppp");
set_perm_recursive(0, 2000, 0755, 0755, "/system/xbin");
set_perm(0, 0, 06755, "/system/xbin/hcitool");
set_perm(0, 0, 06755, "/system/xbin/librank");
set_perm(0, 0, 06755, "/system/xbin/procmem");
set_perm(0, 0, 06755, "/system/xbin/procrank");
set_perm(0, 0, 06755, "/system/xbin/su");
set_perm(0, 0, 06755, "/system/xbin/tcpdump");
show_progress(0.200000, 0);
show_progress(0.200000, 10);
package_extract_file("system/bin/backuptool.sh", "/tmp/backuptool.sh");
set_perm(0, 0, 0777, "/tmp/backuptool.sh");
run_program("/tmp/backuptool.sh", "restore");
package_extract_file("system/bin/modelid_cfg.sh", "/tmp/modelid_cfg.sh");
set_perm(0, 0, 0777, "/tmp/modelid_cfg.sh");
run_program("/tmp/modelid_cfg.sh");
package_extract_file("system/bin/verify_cache_partition_size.sh", "/tmp/verify_cache_partition_size.sh");
set_perm(0, 0, 0777, "/tmp/verify_cache_partition_size.sh");
run_program("/tmp/verify_cache_partition_size.sh");
show_progress(0.200000, 10);
assert(package_extract_file("boot.img", "/tmp/boot.img"),
write_raw_image("/tmp/boot.img", "boot"),
delete("/tmp/boot.img"));
show_progress(0.100000, 0);
unmount("/system");
复制代码
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
update.zip升级过程---updater-script脚本语法简介以及执行流程
Android的Amend脚本(update
【ROM制作中级知识三】教你怎样创建一个刷机包
【L.E.R-未完】丨【安卓rom定制】丨『第七课』丨 系统脚本的初步分析及修改
【实用教程】【骑士原创教程】手把手教你写刷机脚本,小白也能学会做补丁包和rom!
如何制作Android ROM,想学ROM制作的朋友必看
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服