Chinaunix首页 | 论坛 | 博客
  • 博客访问: 123416
  • 博文数量: 16
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 222
  • 用 户 组: 普通用户
  • 注册时间: 2014-07-23 22:32
个人简介

这个博客已经停止更新,请访问blog.mxslly.com

文章分类
文章存档

2018年(4)

2016年(3)

2015年(8)

2014年(1)

我的朋友

分类: Android平台

2015-11-24 10:41:01

How To Port CyanogenMod Android To Your Own Device

怎样把cyanogenmod移植到你自己的设备

Note:

If you came to this page by searching for information about porting Android, and you're not sure what CyanogenMod is, .

注意:

如果你通过搜索关于安卓移植的信息来到这里,而且你不知道cyanogenmod是什么,点击这里了解更多。

Some tips on porting CyanogenMod to your own device

一些关于移植cyanogenmod到你自己设备的建议

So you may come across a phone or tablet or whatever that does not yet have CyanogenMod available.

你可能会碰到一些手机或者平板电脑,他们没有可获得的cyanogenmod版本ROM

You've previously  on your computer for another device or two, and you feel comfortable with the process. In fact, you've still got the  standing by and are ready to tackle a big project.

你可能之前已经在你的电脑上为其他的设备编译过了Cyanogenmod,而且你对于这个过程很享受。事实上,你已经得到了源代码并且准备去处理一个大工程。

Looks like this is your opportunity to shine!

似乎你发光的机会到了。

Note:

For the purposes of this tutorial, all references to directories will assume you are in the root of the source code (ie, where you did the ), and folder names will be relative to there. If you followed the , the root of the source code is at 

注意:

在这个指导教程里面,所有对目录的提及都是假定你是在源代码的根目录(例如在你做repo init的地方),而且目录名会和那个地方有关。如果你遵循构建指导,源代码的根目录是在~/android/system

Prerequisites

预先需要的东西

Porting CyanogenMod to a new device can be ridiculously easy or ridiculously difficult, depending on the device itself, whether it currently runs a recent version of Android or not, and of course your skills as a developer matter too.

Cyanogenmod移植到一个新设备上可能是异常容易的或者异常困难的,这取决于设备本身,它是否运行着较新版本的安卓,当然你作为一个开发者的技术也是很重要的。

It would be pretty hard to do a port without having built CyanogenMod (and ) previously for another device. So if you haven't done a , give it a shot.

如果之前没有为其他设备构建过Cyanogenmod,做一个移植可能会非常难。所以如果你没有做过构建,尽量试试吧。

Helpful Tip

If you found this page other than via the CyanogenMod Learning Center, head over to  for much more information.

有用的建议

如果你不是通过Cyanogenmod学习中心发现这个网页的,点击这里去了解开发的更多信息。


Additionally, you should familiarize yourself with the 
. You should expect that, barring some rare exceptions, nearly everything you need to do will be in the /device/[vendor]/[codename], /vendor/[vendor]/[codename], and /kernel/[vendor]/[codename] directories (which you will need to create).

另外你应该对于Cyanogenmod源代码非常熟悉。你应该知道,不包括一些罕见的例外,你需要做的几乎一切都是在/device/制造商/开发代号,/制造商/制造商/开发代号,和/kernel/制造商/开发代号 目录(你将要创建它们)。

Helpful Tip

For a more-detailed overview of what's where in the CyanogenMod source folders, see . In fact, you really should read this if you plan on doing a port.

有用的建议

对于一个关于在Cyanogenmod源代码文件夹中哪些地方是什么东西的更详细的概述,点击这里。事实上,如果你计划做移植你真的应该读一读这个。

Collect information about your device

搜集你设备的信息

Before you begin your port, you will want to collect as much information about your device as you can. Go to  or XDA-Developers Wiki and identify the product name,  , ,  (i.e. ), memory size, internal storage size, and platform architecture. Put this information in a file for easy retrieval. Try to learn as much about the device, including any similarities it may have to other devices ( common elements, i.e chip, motherboard,  ...).

在你开始移植之前,你应该尽可能多的搜集关于你的设备的信息。去维基百科或XDA维基网站确认产品名,开发代号,生产商名,处理器架构(例如ARMv7架构),内存大小,内置存储器大小,和平台结构。为了方便检索把这些信息放在一个文件里面。努力去了解更多关于这个设备的东西,包括它和其他设备的任何相似的地方(芯片组相同的元素,例如,芯片,主板,GPU等等)。

Helpful Tip

Many devices are architecturally similar to other devices that are already on the market and have existing CM ports. When a new device comes out, see if you can find out if it may be identical to another device or have the same processor (i.e.  processor or  motherboard) only with a different sized screen or more memory or some other minor difference. If you find an "ancestor" or "sibling" of your device, much of the work may already be done for you!

有用的建议

许多设备和其他上市的已经有CM移植包的设备结构上相似。当一个新设备面世的时候,看看它是否是和其他设备相同或者有同样的处理器(例如ARM处理器或者MTK主板),只是有不同尺寸的屏幕或跟大的内存或一些其他小的差别。如果你能发现一个你的设备的祖先或者兄弟,那么许多工作都已经为你做好了。

