Android recovery更新简单流程及注意点

15920阅读 0评论2014-08-14 习_霜
分类:Android平台

关于recovery更新相关的几点总结记录:
1、recovery升级的大致流程:
        ①编译:执行make otapackage
        ②.main system模式下,将升级包重名为update.zip,下载到/cache目录下
        ③.创建文件/cache/recovery/command,并向command中写入:--update_package=/cache/update.zip
        ④终端执行reboot recovery进入recovery模式,也可以通过android上层调用函数android_reboot,并设置进入recovery模式的代码

        ⑤.系统重启,进入recovery模式,并启动recovery进程,该进程会检测/cache/recovery/command的内容,然后升级update.zip。
2、命令文件/cache/recovery/command:保存着Main system传给Recovery的命令行,每一行就是一条命令,支持一下几种的组合。

                --send_intent=anystring   //write the text out to recovery/intent    
                    //在Recovery结束时在finish_recovery函数中将定义的intent字符串作为参数传进来,并写入到/cache/recovery/intent中

                --update_package=root:path  
                    //verify install an OTA package file     Main system将这条命令写入时,代表系统需要升级,在进入Recovery模式后,
                    //将该文件中的命令读取并写入BCB中,然后进行相应的更新update.zip包的操作。

                --wipe_data    //erase user data(and cache),then reboot。擦除用户数据。擦除data分区时必须要擦除cache分区。

                --wipe_cache   //wipe cache(but not user data),then reboot。擦除cache分区。


3、recovery时分区相关需要与system主模式的分区号一致
位置:bootable/bootloader/uboot-imx/include/autoconf.mk

CONFIG_ANDROID_CACHE_PARTITION_MMC=12

CONFIG_ANDROID_RECOVERY_PARTITION_MMC=6
CONFIG_ANDROID_SYSTEM_PARTITION_MMC=5

CONFIG_ANDROID_RECOVERY_CMD_FILE="/recovery/command"
4、bootable/recovery/recovery.c修改

#LOCAL_MODULE_TAGS := eng

如果放开这行,将只会在eng版本软件中有copy/system/bin的动作

5、build/core/Makefile修改

$(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) $(DISTTOOLS)

        @echo "Package OTA: $@"

        $(hide) ./build/tools/releasetools/ota_from_target_files -v \

           -p $(HOST_OUT) \

           -k $(KEY_CERT_PAIR) \

           -n \

-w \

-n在升级时是否不检查时间戳,缺省要检查,即缺省情况下只能基于旧版本升级

 -w是否清除userdata分区
注:如果/cache/recovery/last_log中出现如下错误则说明升级包较旧导致终止执行,可以加上上面说的-n项

assert failed: !less_than_int(1397801920, getprop("ro.build.date.utc"))

6、recovery的log文件放在/cache/recovery/
last_install
last_locale:上次recovery使用的语言,如在更新时界面显示的提示语的语种,英语、日语等
last_log:log
7、检测命令文件/cache/recovery/command函数是int check_recovery_cmd_file(void)如下文件中定义

"bootable/bootloader/uboot-imx/board/freescale/mx6q_sabresd/mx6q_sabresd.c"
8、recovery升级最终是通过执行updater-script脚本来进行的。下面是部分注释供参考。

