http://lhc180.blog.51cto.com/316940/758075
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
#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
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 写定的。
典型的内容如下:
Starting recovery on Mon Nov 21 02:44:11 2011
starting recovery main func.
framebuffer: fd 4 (1920 x 1080)
recovery filesystem table
=========================
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 /misc emmc /dev/block/mmcblk0p17 (null) 0
6 /recovery emmc /dev/block/mmcblk0p18 (null) 0
7 /sdcard vfat /dev/block/mmcblk1p1 /dev/block/mmcblk1 0
8 /system ext4 /dev/block/mmcblk0p12 (null) 0
write_file_with_value: file_name=/sys/module/misc_gpio/parameters/uart2_rx_cfg, value=1
read_value_from_file: file_name=/sys/module/misc_gpio/parameters/tv_busy, value=0
read_value_from_file: file_name=/sys/module/misc_gpio/parameters/uart2_rx_stus, value=0
TV_BUSY and UART_RX at high state. Enter recoverying...
write_file_with_value: file_name=/sys/module/misc_gpio/parameters/uart2_tx_cfg, value=0
write_file_with_value: file_name=/sys/module/misc_gpio/parameters/qc_busy, value=1
write_file_with_value: file_name=/sys/module/misc_gpio/parameters/uart2_tx_write, value=1
I:Boot command: reset-device-info
before update_package = /sdcard/update.zip
after update_package = /sdcard/update.zip
Command: "/sbin/recovery" "--update_package=/sdcard/update.zip"
ro.secure=0
ro.allow.mock.location=1
ro.debuggable=1
ro.build.fingerprint=qcom/msm8660_surf/msm8660_surf:3.2.1/LE111116/eng.liuhongchao.20111116.162249:eng/test-keys
ro.emmc=1
init.svc.recovery=running
init.svc.adbd=running
Finding update package...
I:Update location: /sdcard/update.zip
Opening update package...
I:1 key(s) loaded from /res/keys
Verifying update package...
I:verify_file returned 0
Installing update...
/tmp/update_binary exist, delete it first
liuhongchao-- Verifying current system...
liuhongchao-- Removing unneeded files...
liuhongchao-- Patching system files...
minzip: Extracted file "/system/app/getOTA.apk"
minzip: Extracted file "/system/xbin/busybox"
liuhongchao-- Unpacking new files...
liuhongchao-- umount system
script result was [/system]
after install_package func, install status = 0 .
前半部是分区表。中间的是build.prop文件。系统默认的需要验证ro.build.fingerprint,我们这里忽略。
你可以看到有我们打印的日志
常见错误
看last_log
mount error
注意问题
:updater-script 有些旧版本的命令不支持。具体的命令映射在src/bootable/recovery/roots.c