Much of the information you need may be available online, but assuming the device is already running a non-CyanogenMod version Android, you may also get some of that information from the device itself. To view the files containing this information, sometimes the device may need to be  . However, sometimes you can find a  update package online, and can view the files from the .zip archive file.

你可以在网上获得许多信息,但是假设这个设备已经运行了一个非Cyanogenmod版本的安卓,你可以从设备本身得到一些信息。有时设备可能需要ROOT,这样才能看到包含这个信息的文件。然而,有时你可能在网上发现一个固件更新包,而且能从zip归档文件查看文件。

Look at the device's current /system/build.prop

查看设备目前的/system/build.prop文件

Assuming the device is already running a version of Android, there should be a file, , on the device which may contain useful information that will come into play as you do your port. This file contains definitions for various parameters and settings used by Android.

假设设备已经运行了一个版本的安卓,那就应该有这个文件/system/build.prop。在你做移植的时候会有作用。这个文件包被安卓使用的各种参数和设置信息。

So, if you have previously installed  onto your computer, you can use the following command to  this file to your computer:

所以,如果你之前已经在电脑上安装了adb,你可以用下面的命令把这个文件推到你的电脑上。

adb pull /system/build.prop

If you receive an error relating to permissions, the device may need to be  to gain access to this file. However, as said, there are other ways to locate this file. For example, it may be included in any stock firmware "upgrade" package online.

如果你收到了一个关于权限的错误,这个设备可能需要被ROOT才能获得这个文件。然而,也有其他的方法获得这个文件。例如,这个文件会包含在任何网上的固件更新包里面。

You can also use  and  from  ( is a prerequisite to use them).

你也可以用Build Prop EditorBuild Prop Editor,点击这里(root是使用它们的前提)。

Once you have the file...

当你有了这个文件

·         Write down the value of the ro.product.manufacturer parameter. This will be your vendor name. The [vendor] is the name of the manufacturer/vendor of the device. CM has established naming conventions for most major vendors, such as samsung, htc, lge, etc. Note that in these directory names, the vendor is always lowercase and contains no spaces.

  • 写下ro.product.manufacturer参数的值。这将是你的vender的值。Vender是设备的生产商或者销售商的值。CM已经为大多数主流生厂商建立了命名协定,比如samsunghtclge等等。注意在这些目录名中,生厂商名小写而且没有空格的。

·         Write down the value of the ro.product.device parameter. This will be your device codename. The [codename] corresponds to the project code name of the device itself. This is almost never the sales name of the device. If you have built CM before (and again, you better have!), you should be familiar with the concept of a code name for each device. Like the vendor name, the codename is always lowercase and contains no spaces.

  • 写下ro.product.device参数 的值。这是你的设备的开发代号。这个开发代号对应设备自己的项目代号名。这几乎绝不会是设备的销售名。如果你之前已经编译过CM(再一次说,你最好已经做过 了),你应该对每个设备的开发代号名这个概念很熟悉。和生产商名一样,开发代号也是小写无空格的。

Note:

Sometimes a device is identified in other parameters such as ro.product.board

注意

有时一个设备用其他的参数来确定,例如ro.product.board

Keep the build.prop file handy, as you may refer to it later.

留着build.prop文件,因为你后来可能用到它。

Examine boot.img and recovery.img

检查boot.imgrecovery.Img

As stated, when doing your port, you may wish to use an existing pre-built kernel that you know works instead of  one from  . Depending on your device, you may need to extract this kernel file from the device. The kernel may exist as a single file (as it does on many OMAP devices) or may be wrapped up along with the ramdisk in a boot or recovery partition.

就像之前说的,当做移植的时候,你可能希望用一个存在的之前编译好的内核,你知道它工作,而不是根据源代码编译一个新的。依靠你的设备,你可能需要从设备解压内核文件。内核可能存在作为一个单独的文件(在许多OMAP设备上就这样),或者可能连同内存盘被打包放进一个bootrecovery分区。

Similarly, the contents of the stock ramdisk may be extremely helpful and can often be extracted and reviewed. It may be the case that a device requires specific files from the stock ramdisk in order to boot properly, load a module, etc. In most cases you can view files in the ramdisk from the device itself, but it you may prefer to look at the full directory.

相似地,内存盘的内容可能非常有帮助,而且常常能被提取和检查。为了正常的开机,载入模块等,设备可能要求内存盘的特定的文件。在大多数情况下你可能要检查来自设备本身的内存盘,但是你可能更喜欢看整个目录。

Note:

The ramdisk is a tiny group of files and directories that are loaded into memory along with the kernel. The kernel then runs one of the files in the ramdisk called init, which then runs a script (init.rc, init.[codename].rc, etc.) that in turns loads the rest of Android. The ramdisk and kernel can be packaged together in a number of different ways using tools with names like mkbootimg, mkimage, and other methods.

提示

内存盘是一小群文件和目录,连同内核被载入内存。内核然后运行内存盘的一个叫做init的文件,init然后运行一个脚本(init.rcinit.开发代号.rc等等),接着依次载入安卓的剩余部分。内存盘和内核能够以许多种不同的方式打包在一起,通过使用像mkbootimgmkimage等这样的工具。

