to_build_new_recovery.img

Update/Preface:

It is difficult for me to port recovery for a device I don’t have. So, people can attempt to port it using this guide. However, if you want it done properly, and probably quicker, you can loan the device to me personally at:

Koushik Dutta 2721 1st Ave 507 Seattle, WA 98121

The package must include:

  • The rooted phone.
  • A return packing slip to your address.
  • A signed statement saying: “I, <your name here>, am lending this device, <name of device>, to Koushik Dutta so that he can try to port Clockwork Recovery to the device. I understand that rooting a phone voids the warranty and tampering with the software may render the device nonfunctional. I realize and accept that the phone may not be functional when it is returned. Koushik Dutta is not liable for any damages to the device.”
  • BEFORE SENDING ME THE PACKAGE, CONFIRM WITH ME THAT I AM AVAILABLE TO PORT THE RECOVERY.

It will take around a week, and there are no gaurantees whether I will actually be able to do it (due to proprietary software, locked bootloaders, my schedule, etc). After a week (generally quicker), I will send it back. I’m a trustworthy guy and am well known in the Android community. And I’ve already done this for several loaner devices.Smile So you don’t need to worry about the safety of your precious hardware.

Otherwise, continue on the to the guide!

  • This guide will assume you have some familiarity with doing an Android Build.
  • This guide will work for phones that use a standard Android boot image format. This guide will not work for Samsung phones which use an initramfs.

First, let's check out the CyanogenMod tree. The CyanogenMod repository contains Clockwork Recovery, which is part of a full Android build.

repo init -u git://github.com/CyanogenMod/android.git -b gingerbread

repo sync

make -j4 otatools

Now, use dump_image or dd to dump your recovery or boot image from a running phone and copy it to your computer somewhere.

dump_image boot boot.img

