recovery 模式下,使用 updater-script 脚本来完成的升级。
系统自带到ota_rom_target_files.py,编译时可以生成updater-script的脚本。
有时我们需要自己定义升级的功能。下面自己写一个升级脚本。完成升级功能。
1 创建目录结构:
data/app
META-INF/com/google/android/update-binary
META-INF/com/google/android/updater-script
system/app
system/xbin/busybox
其中 data/app下面的apk会被复制到系统的/data/data/app目录下.
其中 system/app下面的内容会被复制到系统的/system/app目录下
其中 system/xbin下面的内容会被复制到系统的/system/xbin目录下
如果需要放入到系统相应目录下面,你就建立;没有可以空着。
system/xbin/busybox,是我们需要的。这个可以在busybox网站下载armv6版的。
META-INF/com/google/android/update-binary 这个文件从make 系统的ota升级包中复制同名文件。
META-INF/com/google/android/updater-script 这个文本文件下面我们来写。
updater-script的内容
我们复制/data/app下面的所有apk到/data/app目录下面;我们使用busybox的目的是使用cp命令。因为android系统的toobox 没有cp命令。
show_progress(0.500000, 0);
ui_print("liuhongchao- Updater script..");
############################
#partion information came from
# 0 /tmp ramdisk (null) (null) 0
# 1 /boot emmc /dev/block/mmcblk0p8 (null) 0
# 2 /cache ext4 /dev/block/mmcblk0p15 (null) 0
# 3 /data ext4 /dev/block/mmcblk0p13 (null) 0
# 4 /persist ext4 /dev/block/mmcblk0p14 (null) 0
# 5 /recovery emmc /dev/block/mmcblk0p16 (null) 0
# 6 /recovery-bak ext4 /dev/block/mmcblk0p17 (null) 0
# 7 /sdcard vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 0
# 8 /system ext4 /dev/block/mmcblk0p12 (null) 0
############################
#mount partion
show_progress(0.100000, 0);
ui_print("liuhongchao--mount partion ...");
mount("ext4", "EMMC", "/dev/block/mmcblk0p12", "/system");
mount("ext4", "EMMC", "/dev/block/mmcblk0p13", "/data");
############################
#extract_dir
#show_progress(0.100000, 0);
#ui_print("liuhongchao-- extract_dir...");
package_extract_dir("system", "/system");
#package_extract_dir("system/lib", "/system/lib");
############################
# set symlink file----
#show_progress(0.100000, 0);
#ui_print("liuhongchao--symlink...");
# symlink("/data/app/apps.apk", "/system/app/apps.apk");
# symlink("/data/etc/hosts", "/system/etc/hosts");
############################
# set perm file----
#show_progress(0.100000, 0);
#ui_print("liuhongchao--set perm file..");
set_perm(0, 0, 04755, "/system/xbin/busybox");
#set_perm_recursive(1000, 1000, 0771, 0644, "/data/app");
#set_perm(2000, 2000, 0771, "/data/etc");
############################
# copy some_dir 58.#show_progress(0.100000, 0);
#ui_print("liuhongchao--copy some_dir...");
#package_extract_dir("../../sdcard/test", "/data/data");
#package_extract_dir("/sdcard/test", "/data/data");
############################
# copy run_program 66.show_progress(0.100000, 0);
ui_print("liuhongchao--run_program...");
run_program("/system/bin/mkdir", "/data/data/cpdirtest");
set_perm(1000, 1000, 0640, "/data/data/cpdirtest");
#run_program("/system/bin/mv","/mnt/sdcard/test","/data/data/run");
run_program("/system/xbin/busybox","cp","-r","/sdcard/test/*","/data/data/cpdirtest/");
#package_extract_file("data/run.sh", "/tmp/run.sh");
#set_perm(0, 0, 0777, "/tmp/run.sh");
#run_program("/tmp/run.sh");
############################
# delete some file----
#show_progress(0.100000, 0);
#ui_print("liuhongchao-- delete some file...");
#delete_recursive("/data/data/otatest");
#delete_recursive("/system/app/getOTA.apk");
#delete("/system/app/getOTA.apk");
############################
# write bootimg----
#show_progress(0.100000, 0);
#ui_print("liuhongchao--write bootimg..");
# package_extract_file("boot.img","/tmp/boot.img");
# write_raw_image("/tmp/boot.img", "boot");
# delete("/tmp/boot.img");
############################
# set unmount----
show_progress(0.100000, 0);
ui_print("liuhongchao--unmount...");
unmount("/data");
unmount("/system");
这是个我写的模板,选择需要用的命令。下面的命令是必须的。
mount("ext4", "EMMC", "/dev/block/mmcblk0p12", "/system");
mount("ext4", "EMMC", "/dev/block/mmcblk0p13", "/data");
package_extract_dir("system", "/system");
package_extract_dir("data", "/data");
#下面的命令可以复制任何你需要的内容;busybox
set_perm(0, 0, 04755, "/system/xbin/busybox");
run_program("/system/xbin/busybox","cp","/sdcard/app-private/hello.apk","/data/app-private/");
unmount("/data");
unmount("/system");
下面这个是我这个的Android系统的分区表,不同的硬件平台会不同。为了mount时不出错。这个文件在src/device/qcom/msm8660_surf/recovery.fstab
############################
#partion information came from
# 0 /tmp ramdisk (null) (null) 0
# 1 /boot emmc /dev/block/mmcblk0p8 (null) 0
# 2 /cache ext4 /dev/block/mmcblk0p15 (null) 0
# 3 /data ext4 /dev/block/mmcblk0p13 (null) 0
# 4 /persist ext4 /dev/block/mmcblk0p14 (null) 0
# 5 /recovery emmc /dev/block/mmcblk0p16 (null) 0
# 6 /recovery-bak ext4 /dev/block/mmcblk0p17 (null) 0
# 7 /sdcard vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 0
# 8 /system ext4 /dev/block/mmcblk0p12 (null) 0
updater-script 的局限
updater-script 的局限是,所有内容需要打包在update.zip内。如果要操作其他内容。需要busybox的cp命令。
打包update.zip
将上面的三个目录压缩到一个update.zip文件。然后用下面的命令
java -Xmx2048m -jar ../signapk.jar -w ../testkey.x509.pem ../testkey.pk8
./update.zip ./update-sign.zip
其中signapk.jar在src/out/host/linux-x86/framework/下面
../testkey.x509.pem 和./testkey.pk8 是你系统的签名私钥和公钥文件。系统默认使用testkey。这个文件位置在:
/src/build/target/product/security/
执行升级 把update-sign.zip 命名为updat.zip 放入/sdcard/ 从系统里面执行setting/security/update-fw
升级日志
升级的log日志文件在/cache/recovery/last_log 这个位置是在/bootable/recovery/recovery.c 写定的。
典型的内容如下:
01.Starting recovery on Mon Nov 21 02:44:11 2011
02.starting recovery main func.
03.framebuffer: fd 4 (1920 x 1080)
04.recovery filesystem table 05.=========================
06. 0 /tmp ramdisk (null) (null) 0
07. 1 /boot emmc /dev/block/mmcblk0p8 (null) 0
08. 2 /cache ext4 /dev/block/mmcblk0p15 (null) 0
09. 3 /data ext4 /dev/block/mmcblk0p13 (null) 0
10. 4 /persist ext4 /dev/block/mmcblk0p14 (null) 0
11. 5 /misc emmc /dev/block/mmcblk0p17 (null) 0
12. 6 /recovery emmc /dev/block/mmcblk0p18 (null) 0
13. 7 /sdcard vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 0
14. 8 /system ext4 /dev/block/mmcblk0p12 (null) 0
15.
16.write_file_with_value: file_name=/sys/module/misc_gpio/parameters/uart2_rx_cfg, value=1
17.read_value_from_file: file_name=/sys/module/misc_gpio/parameters/tv_busy, value=0
18.read_value_from_file: file_name=/sys/module/misc_gpio/parameters/uart2_rx_stus, value=0
19.TV_BUSY and UART_RX at high state. Enter recoverying...
20.write_file_with_value: file_name=/sys/module/misc_gpio/parameters/uart2_tx_cfg, value=0
21.write_file_with_value: file_name=/sys/module/misc_gpio/parameters/qc_busy, value=1
22.write_file_with_value: file_name=/sys/module/misc_gpio/parameters/uart2_tx_write, value=1
23.I:Boot command: reset-device-info
24.before update_package = /sdcard/update.zip
25.after update_package = /sdcard/update.zip
26.Command: "/sbin/recovery" "--update_package=/sdcard/update.zip"
27.
28.ro.secure=0
29.ro.allow.mock.location=1
30.ro.debuggable=1
31.ro.build.fingerprint=qcom/msm8660_surf/msm8660_surf:3.2.1/LE111116/eng.liuhongchao.20111116.162249:eng/test-keys
32.ro.emmc=1
33.init.svc.recovery=running
34.init.svc.adbd=running
35.
36.Finding update package...
37.I:Update location: /sdcard/update.zip
38.Opening update package...
39.I:1 key(s) loaded from /res/keys
40.Verifying update package...
41.I:verify_file returned 0
42.Installing update...
43./tmp/update_binary exist, delete it first
44.liuhongchao-- Verifying current system...
45.liuhongchao-- Removing unneeded files...
46.liuhongchao-- Patching system files...
47.minzip: Extracted file "/system/app/getOTA.apk"
48.
49.minzip: Extracted file "/system/xbin/busybox"
50.liuhongchao-- Unpacking new files...
51.liuhongchao-- umount system
52.script result was [/system]
53.after install_package func, install status = 0 .
前半部是分区表。中间的是build.prop文件。系统默认的需要验证ro.build.fingerprint,我们这里忽略。
你可以看到有我们打印的日志
常见错误
看last_log
mount error
注意问题
:updater-script 有些旧版本的命令不支持。具体的命令映射在src/bootable/recovery/roots.c