You can frequently extract the boot and recovery images (to a file you name boot.img and recovery.img) on a rooted Android device using .

你可以经常使用dd命令在已经ROOT的安卓设备上提取bootrecovery镜像。

Or, if you have access to an  .zip file from the vendor (that could call it firmware), you can often find those files within.

或者,如果你从生厂商那里获得了一个update.zip文件(常常被他们成为固件),你能在里面发现这些文件。

Collect any available existing source code

搜集任何可获得的,存在的源代码

The manufacturer or vender of any device using Android will minimally need to make the source code available for all  components upon request, including (and especially) the kernel. You definitely want to request a copy of the kernel source and keep it handy.

任何使用安卓的设备生厂商或者销售商会最小地让源代码可获得,由于遵循GPL协议的组件,包括(特别是)内核。你确实可以要求一份内核源代码并且留在手里。

Determine the partition scheme

决定分区表

The primary long-term storage portion of your mobile device-- usually an "emmc" (embedded )-- is much like a computer hard drive in that it is prepared in a la particular way to identify and isolate different areas of data. These unique areas are called  and they can have any kind of data stored there. Some partitions contain  --  ,  s,  s, etc. More often, a partition is formatted to use a particular  that the kernel will recognize so that individual files and directories can be read and written there.

你的移动设备主要的长期存储部分,通常是一个“emmc”芯片,更像一个电脑的硬盘驱动器,因为它在一种特殊的方式下被准备好,能识别和隔离不同的数据区域。这些独立的区域被叫做分区,他们能让任何种类的数据存储在那里。一些分区包含原始数据,固件,内核,内存盘等等。更加经常的是,一个分区被格式化来使用一个特定的内核识别的文件系统,所以单独的文件和目录能在那里被读和写。

Before you can replace the stock operating system with CyanogenMod, it is therefore important to ascertain the  of the device. The recovery image you build will need this information to know where to find the various Android directories. Particularly, you want to know which partitions are assigned to /system, /data, /cache, and /sdcard.

在你用Cyanogenmod代替原来的操作系统之前,确定设备的分区表是相当重要的。你构建的Recovery镜像将需要这些信息来知道在哪里发现各种安卓目录。特别是你想知道哪些分区被安排为/system, /data, /cache/sdcard

You want to know which partitions exist, on what device, how they are mounted, as well as the size of the partitions. This information may be transferred later to the BoardConfig.mk file in your /vendor directory.

你想知道哪个分区存在在哪个设备上,它们怎么被挂载,以及分区的大小。这个信息后来可能被转移到你的/vender目录的BoardConfig.mk文件。

If you're lucky, a recovery.fstab file can be located in a recovery.img file, speeding up the process of figuring out what goes where. Also, the init.[codename].rc file in the  may have the information. Look for the lines near the top where the partitions are mounted.

如果你幸运,会发现一个recovery.fstab文件在recovery.img文件中,加快弄清楚什么东西去哪里的过程。这个在内存盘中的init.开发代号.rc文件可能有这个信息。在文件靠近头部的几行分区被挂载。

Also, the command:

这个命令是

$ cat /proc/partitions

from a running device can also help you identify the partitions. Also see /proc/emmc, /proc/mounts or /proc/mtd. You may also get some information from the command mount (run as  ).

从一个运行的设备也能帮你识别这个分区。也可以看看/proc/emmc, /proc/mounts 或者 /proc/mtd目录。你也可以用命令mountroot权限)得到一些信息。

Also check /cache/recovery.log or /tmp/recovery.log.

也可以检查一下/cache/recovery.log 或者 /tmp/recovery.log文件

Finally, if you have source code to the  (such as the  used by many  -based devices), you will likely find the information there as well.

最后,如果你有bootloader的源代码(比如被许多基于OMAP设备使用的u-boot),你也很可能在那里发现这些信息。

Note:

Be aware that in some rare cases, such as the , an abstracted  is used.

注意:

要知道在一些很罕见的情况下,例如HP Touchpad,一种VFS虚拟文件系统被使用。

Set up three new directories

建立三个新的目录

Now that you've gathered information about your device, it's time to generate the folders for your device configuration, located in the following directories, relative to the code source directory.

现在你已经收集的你的设备的信息,是时候为你的设备配置建立文件夹了。这些配置信息在下列文件夹里,和代码资源有关。

·         device/[vendor]/[codename]/ -- this is where the installation files specific to your device will go. The device/ directory contain 99-100% of the configuration settings and other code for particular devices. You'll get to know this directory pretty well. As mentioned, when starting the folder for this device, it may be a good idea to adapt a directory for an existing device that is architecturally similar to the one you wish to port. Look for a device that is based on the same platform, as  or  chipset, for example.

·         这是和你的特定的设备有关的安装文件要去的地方这个device文件夹包含99%100%的设置配置信息和其他针对特殊设备的代码。你将逐渐了解这个文件夹。就像之前说的一样,在为这个设备建立文件夹时,比较好的做法可能是去修改一个已存在的设备的文件夹,这个已存在的设备是和你希望移植的设备在架构上相似。寻找基于同一个平台的设备,例如使用ARMv7MTK芯片组。

