porting cyanogenmod

由于Cyanogenmod的源码编译已经没有问题,手头手机又都不在Cyanogenmod的支持列表里,所以打算将cyanogenmod亲自移植到我自己的手机上。
参考:How To Port CyanogenMod Android To Your Own Device

必备知识

成功移植过cyanogenmod到已知已支持的设备上;
对cyanogenmod的代码目录结构要熟悉;
移植一般会涉及到如下三个目录:
/device/[vendor]/[codename]
/vendor/[vendor]/[codename]
/kernel/[vendor]/[codename]

搜集我们手机的相关信息

搜集手机的必要信息,如:product name, code name, architecture, memory size, internal storage size, and platform architecture.可以从手机中读取(手机最好已经root),或者在网上下载.zip升级包,从.zip包里解出获取相关信息;

mkdir lenovo_s2 && cd lenovo_s2
adb pull /system/build.prop

vendor name:
adb shell getprop ro.product.manufacturer 或者从build.prop中读取
codename:
adb shell getprop ro.product.device 或者从build.prop中读取

解包boot.img 或者 recovery.img得到内核文件kernel,在得不到内核源码的情况下,可以通过这种方式得到编译好的内核文件;

boot.img,recovery.img可以在root过的手机上找到其对应分区,然后取出来;或者从.zip中得到;

在device、vendor、kernel下创建手机相关的目录

  1. 通过mkvendor.sh脚本自动创建
  2. 从github仓库里找是否有手机型号比较接近的然后克隆下来
  3. 手动创建这三个目录结构

我们使用1.的方式,此种方式比较快速,先得到boot.img或者recovery.img

./build/tools/device/mkvendor.sh [vendorname] [codename] [boot.img|recovery.img]

If it returns the message “unpackbootimg not found. Is your android build environment set up and have the host tools been built?” please be sure that you run the following command during setting up the developer environment:

$ make -j4 otatools

$ export PATH=$PATH:[source path]/out/host/linux-x86/bin

$ ./build/tools/device/mkvendor.sh lenovo s2 ../lenove_s2/mmcblk0p8_boot.img 
Arguments: lenovo s2 ../lenove_s2/mmcblk0p8_boot.img
Output will be in /data/Android/Cyanogenmod/device/lenovo/s2
737 blocks
Creating initial git repository.
/data/Android/Cyanogenmod/device/lenovo/s2 /data/Android/Cyanogenmod
Initialized empty Git repository in /data/Android/Cyanogenmod/device/lenovo/s2/.git/
[master (root-commit) 89d920e] mkvendor.sh: Initial commit of s2
 8 files changed, 96 insertions(+)
 create mode 100644 AndroidBoard.mk
 create mode 100644 AndroidProducts.mk
 create mode 100644 BoardConfig.mk
 create mode 100644 cm.mk
 create mode 100644 device_s2.mk
 create mode 100644 kernel
 create mode 100644 recovery.fstab
 create mode 100644 system.prop
/data/Android/Cyanogenmod
Done!
Use the following command to set up your build environment:
  lunch cm_s2-eng
And use the follwowing command to build a recovery:
  . build/tools/device/makerecoveries.sh cm_s2-eng

此时在device/[vendorname]/[codename]/目录下会生成 AndroidBoard.mk, AndroidProducts.mk, BoardConfig.mk, cm.mk, device_[codename].mk, kernel , recovery.fstab等文件

ls device/lenovo/s2/
AndroidBoard.mk  AndroidProducts.mk  BoardConfig.mk  cm.mk  device_s2.mk  kernel  recovery.fstab  system.prop

客制化生成的文件

为了能使用生成的recovery.img正常工作,我们需要到device/[vendorname]/[codename]/下对生生的文件根据手机做相应的修改;

Setup build environment:

lunch cm_[codename]-eng
lunch cm_s2-eng

build recovery image:

. build/tools/device/makerecoveries.sh cm_[codename]-eng
. build/tools/device/makerecoveries.sh cm_s2-eng

这样就完成了recovery.img的编译,但是发现用了两部手机通过此步骤做出的recovery.img刷进去后手机无法启动该recovery。