To build Android from source for a new device, you need to set up a board config and its makefiles. This is generally a long and tedious process. Luckily, if you are only building recovery, it is a lot easier. From the root of your Android source directory (assuming you've run envsetup.sh), run the following (substituting names appropriately):

build/tools/device/mkvendor.sh device_manufacturer_name device_name /your/path/to/the/boot.img

You will receive the confirmation "Done!" if everything worked. The mkvendor.sh script will also have created the following directory in your Android source tree:

manufacturer_name/device_name

Now, type the following:

lunch full_device_name-eng

This will set the build system up to build for your new device. Open up the directory in a file explorer or IDE. You should have the following files: AndroidBoard.mk, AndroidProducts.mk, BoardConfig.mk, device_.mk, kernel, system.prop, recovery.fstab, and vendorsetup.sh.

The two files you are interested in are recovery.fstab and kernel. The kernel in that directory is the stock one that was extracted from the boot.img that was provided earlier. For the most part, recovery.fstab will work on most devices that have mtd, emmc, or otherwise named partitions. But if not, recovery.fstab will need to be tweaked to support mounts and their mount points. For example, if your /sdcard mount is /dev/block/mmcblk1p1, you would need the following lines in your BoardConfig.mk:

/sdcard vfat /dev/block/mmcblk1p1

Once the recovery.fstab has been properly setup, you can build the recovery using:

make -j4 recoveryimage

Your recovery can then be found at $OUT/recovery.img. If you are in need of building a fakeflash recovery, you will need to run the following to create the update.zip that hot replaces the recovery:

make -j4 recoveryzip

Once this is done, build, and tested, notify me, "koush", on Github and I can build official releases and add ROM Manager support!


/

你必须使用32位或64位Ubuntu系统,关于如何建立编译环境和同步源码的指导,请自己查找有关指导的文章。

 

1,

安装所需要的包

 

2,

建立编译的环境,并同步CWM所需的源码,CyanogenMod源码中附带CWM源码

CWM 5 - Gingerbread
CWM 6 - Jellybean

 

3,

下面我们进入真正的编译阶段,确保你已经使用“repo sync ”命令同步了最新的源码

进入源码的目录

放出以下命令:

     make -j4 otatools

 

3.5,

如果你的机型不被CM10官方支持,请执行这一步

在你的手机终端上执行以下命令,

dump_image boot /sdcard/boot.img

这将boot镜像导出到你手机的sdcard,复制该镜像至你的home目录下

为一款新设备编译android源码,需要建立相应的配置文件和makefile文件,这通常比较麻烦,如果仅仅编译recovery镜像,会容易的多。在android源码根目录下(假设已运行envsetup.sh),运行以下命令(使用适当的名称取代命令中的名称)

build/tools/device/mkvendor.sh device_manufacturer_name device_name /your/path/to/the/boot.img

例如,你拥有Samsung Galaxy Ace这款设备,你应该使用以下这条命令

build/tools/device/mkvendor.sh Samsung cooper ~/boot.img
 
Please note that Cooper is the device name. Only use "~/boot.img" if you have the boot image in your home directory. Or else please specify the correct path.

如果所有都工作正常,你将看到"Done!"这样的确认信息。mkvendor.sh脚本也将在你的android源码树中创建以下目录:

manufacturer_name/device_name

 

4,

现在你已经拥有相关的配置文件

在源码目录下,在terminal终端下键入以下命令

. build/envsetup.sh

这一步将为你建立编译环境

现在使用这条命令

lunch full_device_name-eng

这将为你的设备建立起build system。用文件管理器或IDE打开目录,你应该拥有以下文件: AndroidBoard.mk, AndroidProducts.mk, BoardConfig.mk, device_.mk, kernel, system.prop, recovery.fstab, 和 vendorsetup.sh

 

对你感兴趣的应该是recovery.fstab和kernel这两个文件,kernel这个文件是你之前从boot.img文件中提取出的。recovery.fstab将适用于大部分拥有 mtd, emmc,或者其他分区的设备。如果没有,recovery.fstab将需要优化以支持加载这些点。例如 /sdcard被加载至/dev/block/mmcblk1p1,

你需要将下面这段加入到你的BoardConfig.mk文件中

/sdcard vfat /dev/block/mmcblk1p1 

一旦recovery.fstab已经适当的装载,你可以开始下一步了

 

5,

现在,我们开始编译Recovery

make -j4 recoveryimage

这个命令用于编译recovery镜像

你能使用这个命令

make -j4 recoveryzip

用于建立一个临时的recovery.zip刷机包在你真实的设备上测试

你编译好的recovery可以在"your_source_directory/OUT/target/product/device/recovery.img"目录下找到。而.zip刷机包可以在相同目录下的utilities文件夹下找到。

如果各项测试正常,就可以有一个成功的recovery

 

一旦你编译通过了recovery,通知"koush",在Github上,他就能根据你的编译文件发放官方版的CWM Recovery,并使Rom Manager提供相应的支持。

 

 

小贴士:

如果你想编译CWM6,使用以下命令同步jellybean分支源码

repo init -u git://github.com/CyanogenMod/android.git -b jellybean
 
repo sync

 

如果你改变了BoardConfig.mk文件,在编译期间运行"make clobber",否则你做的更改就不会生效。


//

主要参考了http://hi.baidu.com/juicewb/item/bb711fb3c3efcce84fc7fdf1及文章里提出的几篇文章。

我是在ubuntu 12.10 64位 系统来做这个的,建立好环境http://source.android.com/source/initializing.html

1.在下载安卓的源码

$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo

此命令有时候会连接不上,不懂怎么回事,这时就可以用以下命令,也是可以用的

$ curl ”http://php.webtutor.pl/en/wp-content/uploads/2011/09/repo” >~/bin/repo 

同步源码 repo sync -j16 ,的确速度快很多,下载ics源码大约只用了两个多小时,比我的预料快很多。

2.下载完源码,进入源码目录,执行

./build/envsetup.sh

3.执行 make -j4 otatools,下面问题就多了,

chen@chen-virtual-machine:~/cm$ make
cc: 错误: unrecognized command line option ‘-mfloat-abi=softfp’
cc: 错误: unrecognized command line option ‘-mfpu=neon’
cc: 错误: unrecognized command line option ‘-mthumb-interwork’
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.0.4
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=IMM76L
============================================
Checking build tools versions...
grep: build/target/board/generic/recovery.fstab: 没有那个文件或目录
build/core/java.mk:20: *** dalvik/dexgen: Invalid LOCAL_SDK_VERSION '4' Choices are: current 。 停止。

这是由于gcc版本引起的,我换了旧版本的gcc没有出现这个问题。

最后出现的问题是由于我的源码是直接拿过来的,重新同步prebuilt ,问题解决。

"rm -rf prebuilt ; repo sync -l prebuilt"

自己同步源文件的时候不会出现这个问题。

继续执行 make -j4 otatools,

中间若遇到cc错误的问题,均是gcc版本等问题引起。换gcc版本可以解决。

4.之后生成out目录,在out/host/linux-x86/bin中有后面要用的工具。

要将bin加入环境变量。

gedit ~/.bashrc
在文本最后添加:
export PATH=$PATH: ~/android/system/out/host/linux-x86/bin
保存退出,执行下面命令,让刚加的环境变量生效:
source ~/.bashrc

我按照上述操作,没有成功,我把环境变量添加在profile。

5.提取官方boot.img。放到了~/ad/目录
执行

./build/tools/device/mkvendor.sh zte n880e ~/android/boot.img
命令参考:
./build/tools/device/mkvendor.sh device_manufacturer_name device_name /your/path/to/the/boot.img

这都没有问题,在device之下会产生你的机型。

修改机型下面的recovery.fstab,我是直接从官方recovery.img中提取的

6.执行./build/envsetup.sh && lunch full_n880e-eng

这时候问题又来了,

1)提示 lunch"未安装"