·         vendor/[vendor]/[codename]/ -- The vendor/ directory contains proprietary, binary "blobs" that are backed up from the original device (or provided by the vendor, such as in the case of Google Nexus devices and some TI graphics blobs).

·         vendor文件夹包含生产商专有的,从原始设备打包的二进制块文件(或者是被生产商提供的,例如Google Nexus设备和一些德州仪器的图像处理块文件)

·         kernel/[vendor]/[codename]/ -- the kernel source goes here. When you first start your porting effort, you may wish to simplify things by using a pre-built kernel (such as the one that came with the stock installation) rather than building the kernel from scratch. The trick to that will be extracting the kernel out of the stock system from whatever format it may be in, and then re-packaging it, along with a new ramdisk, into a form that your device can use. This can vary from device-to-device, so it may again be helpful to look at similar devices to yours that use a similar architecture. Building the kernel from source is not strictly necessary for every device, but in the spirit of open source, it is the preferred practice for CyanogenMod. See  for a detailed discussion about how CyanogenMod builds the kernel source from scratch.

·         内核源代码在这里。在你第一次开始移植的努力的时候,你可能希望使用一个预先编译好的啮合来简化工作(例如来自一个固件安装包的内核),而不是从头开始。那样做的技巧就是从一个无论内核是什么格式的原来的系统中提取内核,然后加上一个新的内存盘来重新打包,用一个你的设备可以使用的格式。这种活可能不同的设备有不同的方式,所以再一次说明找一个有相似架构的设备是很有帮助的。用源代码重新构建内核不是对每个设备都是必要的,但是本着开源的精神,重新编译对于Cyanogenmod更好。

There are at least three methods to generate these directories:

至少有三种建立这些文件夹的方式。

Method 1: Use mkvendor.sh to generate skeleton files

方法一:用mkvendor.sh建立框架文件

Use the mkvendor.sh script in build/tools/device/ to automatically generate the directories.

用在build/tools/device/mkvendor.sh脚本自动建立这些文件夹

Note:

The mkvendor script only works with devices that use a standard boot.img file, using the standard Android conventions and headers. It won't work for devices that deviate from this standard (Nook Color, Touchpad, etc.).

注意:

Mkvendor脚本只和使用标准boot.img文件的设备工作,它使用标准的安卓协定和文件头。它不会和偏离这个标准的设备工作(例如Nook ColorTouchpad等等)。

This script accepts three parameters: vendor, codename, and a boot.img file.

这个脚本接受三个参数,vendorcodename和一个boot.img文件

Example usage:

示例用法:

$ ./build/tools/device/mkvendor.sh samsung i9300 ~/Desktop/i9300boot.img

In the above example, samsung represents the vendor, i9300 represents the codename and the last parameter is the path to the boot.img file that was extracted from the boot partition with dd or provided by the vendor in an update .zip as discussed above.

在上面的例子中,samsung代表生厂商,i9300代表开发代号名,最后一个参数是到boot.img文件的路径,像上面讨论的一样,这个文件用dd命令从boot分区解压出来或者被生产商提供在一个update .zip里。

The command above should create a /device/samsung/i9300/ folder within your CyanogenMod source repo structure. And inside the folder, the files AndroidBoard.mk,AndroidProducts.mk, BoardConfig.mk, cm.mk, device_[codename].mk, kernel (the binary), recovery.fstab, etc.

上面的命令会创建一个/device/samsung/i9300/文件夹,在你的Cyanogenmod源代码repo结构里。这个文件夹里面有AndroidBoard.mkAndroidProducts.mk,BoardConfig.mk cm.mk,device_[codename].mk,kernel (二进制的) recovery.fstab等等文件。

This will not build the kernel/ directory. You will need to do that later, when you are ready to build the kernel.

这样不会建立内核文件夹。在你准备去构建内核的时候,你将会去建立这个文件夹。

Note:

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

注意:

如果它返回这个信息“unpackbootimg没有发现。你的安卓编译环境建立了吗?而且host工具被构建了吗?”请确定你在建立开发环境的时候运行了下列的命令。

Method 2: Fork a similar device's git repository

方法二:复制一个相似设备的git仓库

If you've got a  account, you might want to start by  another, similar device, and then rename it for your device. See the section on setting up github for a discussion on how to name your repository.

如果你有一个git账号,你可能想通过复制另一个相似的设备的文件夹然后重命名为你的设备来开始。可以看看这个section on setting up github关于怎样命名你的仓库的讨论。

Always be sure you're compliant with the license of any repository you fork.

当然要确定你符合任何你复制的仓库的许可证。

Method 3: create the directories and files manually

手动创建文件夹和文件

You can always start with an empty directory and start creating the files by hand. This is the least recommended and perhaps the most tedious method, but it may be the most instructive. You can look at other devices for reference on what files you need.

你总是可以以一个空文件夹开始来手动创建文件。这是最不推荐的和或许最冗长乏味的方法,但也可能是最有益的方法。你可以可以参考其他的设备来决定你需要什么文件。

Customize the files

定制这些文件

There are many files in the device/ folders. We will start by focusing on four files BoardConfig.mk, device_[codename].mk, cm.mk, recovery.fstab, and kernel to get recovery working for your device.