点击(此处)折叠或打开

  1. assert(getprop("ro.product.device") == "sabresd_6dq" ||
  2.        getprop("ro.build.product") == "sabresd_6dq");
  3. //show_progress(frac,sec):frac表示进度完成的数值,sec表示整个过程的总秒数。主要用与显示UI上的进度条。
  4. show_progress(0.500000, 0);
  5. //format(fs_type,partition_type,location):fs_type,文件系统类型,取值一般为“yaffs2”或“ext4”。Partition_type,分区类型,一般取值为“MTD”或则“EMMC”。主要用于格式化为指定的文件系统。
  6. format("ext4", "EMMC", "/dev/block/mmcblk0p5", "0", "/system");
  7. //挂在一个文件系统/system到指定挂载点mmcblk0p5
  8. mount("ext4", "EMMC", "/dev/block/mmcblk0p5", "/system");
  9. //package_extract_dir(src_path,destination_path):src_path,要提取的目录,destination_path目标目录。作用:从升级包内,提取目录到指定的位置。
  10. package_extract_dir("recovery", "/system");//提取recovery
  11. package_extract_dir("system", "/system");//提取system
  12. //创建符号链接
  13. symlink("Roboto-Bold.ttf", "/system/fonts/DroidSans-Bold.ttf");
  14. symlink("Roboto-Regular.ttf", "/system/fonts/DroidSans.ttf");
  15. symlink("mksh", "/system/bin/sh");
  16. symlink("toolbox", "/system/bin/cat", "/system/bin/chmod",
  17.         "/system/bin/chown", "/system/bin/cmp", "/system/bin/cp",
  18.         "/system/bin/date", "/system/bin/dd", "/system/bin/df",
  19.         "/system/bin/dmesg", "/system/bin/du", "/system/bin/getevent",
  20.         "/system/bin/getprop", "/system/bin/grep", "/system/bin/hd",
  21.         "/system/bin/id", "/system/bin/ifconfig", "/system/bin/iftop",
  22.         "/system/bin/insmod", "/system/bin/ioctl", "/system/bin/ionice",
  23.         "/system/bin/kill", "/system/bin/ln", "/system/bin/log",
  24.         "/system/bin/ls", "/system/bin/lsmod", "/system/bin/lsof",
  25.         "/system/bin/md5", "/system/bin/mkdir", "/system/bin/mount",
  26.         "/system/bin/mv", "/system/bin/nandread", "/system/bin/netstat",
  27.         "/system/bin/newfs_msdos", "/system/bin/notify", "/system/bin/printenv",
  28.         "/system/bin/ps", "/system/bin/reboot", "/system/bin/renice",
  29.         "/system/bin/rm", "/system/bin/rmdir", "/system/bin/rmmod",
  30.         "/system/bin/route", "/system/bin/schedtop", "/system/bin/sendevent",
  31.         "/system/bin/setconsole", "/system/bin/setprop", "/system/bin/sleep",
  32.         "/system/bin/smd", "/system/bin/start", "/system/bin/stop",
  33.         "/system/bin/sync", "/system/bin/top", "/system/bin/touch",
  34.         "/system/bin/umount", "/system/bin/uptime", "/system/bin/vmstat",
  35.         "/system/bin/watchprops",
  36.         "/system/bin/wipe");
  37. //设置文件或目录权限
  38. set_perm_recursive(0, 0, 0755, 0644, "/system");
  39. set_perm_recursive(0, 2000, 0755, 0755, "/system/bin");
  40. set_perm(0, 3003, 02750, "/system/bin/netcfg");
  41. set_perm(0, 3004, 02755, "/system/bin/ping");
  42. set_perm(0, 2000, 06750, "/system/bin/run-as");
  43. set_perm(1002, 1002, 0440, "/system/etc/dbus.conf");
  44. set_perm(1014, 2000, 0550, "/system/etc/dhcpcd/dhcpcd-run-hooks");
  45. set_perm(0, 2000, 0550, "/system/etc/init.goldfish.sh");
  46. set_perm(0, 0, 0544, "/system/etc/install-recovery.sh");
  47. set_perm_recursive(0, 0, 0755, 0555, "/system/etc/ppp");
  48. set_perm_recursive(0, 2000, 0755, 0644, "/system/vendor");
  49. set_perm(0, 0, 0644, "/system/vendor/etc/audio_effects.conf");
  50. set_perm_recursive(0, 2000, 0755, 0755, "/system/xbin");
  51. show_progress(0.200000, 0);
  52. show_progress(0.200000, 10);
  53. //将升级包中的boot.img文件写入到/dev/block/mmcblk0p1
  54. package_extract_file("boot.img", "/dev/block/mmcblk0p1");
  55. show_progress(0.100000, 0);
  56. unmount("/system");


9、updater-script脚本是从python脚本build/tools/releasetools/ota_from_target_files中生成的。


10、更新时的图片显示是在/android4.2-imx6/bootable/recovery/res/images下面
11、Android recovery模式时界面显示的文字是从png文本图片中读取的。目录也是在/android4.2-imx6/bootable/recovery/res/images
如果要显示文字是需要从上层传递locale变量的。如果没有设置或者不知如何设置(我就不知),可以直接修改bootable/recovery/recovery.cpp文件中locale 定义时赋予初始值,如下表示英语_英国
char* locale = "en_GB"


上一篇: Linux 软件看门狗 watchdog
下一篇:Recovery模式下的文本显示