2)提示 full_n880e-eng不存在,

第二个问题g了好久,才隐约知道问题所在,只能是自己太笨了。

上述问题执行source build/envsetup.sh 问题就解决了。

下面直接执行 lunch full_n880e-eng

7.最后执行

make -j4 recoveryimage

就可以生成我们需要的recovery.Img了。赶快去试试吧


///


首先声明,此教程并非我写,不过这篇教程在网上算是比较详细的教程,我转载过来,并加入一些我个人编译时的注解,希望可以帮到大家。

本教程是针对有一定基础的人。如果你不会Ubuntu,不会环境的搭建。那你还是先学习一下吧。装Ubuntu各种各样的教程,网上一找一大堆。
   教程所用的系统为Ubuntu12.04,示例机型为中兴N880E。源码目录为~/android/system/。
  码字不容易,你懂的。。。。。。。
我自己用的是ubuntu11.04,我的注解以红色表示
教程开始:
源码的同步大家可以看官方文档,教程直接从源码同步完后开始。
1、同步源码到最新,我同步的源码目录为~/android/system/,要改为自己的源码目录,下面每一步也一样
  • cd ~/android/system/
  • repo sync -j16


2、更新完成后,执行下面命令,完成环境的安装
  • ./build/envsetup.sh

在这一步,可能有些同学会出现权限不足的提示,大家可以看图,原教程作者也出现这个提示,可以按照他的命令,给目录777权限即可


输出结果:
12.jpg
3、下一步,make我们后面要用到的工具
  • make -j4 otatools
    输出结果:
    2.jpg


执行完成后的输出:
3.jpg
会生成out目录,在/out/host/linux-x86/bin中有后面要用到的工具

在这一步请注意,环境组件如果没有安装齐全,会出现一些报错的信息,请参考我发布的环境布置教程,安装完所有的组件。