device文件夹里有很多文件。我们会通过致力于四个文件BoardConfig.mkdevice_[codename].mk cm.mk recovery.fstab来开始,kernel文件是为了得到recovery为你的设备工作。

Helpful Tip– Start with the recovery!

The first major step is to get a working recovery image for your device so that testing subsequent update.zips is easy. A working recovery will also assist you in doing backups if necessary.

Since having a working recovery is so critical for doing your port, these next steps will focus more on getting a working recovery than getting CM itself to work. Once the recovery is built and operating safely, the work you've done will apply directly to the CM part as well.

有用的建议,以recovery开始

第一个主要的步骤是为你的设备得到一个工作的recovery镜像,所以测试接下来的update.zip是容易的。一个工作的recovery镜像将会帮助你在必要的时候备份。

因为一个工作的recovery对做你的移植是如此至关重要,这些接下来的步骤将会更加致力于得到一个工作的recovery,和让CM它自己去工作相比。一旦recovery被构建和安全地运行,你已经做的工作也将会直接应用到CM的部分。

Lets examine each of these files:

让我们检查这些文件的每一个。

BoardConfig.mk

This file contains vital architectual and build information about the architecture of your device's motherboard, CPU, and other hardware. Getting this file right is essential.

这个文件包含必不可少的关于你的设备的主板架构,CPU,和其他硬件的架构的和构建信息。让这个文件正确是至关重要的。

To get a basic recovery booting, a few parameters need to be set in this file.

为了得到一个基本的recovery镜像,几个参数需要在这个文件里设置。

The following parameters must be set properly in BoardConfig to compile a working recovery image:

接下来的几个参数必须在BoardConfig中被合适地设置,为了编译一个工作的recovery镜像。

·         TARGET_ARCH: this is the architecture of the device it is usually something like arm or omap3.

·         这是这个设备的架构,通常像armomap3.

·         BOARD_KERNEL_CMDLINE: not all devices pass boot parameters however if your device does this must be filled out properly in order to boot successfully. You can find this information in the ramdisk.img. (You can learn more about configuring the integrated kernel build-from-source .)

·         不是所有的设备都传递开机参数。但是如果你的设备确实这样,那为了正确地开机这个参数必须被合适地填写。

·         BOARD_KERNEL_PAGESIZE: the pagesize of the stock boot.img and must be set properly in order to boot. Typical values for this are 2048 and 4096 and this information can be extracted from the stock kernel.

·         这是boot.img的页大小。为了开机必须被合适地设置。典型的值是2048或者4096,而且这个信息可以从原来的内核中提取。

·         BOARD_BOOTIMAGE_PARTITION_SIZE: the number of bytes allocated to the kernel image partition.

·         分配给内核镜像分区的字节数。

·         BOARD_RECOVERYIMAGE_PARTITION_SIZE: the number of bytes allocated to the recovery image partition.

·         分配给recovery分区的字节数

·         BOARD_SYSTEMIMAGE_PARTITION_SIZE: the number of bytes allocated to the Android system filesystem partition.

·         分配给安卓system文件系统的字节数。

·         BOARD_USERDATAIMAGE_PARTITION_SIZE: the number of bytes allocated to the Android data filesystem partition.

·         分配给安卓data文件系统分区的字节数

Note:

The above information can be obtained by multiplying the size from /proc/partitions or /proc/mtd by the block size, typically 1024.

注意:

这上面的信息可以通过把来自/proc/partitions /proc/mtd的大小和块大小相乘得到,典型的是1024

·         BOARD_HAS_NO_SELECT_BUTTON: (optional), use this if your device needs to use its Power button to confirm selections in recovery.

·         (可选的),如果你的设备需要在recovery中用电源键去确认选择,你要使用这个

·         BOARD_FORCE_RAMDISK_ADDRESS / BOARD_MKBOOTIMG_ARGS: (optional), use these to force a specific address for the ramdisk. This is usually needed on larger partitions in order for the ramdisk to be loaded properly where it's expected to exist. This value can be obtained from the stock kernel. The former is deprecated as of Android 4.2.x and the latter will now be used in 4.2.x and beyond.

·         (可选的)用这个去强制为内存盘指定一个特定的地址。这通常在分区很大的时候被需要。为了让内存盘在它应该在的地方被合适地载入。这个值能从原来的内核得到。安卓4.2.x之前是不推荐的,但之后版本这个东西被使用。

device_[codename].mk

The device_codename.mk  contains instructions about which Android packages to  , and where to copy specific files and packages, or specific properties to set during your  .

这个device_codename.mkmake文件包含一些指导说明,说明要编译哪些安卓包,复制特定的文件和包到哪里,或特定的在你编译的时候设定的资源。

This file can be used to copy vital files into the  at compilation time.

这个文件可以被使用在编译的时候复制必不可少的文件到内存盘。

·         PRODUCT_COPY_FILES: used to copy files during compilation into the ramdisk, which will be located at $OUT/recovery/root.

  • 这个变量被使用在编译的时候把一些文件复制到内存盘,这些文件将会位于$OUT/recovery/root

Example:例子:

$(LOCAL_PATH)/sbin/offmode_charging:recovery/root/sbin/offmode_charging \

This will copy the file offmode_charging binary into the  folder within the ramdisk.

