zoukankan      html  css  js  c++  java
  • Android平台刷机包 修改制作方法

    转自:http://www.g3top.com/

    在此先要明确声明一下:
    由于android平台的更新换代过于频繁,偶的做法不一定好用,也不一定完全正确(只是记录一下偶在自己的nexus one上面做的一些实验而已)。依照偶的做法出现了您的手机出现任何问题,偶都是不负责的喔!!

    英文好的朋友可以不必看着偶聒噪,直接看英文官方的参考网站即可:
    http://forum.xda-developers.com/showthread.php?t=566235

    只用android源代码做一些简单实验的朋友可以参考下面这几个网站:
    http://nhenze.net/?tag=build-android
    http://developer.htc.com/adp.html

    说起android刷机包,听起来非常神秘,实际上它仅仅是一个经过数字签名的zip压缩包而已。如果要自己制作刷机包,则必须了解刷机包的基本工作原理,偶首先从android系统的启动说起:

    android系统启动的时候,首先会进行一些诸如硬件自检之类的操作,这些操作完成以后(至少它应该知道当前的机器有没有电),会检查一下当前手机按键的状态(接下来就是所谓刷机模式切换了,不同的android手机有不同的按键组合用来进入刷机模式),如果此时按键状态处于刷机组合,那么系统会调用ROM里面的一个叫做recovery的程序(这时就是进入了所谓的刷机程序了,它只是一个工具性质程序,用于检查刷机包的完整性和数字签名的合法性。对于目前大多数root过的机器而言,数字签名的合法性都不会成问题,然后由recovery程序将刷机包进行解压,然后把刷机包里面的文件写入到ROM中去,以此完成刷机过程);如果此时按键没有标明是刷机模式,那么系统会创建内存盘,开始从ROM里面载入相应的文件系统,并把相关的文件拷贝到内存盘中,进而引导linux启动,然后是启动虚拟机dalvik,然后就是创建工作进程载入和运行framework,然后就会看到待机的画面。当然在这个过程中还发生了许多事情,启动了许多服务,为了简化起见,对于启动过程偶只讲解到此,感兴趣的朋友可以自己结合着linux的启动过程加以对比来学习。

    现在来总结一下,实际上刷机包就是一个ROM文件的压缩包,进入刷机模式后,recovery程序会把刷机包里面的文件写入ROM存储区替换ROM存储区的原有文件;当下次启动手机的时候,会从ROM中载入刚刚替换过的文件,并利用这些文件来启动和运行系统。这就是刷机包的全部功能和作用,看不懂的朋友可以反复看几次,刷机的本质就是文件的覆盖和替换操作,偶相信各位一定能看懂!

    OK,现在大家已经知道ROM文件的zip压缩包就是所谓的刷机包。制作刷机包的过程就是准备这些文件,然后重新把这些文件压缩成一个zip包的过程,在制作的最后,使用签名工具签个名,就可以测试和发布刷机包了。虽然说起来就是一句话的事情,但是实际上准备这些文件的过程是非常痛苦和漫长的。

    那么update.zip压缩包里面的都包含哪些文件?这些文件又都是如何做出来的呢?hoho,现在开始渐渐接触到问题的本质了,解压缩这个update.zip压缩包以后我们可以看到两个目录和一个文件:

    boot.img   <---文件,这是编译内核源代码生成的内核映像,然后与android源码编译出来的ramdisk.img一起通过mkbootimg工具创建出来的,图省事的朋友也可以从网上其他的刷机包里面拷贝一个能用的出来即可,基本上都差不多。

    META-INF   <---目录,这个目录是手工创建的,主要用来存放一个升级脚本update-script(这个脚本的内容与system目录中包含的文件有很大关联)以及保存若干刷机包内的apk文件的签名。

    system   <---目录,这个目录就是编译android的平台源代码生成的,

    其实最好的学习方式就是把现在互联网上的那些update.zip包给解包,然后自己一个一个文件地看和分析,然后修改,尝试做自己的刷机包。

    对于这个boot.img,基本思路是编译android kernel代码,生成内核image然后利用mkbootimg感兴趣的朋友可以参考下面这两个wiki网站:
    http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images

    http://android-dls.com/wiki/index.php?title=Replace_Recovery_Partition

    下面的做法偶都是在linux下面完成的(slackware 13.1):
    (1)下载和编译android的源代码,具体过程不再赘述
    如果各位还不知道repo sync之类的命令的话,可以参考网上的关于下载android源代码以及编译的文章,据偶所知这些文章非常丰富。编译之前一定要注意平台的选择,不同平台的驱动程序是不一样的!这些参数可以通过:
    $ cd android-src    <---进入android的源代码目录
    $ . build/envsetup.sh <---设置环境变量,运行完毕后,你可以输入一下help命令,看看google的团队提供了多少有用的便利命令,这对于我们以后修改代码重新编译非常有帮助。
    $ lunch generic-eng   <---开始配置android的源代码的编译选项
    运行上述命令后会看到如下输出:
    wayne@wayne:~/android-src$ lunch generic-eng

    ============================================
    PLATFORM_VERSION_CODENAME=REL
    PLATFORM_VERSION=2.1-update1
    TARGET_PRODUCT=generic
    TARGET_BUILD_VARIANT=eng
    TARGET_SIMULATOR=false
    TARGET_BUILD_TYPE=release
    TARGET_ARCH=arm
    HOST_ARCH=x86
    HOST_OS=linux
    HOST_BUILD_TYPE=release
    BUILD_ID=ECLAIR
    ============================================

    $ make -j2   <---只有单核的CPU的朋友可以尝试此参数,双核的朋友可以试试-j3,否则就老老实实运行make即可

    然后就是一个漫长的等待,这个时间大概有1-2小时左右(偶的机器比较慢),完全编译完毕以后硬盘的占用大概需要8个G左右。

    (2)编译完成以后,进入wayne@wayne:~/android-src/out/target/product/generic目录,应该会看到如下的文件:
    android-info.txt  
    data                 
    obj                       
    ramdisk.img  
    sdk      
    system      
    userdata.img
    clean_steps.mk   
    installed-files.txt  
    previous_build_config.mk  
    root         
    symbols  
    system.img
    这里的system.img是不是很眼熟?!对拉,这个就是刷机包里面好像也有一个叫做什么system的目录,那么这个system.img里面都有什么呢?这里面的东西其实就是当前目录下的一个叫做system的目录里面的内容了,只是保存成了yaffs文件系统的格式。我们可以通过unyaffs工具来把system.img给解开来看看,就明白偶说话了。
    unyaffs的代码下载地址为:
    http://code.google.com/p/unyaffs/downloads/list

     或者下载 win32 版本

    http://jiggawatt.org/badc0de/android/index.html
    注意你需要在cygwin.com下载 cygwin1.dll and cygz.dll (zlib0 package).

    在linux下编译方法非常地简单,只需要下载源代码,然后运行:

    $ gcc -c unyaffs.c
    $ gcc -o unyaffs unyaffs.o
    即可生成这个unyaffs的解包工具,利用这个工具就可以把自己生成的system.img进行解包,然后修改里面的内容了。
    unyaffs使用方法非常简单:
    $ unyaffs system.img [回车]
    即可将system.img解包成一个叫做system的目录,里面包含了整个android的文件系统

    (3)刚刚开始,不适合一切从头来,还是老实一些,先从修改别的大牛们做得刷机包开始吧
    首先拷贝一个从网上下载下来的刷机包,然后找一个目录解压缩(当然,这是最保险的做法,自己做这些目录也没有任何问题,只是比较费时间而已)
    $ unzip xxxxxx.zip   <--- 这个xxxxx.zip就是从网上下载的某刷机包(一定要跟你的代码版本基本一致喔,偶在这里用的是2.1的刷机包)

    (4)替换原有的system目录
    解压缩刷机包以后,会看到在开篇的时候提到的两个目录,一个文件:
    boot.img
    META-INF
    system
    好了,可以把system目录拷贝到别的路径下备份一给,防止这些修改发生别的问题。然后把wayne@wayne:~/android-src/out/target/product/generic这个目录下面的system拷贝到当前的工作目录下。注意,这个system目录里面有很多“符号链接”指向了toolbox。这些链接其实没啥用,可以通过后面的update-script自动进行创建的,因此,需要用一个脚本把这些链接都删掉。
    可以参考:
    http://forum.xda-developers.com/showthread.php?t=566235
    这个网页附件给出来的DeleteExtras.txt改写成一个DeleteExtras.sh脚本来清除这些符号链接。

    (5)修改update-script脚本
    修改META-INF/com/google/android目录下的那个叫做update-script的脚本,只要修改一下即可,主要是删除一些不存在的文件以及增加一些文件的权限之类的定义(语法十分清晰,一目了然)。把需要“预装”到刷机包里面的apk安装程序都准备好,将这些apk拷贝到system/app目录下即可。那个boot.img能不改就不改,因为这东西涉及到驱动和内核的问题,出了问题刷机包就启动不了了。

    (6)重新打包成update.zip
    $ zip -r update.zip .   <---注意这最后的“.”是必不可少的,代表是当前路径下的意思。

    (7)为做好的刷机包签名

    在上面提到的链接中,有一个叫做AutoSign的工具,打开一看是一个jar格式的工具包。

     /Files/shenhaocn/autosign.zip

    运行如下命令对刷机包进行签名:
    $ java -jar autosign.jar update.zip update_signed.zip

    ok,签名完毕后,就可以备份一下手机里面的东西,测试一下了。

    下面是相关的帖子和内容

    How to create your own ROM update.zip for the T-Mobile MyTouch 3G

    Things you will need to perform this:
    Java SE Dev Kit from Sun. java.sun.com
    May need Cygwin with zlib0 package, from cygwin.com


    This will give you Android 1.6 with all the Google applications, Root access.
    I never found one place where all this information is all together, so that is why I compiled this together.
    Now anyone can do this themselves.

    Thanks to all the hard work others have done before this.


    1.
    First Root your phone and install a new Recovery image, either Amon Ra or Cyanogens Recovery image.
    Instructions for one-click root: http://theunlockr.com/2009/08/22/how...-in-one-click/

    2.
    Download the Android 1.6 System image from
    http://developer.htc.com/google-io-device.html

    extract the contents of signed-google_ion-img-14721.zip.

    3.
    You now need to extract the contents of system.img using a tool called unyaffs. The source code is here:
    http://code.google.com/p/unyaffs/downloads/list
    Or download a prebuilt win32 version here.
    http://jiggawatt.org/badc0de/android/index.html
    Note you may also need cygwin1.dll and cygz.dll (zlib0 package). Found at cygwin.com

    Of course if you already have Cygwin installed with the GCC packages, you can just compile it yourself. Then also
    if you comment out the line 67 to "// symlink(oh->alias, full_path_name);"
    then it will not create the copies of the symbolic link file, and you will not have to worry about deleting duplicate
    symbolic link files later.


    Now in the directory where system.img exists, create a new directory called "system"
    go into the "system" directory.
    type the following command:
    unyaffs ..\system.img

    That should extract all the files from the system.img file into the system directory.

    4.
    Now we just need to clean up some items. Since the system.img is a linux file system, it has symbolic
    links built into it, but when we extracted it, it just created duplicate files, if you used the prebuilt unyaffs.exe.
    So we can just delete the duplicates and have a script recreate the symlink on install.

    So we need to delete some extra files from the system\bin directory.
    Run the attached DeleteExtras.bat file from the same directory where system.img is in.
    If you notice, all the files it deletes are 28 byte files, and if you open them in notepad only contain:
    "!<symlink>toolbox..."
    And we will remake the symbolic link when it is installed.


    5.
    Now from the directory where the system.img is, enter the following commands
    mkdir META-INF
    mkdir META-INF\com
    mkdir META-INF\com\google
    mkdir META-INF\com\google\android


    Now copy the included file "update-script.txt" into the "META-INF\com\google\android" directory
    and RENAME it to just "update-script".
    This update-script gets run to recreate the symbolic links.

    Not sure if these two are needed but they are in some custom ROMs here:
    Copy the two files "fix_permissions" and "flash_image" to the "system\bin" directory.


    6.
    -- Optional --
    These add root and Superuser access to the ROM, plus the Terminal Emulator application.

    Copy the file "su" from Cyanogen's rom to the folder "system\bin"
    Copy the file "Superuser.apk" to the folder "system\app"
    Copy the file "Term.apk" to the folder "system\app"

    You can also replace the "system\etc\apns-conf.xml" with a more complete one from here:
    http://forum.xda-developers.com/showthread.php?t=547718
    or here
    http://docs.google.com/Doc?docid=0AZ...g3ejN3eg&hl=en

    Turn data roaming off by default by editing line in the build.prop file:
    ro.com.android.dataroaming=false

    Also to fix the Market program to show "Protected" applications change the ro.build.fingerprint line to the following:
    ro.build.fingerprint=tmobile/opal/sapphire/sapphire:1.5/COC10/150449:user/ota-rel-keys,release-keys

    Only phones with a fingerprint of a "released" device can access some market applications.

    --------------

    7.
    Now we just need to create a ZIP file for the final ROM

    Zip up the following file and two folders:

    boot.img
    META-INF
    system


    8.
    Now sign the zip file.
    See here how to sign a ZIP file for flashing it.
    http://androidforums.com/developer-1...ning-roms.html

    9.
    Copy it to your SD card, boot into recovery, wipe, apply the update, Reboot.

    You are now running Android 1.6! 

    /Files/shenhaocn/update-script.txt  

    /Files/shenhaocn/DeleteExtras..txt   

  • 相关阅读:
    JAVA规范
    JMS开发指南
    JMS异步消息机制
    大型系统中使用JMS优化技巧–Sun OpenMQ
    02.MyBatis配置文件详解
    elasticsearch.yml配置文件
    04.ActiveMQ与Spring JMS整合
    01.MyBatis入门
    03.JMS深入
    02.JMS基础
  • 原文地址:https://www.cnblogs.com/shenhaocn/p/1743685.html
Copyright © 2011-2022 走看看