4、将/out/host/linux-x86/bin加入环境变量,变量具体位置要改成你的:
gedit ~/ .bashrc
在文本最后添加:
export PATH=$PATH: ~/android/system/out/host/linux-x86/bin
4.jpg
保存退出,执行下面命令,让刚加的环境变量生效:
source ~/ .bashrc
4、从官方包中,别人的ROM包也可以,拿出boot .img。我放到了~/android/目录
5、开始建立我们N880E的 device目录:
./ build/ tools/ device/ mkvendor.sh zte n880e ~/android/boot .img
命令参考:
./ build/ tools/ device/ mkvendor.sh device_manufacturer_name device_name /your/path/to/the/boot .img
命令输出为:
5.jpg
此时在/ device/zte/中就会有你的机型n880e了,里面有你的配置文件:AndroidBoard .mk,AndroidProducts .mk, BoardConfig .mk, device_ .mk, kernel, system .prop,recovery .fstab, and vendorsetup.sh .
6、修改配置文件:
在这里很重要的一个文件就是recovery .fstab,是你手机里各个设备分区对应的挂载点,可以理解为手机的分区表。如果这个文件有错误,那么进入recovery后,会提醒分区挂载失败。
这个文件我们可以从官方的recovery .img提取出来。也可以直接解包别人编译好的recovery,得到recovery .fstab
当然,我们也可以自己动手写。目前,自己也没发现什么简洁一点的办法。我是查看刷机包中的updater-script文件中各个分区的挂载点和
cat /proc/mount
输出结果:
6.jpg
cat /proc/partitions
输出结果:
7.jpg
一个个排除定位出来的。
大家有好的办法,可以共同探讨。
这里有一个分区表比较全的recovery .fstab,大家可以按照自己手机的分区表修改。
7、开始编译,执行命令:
./ build/envsetup.sh && lunch full_n880e-eng
(把n880e替换为自己的机型)
输出结果:
8.jpg
下一步命令,编译开始:
make -j4 recoveryimage
最后成功时输出结果:
9.jpg
输出的目录为:out/target/product/n8880e/recovery .img文件,就是我们要的。
NOTE:
1、 编译时间:实体机,一两分钟的样子(i3-380、2GBDDR3)
2、 异常处理:(都是自己编译过程中遇到的笔录,非官方)
错误1:
执行
./ build/envsetup.sh
命令后,提示某些设备文件不存在。
这是自己当初在CM7源码下编译出现的,因为自己没有把所有的设备的源码同步下来,一些设备自己在~/android/system/ .repo/manifest .xml中用注释掉了,所以同步完源码后要修改vendor/cyanogen/products/AndroidProducts .mk 文件,把没有同步的设备删除掉。重新执行命令就行了。
错误2:
在编译的最后,提示出错 “Boot .img is too large”,自己当时的解决办法是修改BoardConfig .mk:
# fix this up by examining /proc/mtd on a running device
BOARD_BOOTIMAGE_PARTITION_SIZE := 0x01000000
BOARD_RECOVERYIMAGE_PARTITION_SIZE := 0x01000000
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 0x19000000
BOARD_USERDATAIMAGE_PARTITION_SIZE := 0xA0000000
BOARD_FLASH_BLOCK_SIZE := 131072
将后面的十六进制改为自己手机分区的大小,要把兆转换为KB,再转换为十六进制,然后替换0x后面的数字(0x表示十六进制)。
另一种解决办法,就在下面几篇参考文档中刚看的,未实践:
打开源码目录中的 Build/Core/definitions .mk,将1688 – 1694行替换为:
# if [ "$total" -gt "$maxsize" ]; then
# echo “error: $printname too large ($total > [$(2) - $reserve])”;
# false;
#el
if [ "$total" -gt $((maxsize - 32768)) ]; then
echo “WARNING: $printname approaching size limit ($total now; limit $maxsize)”;
fi
然后保存。重新编译即可。
错误3:
执行7中的第一个命令时,提示lunch未安装:
10.jpg
解决办法:
执行
source build/envsetup.sh
再执行上面命令就OK 了。
111.jpg
更进一步,自己也在学习中,还未实践的:
recovery_ui .c 这个文件里面是手机各按键对应的按键值,这样写入之后才能正确选择按键。对按键的修改自己找了一些资料还在进一步学习中。


总结

1.首先从每个手机的rom包中取出boot.img(主要网上提供的最新rom包,比如hiapk,甜辣椒官网等)

2.然后将boot.img 拷贝到源代码目录结构下面

3.开始boot.img

./build/tools/device/mkvendor.sh huawei u9508 ~/cyanogenmod/huawei/boot.img
4.开始编译源码

 source build/envsetup.sh 

5.选择编译好的菜单选择,此时full_u9508-eng 不存在,需要自己去输入
lunch full_u9508-eng

6.选择菜单完成后,开始编译生存recovery.img文件

 make -j3 recoveryimage

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值