这将会把offmode_charging这个二进制文件复制到内存盘里的sbin文件夹。

·         PRODUCT_NAME / PRODUCT_DEVICE: used for setting the value of your codename. This is the name of the device you load with .

·         被用来设置你的开发代号的值。这是你用lunch载入的设备的名称。

Kernel内核

This is simply the prebuilt kernel image or a kernel you built yourself used to boot the device. The format of the kernel may be in a  or  , depending on the requirements of the  of your device.

这就是预编译的内核或你自己编译用来启动设备的内核。内核的格式可能是zImage或者uImage,取决于你的设备架构的要求。

cm.mk

You'll need to make a few changes to this file to integrate with the  ,  , and  commands, so that your device shows up on the list and builds properly. You'll also set some variables (see other devices) to indicate what size splash animation should be used, whether this is a tablet or phone, etc.

为了集成lunchbrunchbreakfast命令你将需要对这个文件做一些改变,这样你的设备将会出现在列表上和正确的编译。你也会设置一些变量(看看别的设备)来说明什么尺寸的开机动画应该被使用,这是一个手机还是平板,等等。

Some of these settings aren't used for building just the recovery, but you may as well set them now because once recovery is done and working, the settings here will be important.

这些设置中的一些不会被构建CM使用,只是为了recovery,但是你也应该现在设置它们,因为一旦recovery做好而且工作,这些设置将会变得非常重要。

Again, take a look at a similar device to yours to get an idea of what the settings here should be. It's fairly intuitive.

在说一次,看一看相似的设备来了解这里的设置应该是什么样的。这是相当靠直觉的事。

recovery.fstab

 defines the   ,  , and block device for each of the partitions in your device. It works almost exactly like in a standard Linux operating system.

recovery.fstab定义了你设备的文件系统,挂载点,文件系统类型和每个分区对应的块设备名。它就像标准linux操作系统的/etc/fstab一样工作。

Example:例子:

/system           ext4        /dev/block/mmcblk0p32 

This sets the block device at mmcblk0p32 to be mounted on /system as filesystem type ext4

这句话设置在mmcblk0p32的块设备挂载在/system文件夹,以ext4的文件系统类型。

All mountpoints should exist in this file and it is crucial this information be correct or else very bad things can happen, such as a recovery flash writing to the wrong location.

所有的挂载点都应该存在在这个文件,保持这个信息正确是至关重要的,否则非常坏的事情可能发生,比如一个recovery烧写了错误的区域。

Note:注意:

The filesystem type datamedia can be used for internal sdcards as well as setting the block device to /dev/null.

看不懂了

vendorsetup.sh

vendorsetup.sh is called when setupenv.sh is run. It is used to add non-standard lunch combos to the lunch menu.

setupenv.sh运行时需要vendorsetup.sh这个脚本。它被使用来添加非标准的lunch套餐到lunch菜单。

To add your device to the lunch menu:

把你的设备添加到这个lunch菜单:

add_lunch_combo cm_-userdebug

Then build a test recovery image

然后编译一个测试的recovery镜像

To build only the recovery, set up lunch as with a regular build, and say make recoveryimage.

为了只编译一个recovery,用一个一般的构建来建立lunch然后输入make recoveryimage

If things break (and they will break), have a look at these tips for .

如果事情出错了(而且这几乎是必然的),看看这些关于如何处理编译错误的建议。

Helpful Tip

If you have , you can try it to install the recovery image to the  . There are other methods for installing the recovery, such as using  from a rooted system to flash it into place.

有帮助的建议:

如果你有fastboot,你可以试着安装recovery镜像到recovery分区。也有其他方法安装recovery,比如在一个root的系统用dd命令烧录。

Not much needs to be said here, but make sure the recovery is working before you move on to getting CyanogenMod working. A 100%-working and reliable  is absolutely necessary before you start testing experimental Android builds.

不是非常有必要在这里说,但是在你继续让Cyanogenmod工作之前应该保证这个recovery工作。一个百分之百工作和可靠的recovery在你开始测试实验性的安卓编译之前是绝对有必要的。

Adjust recovery_ui.cpp if necessary

在必要的时候修改recovery_ui.cpp文件

You may discover that although the recovery image runs, some of the hardware buttons, such as the volume buttons or power buttons, which would normally be used to scroll through the options, don't work.

你可能会发现即使recovery镜像工作,一些硬件按键,比如通常用来滚动选项的音量键或电源键,不工作。

You may need to adjust the  values to get the buttons to be recognized. Similarly, you may wish to include/exclude options or modify other UI elements.

你可能需要调整GPIOGeneral Purpose Input Output (通用输入/输出)简称为GPIO,译者注)的值来让按键被识别。同样地,你可能会希望包括或去除一些选项或修改其他UI元素。

To do this, you may wish to create and edit the /device/[vendor]/[codename]/recovery/recovery_ui.cpp. You can find ample examples of this file, the associated file that builds it, and how it is used.

为了这样做,你可能会希望创建和编辑/device/[vendor]/[codename]/recovery/recovery_ui.cpp这个文件。你可以发现这个文件的大量的例子,相关的编译它的recovery/Android.mk文件和它是怎样被使用的。

Helpful Tip

The GPIO values for your device may be found in the  .

有帮助的建议

你的设备的GPIO的值能在内核源代码中找到。

Put your device folder in github, and use a local manifest to automatically sync it with repo sync

把你的设备文件夹放到git上去,用repo sync命令,使用一个本地清单来自动同步它

Once you've started your device folder, create your own  account and . This is a great opportunity to learn about , and also your source can be accessible to others who can collaborate with you.

一旦你建立你的设备文件夹,你就应该创建你自己的账户并且建立你的文件夹作为一个公共的GitHub仓库。这是学习git 的一个很好的机会,而且你的源代码也可以被那些能协助你的人获得。

When naming your repository, use the format android_device_VENDOR_CODENAME, where VENDOR and CODENAME use the new device's values. So, let's say your GitHub account name is "fat-tire" and your device codename is "", manufactured by Barnes and Noble. You should call your repository android_device_bn_encore. It would be accessible at https://github.com/fat-tire/android_device_bn_encore. Similarly, the kernel repository would be called android_kernel_bn_encore. It would be accessible at .

在命名你的仓库的时候,使用这样的格式android_device_VENDOR_CODENAMEvendorcodename用新设备的值。所以,假如说你的GitHub账户名是fat-tire而且你的设备开发代号是encore,被Barnes and Noble制造。你应该把你的仓库叫做android_device_bn_encore。这个可以在https://github.com/fat-tire/android_device_bn_encore获得。类似的,内核仓库将会被叫做android_kernel_bn_encore。这个也可以在获得。

The last thing to do is create a  for other people to use to automatically download and their keep up-to-date with your changes. Here's an example, using the above scenario:

最后一件事是创建一个本地文件清单,方便其他人用它自动下载代码和于你的改动保持一致。这里有一个例子,使用了上面的情景。

  
  

Note:

The revision attribute is optional. If it is omitted, repo sync will use the revision specified by the  tag in the .

注意:

这个revision属性是可选的。如果它被省略,repo sync会用在默认manifest标记的revision

Once you've tested that the  file works, you can pass it on to others, who can then try out your work. At that point you can continue to push your changes to GitHub, and even give other users commit access so that you can work on the device together.

一旦你测试了这个本地文件清单工作,你就可以把它传递给别人,这些人可以协助你的工作。那个时候你也可以继续把你的修改推送到GitHub,甚至可以给别的用户委托权限,这样你们就可以一起开发这个设备。

Helpful Tip– Using other repositories

If you find that for some reason you need to replace or supplement other repositories provided by CyanogenMod, you can add additional repositories using the . Once you've got everything working, you can use  to submit stuff found in those repositories back upstream to CyanogenMod.

有帮助的建议——使用其他的仓库

如果你发现,由于某些原因你需要代替或补充由Cyanogenmod提供的其他仓库,你可以使用本地文件清单添加附加的仓库。一旦你让一切工作,你可以用Gerrit来反过来向Cyanogenmod提交在这些仓库中发现的组件。

Add the blobs to the vendor/ directory

把块文件添加到vendor文件夹

Once you have a working recovery, it's now time to get CyanogenMod building and working.

一旦你有一个工作的recovery,是时候来编译Cyanogenmod和让它工作了。

The first thing you may do is to get all the proprietary, binary  into the vendor/ folder, along with a  file that will include them in the final build.

你要做的第一件事就是把所有的专有的文件,二进制块文件放进vendor文件夹,连同在最后编译的时候会把它们包含进来的.mk文件。

This requires three steps:

这需要三步:

1.    Create  and   s to pull those blob files from the device using  and put them in the right  directory. There are plenty of examples available for other devices.

创建一个extract-files.shsetup-makefiles.sh脚本来用adb把这些块文件从设备拉出来,然后把它们放进vendor目录。其他的设备有足够多可获得的例子。

2.    Create an .mk Makefile to copy those files to the  folder during the build process and put them in the right place. Again, use other devices as a guide for what this Makefile should look like. An example filename might be 

创建一个.mkmakefile文件来在编译的过程中把这些文件复制到$OUT文件夹并且把它们放在正确的地方。再说一次,用其他的设备指导自己,这个makefile文件应该看起来怎么样。一个示例文件名可以是BoardConfigVendor.mk

3.    Make sure that the Makefile you just created is included from your main BoardConfig.mk via a command such as -include vendor/[vendor]/[codename]/BoardConfigVendor.mk. Again, existing devices can illustrate how this is done.

保证你刚刚创建的makefile文件被你的主要的BoardConfig.mk包含,用一个像-include vendor/[vendor]/[codename]/BoardConfigVendor.mk这样的命令。再一次说,存在的设备可以说明这个是怎么工作的。

An alternative is use the blob-free and free code .

一个可以选择的是使用blob-free和自由代码项目Replicant

Now revise the device/ directory

现在修改一下这个device目录

Since you have a working recovery, go back and start modifying the files in the device/ folder . As always, use other similar devices as a reference.

一旦你有了一个工作的recovery,回去开始修改device文件夹里的文件。总是要记住,使用相似的设备作为参考。

You now have a easy means to do backups and test your builds. So start tweaking the device folder itself, and see if you get it to boot... Once you do, from there its a matter of building and supporting the various parts and peripherals, one-by-one.

你现在有一个容易的方法来备份和测试你的系统。所以开始拉扯设备文件夹它本身,看看你是否能让她开机。一旦你成功了,就可以一个接一个地编译和支持这个设备的各个部分和外围组件。

Getting help from the manufacturers & vendors

从生产商和销售商那里获得帮助

Many of the  s ( s) who make the underlying platform used by your device frequently provide wikis, documentation, and sample code that can assist you in completing your port. You'll find that some companies are more friendly to the development community than others. Here are some of the more common OEMs and vendors, along with web sites and repositories that may help.

许多制造你的设备使用的基础平台的OEM(原始设备制造商)经常提供维基、文档和示例代码,这能帮助你完成你的移植。你将会发现一些公司比另一些公司对开发社区更加友好。这里有一些更加普遍的OEM和销售商,以及可能会有帮助的网站和仓库。

(This list is incomplete. Please help add to it)

这个列表是不完全的。请帮助添加。

OEM

Platform

Repositories/Resources

Google

various

, Nexus binary blobs

HTC

various

Dev Center

HP

various

Lenovo

various

Lenovo Smartphones (Search your device)

LG

various

Motorola

various

Nvidia

Tegra

Qualcomm

MSM/QSD

Samsung

various

Texas Instruments

OMAP

 , 

Sometimes if you have questions you can even reach out to the developers via email or the support forums.

有时如果你有问题你可以致邮件给开发者或者支持的论坛。

Adding XML Overlays

添加XML覆盖文件

It's very likely in your device_[codename].mk file, there's a line that looks like this:

在你的device_[codename].mk文件里,可能有一行看起来这样的:

DEVICE_PACKAGE_OVERLAYS := \
    device/[vendor]/[codename]/overlay

What this does is set the  folder to allow you to override any XML file used by  s or apps, just for this device. To do so, create a directory structure which mirrors the path leading to an XML file, starting from the root of your source. Then replace the file you want to overlay.

这段话做的工作是设置这个overlay文件夹来允许你为你的这台设备抛弃任何被安卓框架或者apps使用的XML文件。为了能够这样做,创建一个对应到一个XML文件的文件夹结构,从你的源代码的根目录开始。然后取代你想去抛弃的文件。

Example: Let's say you want to override some standard Android settings. Look at the file in frameworks/base/core/res/res/values/config.xml. Then copy it todevice/[vendor]/[codename]/overlay/frameworks/base/core/res/res/values/config.xml. Now YOUR version will be used instead of the other one. You only need to include the settings you wish to override-- not all of them, so you can pare down the file to those few that change from the default.

例子:假设你想抛弃一些标准安卓设置。找到这个文件frameworks/base/core/res/res/values/config.xml。然后把它复制到device/[vendor]/[codename]/overlay/frameworks/base/core/res/res/values/config.xml。现在你的版本的文件将会被使用。你只需要包含你想要抛弃的设置,没必要是全部。所以你能让这些文件与默认的改变得更少。

You can overlay any XML file, affecting layouts, settings, preferences, translations, and more.

你可以覆盖任何XML文件,这可以影响布局、设置、偏好、翻译等等。

Make the kernel and kernel modules build from source

从源码编译内核和内核模块

If you have previously used a pre-built kernel, you may at some point want to start building the kernel from scratch.

如果你之前已经使用了一个预编译的内核,你可能想去从头开始编译内核。

See the instructions for how to change the BoardConfig.mk file to make CyanogenMod .

看看这个关于怎么改变BoardConfig.mk文件来使CM自动编译内核和任何要求的内核模块的介绍。

Conclusion

结论

There's no way a single wiki page will tell you everything you need to know to do a port from beginning to end. However, hopefully you now have an understanding of how things are set up and the steps you need to take. You can always ask for help on the  or on . Others with the same device, chipset or platform (i.e. same  chip) may jump in to help too.

没有一个单独的网页能告诉你需要知道的一切,来从头到尾完成一次移植。然而有希望的是你现在已经对事情是怎么建立的和你需要采取的步骤有了一个理解。你总是可以在CM论坛或者IRC上寻求帮助。其他有同样设备、芯片组或者平台的人会跳出来帮助你。

Hopefully you'll find the process rewarding and educational. And it'll get you some street cred as well.

有希望的是你会发现这个过程是让你受益匪浅的和受教育的。而且它也会让你得到许多宝贵的能力。

When you're all done, and your port works better than stock... when it's stable and shiny and marvelous and wonderful and includes improvements, free code or commons grounds for different devices...

在你完成时,你的移植包工作得比官方的更好……在它是稳定的和闪耀的和令人惊异的和很棒的和包含了很多改进的时候,

You may want to contribute your work upstream.  for how to do just that.

你可能想要反向的贡献你的代码。这里有一些怎么做的建议。

Good luck!

祝你好运!

See Also

·        

·        

·        

·         , for official release installation.

·        

·        

·        

·         , to install unofficial ports.

·        

External links

·          -- the official Google Group on this topic

·         General CyanogenMod Porting Discussion -- a forum post on porting

·         How To Port Different Roms to Your Device

·         How to port ROMS.

: 

·        

 

阅读(2865) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~