AOSP 的 Android 设备配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11352709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:07:38  来源:igfitidea点击:

Android device configuration for AOSP

android

提问by Tejas Jadhav

I've downloaded Android source code. Now I want to make it for my own device (LG GT540). I heard that you need to create some 'Device configuration' for that. Although several developers have already created device configurations for my device, but I want to create my own, just for learning.
I saw a lot of files like BoardConfig.mk, AndroidProducts.mk, etc. But don't know what they do. Besides they contain a lot of configurations. Over that, there's not a good documentation for that.
Can anyone experienced with Android porting and device configurations help me?

我已经下载了Android源代码。现在我想为我自己的设备(LG GT540)制作它。我听说您需要为此创建一些“设备配置”。虽然有几个开发者已经为我的设备创建了设备配置,但​​我想创建自己的,仅供学习。
看到了很多BoardConfig.mk、AndroidProducts.mk等文件,但不知道它们是做什么的。此外,它们包含许多配置。除此之外,没有一个很好的文档。
任何有 Android 移植和设备配置经验的人都可以帮助我吗?

回答by t0mm13b

Right... So you want to build your own device tree, read on.

对...所以您想构建自己的设备树,请继续阅读。

Disclaimer:this is by no means complete, and there will be omissions as have explained all this top of my head and copied pasted certain bits that I have here on my own device tree.

免责声明:这绝不是完整的,并且会有遗漏,因为我已经解释了所有这些我的头顶并复制粘贴了我在我自己的设备树上的某些位。

The device tree, for example, /device/lg/gt540would consist of the following make files:

例如,设备树/device/lg/gt540将包含以下 make 文件:

  • Android.mk- this will tell the build system to include and to build sources specifically for your device. See below, for an example. This is dependant on the device and hardware, you could have libsensors, liblights, libcamera subdirectories under the example device tree, i.e. /device/lg/gt540/libsensors, /device/lg/gt540/liblights, /device/lg/gt540/libcameraetc.
  • AndroidBoard.mk- this is for the kernel, the build system uses that to drop the kernel image in place (more about this in a few minutes)
  • AndroidProducts.mk- specifies the appropriate device's make file, to use for building. i.e. /device/lg/gt540/device_gt540.mk, this is specific also.
  • device_xxxxx.mk- specifies the properties and extras to copy over into the final output, in this case, it could be for example, device_gt540.mk
  • BoardConfig.mk- This is the meat of it all, this is where compiler conditional flags are set, partition layouts, boot addresses, ramdisk size, and so on.
  • Android.mk- 这将告诉构建系统包含和构建专门用于您的设备的源代码。见下文,举个例子。这取决于设备和硬件上,你可以有例子装置树下libsensors,liblights,libcamera子目录,即/device/lg/gt540/libsensors/device/lg/gt540/liblights/device/lg/gt540/libcamera等等。
  • AndroidBoard.mk- 这是内核,构建系统使用它来放置内核映像(几分钟后会详细介绍)
  • AndroidProducts.mk- 指定用于构建的适当设备的 make 文件。即/device/lg/gt540/device_gt540.mk,这也是具体的。
  • device_xxxxx.mk- 指定要复制到最终输出中的属性和附加内容,在这种情况下,它可以是例如,device_gt540.mk
  • BoardConfig.mk- 这是全部内容,这是设置编译器条件标志、分区布局、引导地址、内存磁盘大小等的地方。

Lets peek into each of those to give a glance as to where it all fits in.

让我们看一看其中的每一个,看看它们的位置。

Android.mk:

安卓.mk:

ifeq ($(TARGET_BOOTLOADER_BOARD_NAME),xxxxx)
    include $(call all-named-subdir-makefiles, recovery libsensors liblights libcamera ....)
endif

This is how the build will use that to build recovery, sensors, lights and camera (of course there will be more), its saying 'Yo Builder, go into each of the directories specified, and build the respective sources plskthxbai'

这就是构建将如何使用它来构建恢复、传感器、灯光和相机(当然会有更多),它说' Yo Builder,进入指定的每个目录,并构建各自的源 plskthxbai'

AndroidBoard.mk:

AndroidBoard.mk:

LOCAL_PATH := device/lg/gt540/

#
# Boot files
#
TARGET_PREBUILT_KERNEL := $(LOCAL_PATH)/kernel

file := $(INSTALLED_KERNEL_TARGET)
ALL_PREBUILT += $(file)
$(file): $(TARGET_PREBUILT_KERNEL) | $(ACP)
    $(transform-prebuilt-to-target)

Now this, is telling the build system, to be able to drop this kernel into the out/target/product/lg/gt540(notice the correlation with the device tree directory?)

现在,这是告诉构建系统,能够将此内核放入out/target/product/lg/gt540(注意与设备树目录的相关性?)

AndroidProducts.mk:

AndroidProducts.mk:

PRODUCT_MAKEFILES := \
    $(LOCAL_DIR)/device_gt540.mk 

Its telling the build as in 'Yo Builder, read that device make file please and process it upon completion of build.'

它在' Yo Builder 中告诉构建,请阅读该设备制作文件并在构建完成后对其进行处理。'

*device_xxxxx.mk: (for this example, device_gt540.mk) *

* device_xxxxx.mk:(对于这个例子,device_gt540.mk)*

PRODUCT_NAME := lg_gt540
PRODUCT_DEVICE := gt540
PRODUCT_MODEL := LG GT 540

PRODUCT_COPY_FILES += \
    ... specific ...

PRODUCT_PROPERTY_OVERRIDES := \
    ro.com.android.dateformat=dd-MM-yyyy \
     ... more stuff ...

This is where all the specifics for the device such as drivers, proprietary libraries, supporting scripts specifically for the device, gets copied over to out/target/product/lg/gt540/system/in this case. Notice how the overrides for the properties, these end up in the build.propfound in the root of the /systemof the Android ROM.

在这种情况下,设备的所有细节(例如驱动程序、专有库、专门用于设备的支持脚本)都被复制到此处out/target/product/lg/gt540/system/。请注意属性的覆盖如何,这些最终会在Android ROMbuild.prop的根目录中找到/system

BoardConfig.mk:

BoardConfig.mk:

LOCAL_PATH:= $(call my-dir)

TARGET_NO_BOOTLOADER := true
TARGET_PREBUILT_KERNEL := device/lg/gt540/kernel
TARGET_PREBUILT_RECOVERY_KERNEL := device/lg/gt540/recovery_kernel

# This will vary from device!
TARGET_BOARD_PLATFORM := msm7k
TARGET_ARCH_VARIANT := armv6-vfp
TARGET_CPU_ABI := armeabi
TARGET_CPU_ABI := armeabi-v6l
TARGET_CPU_ABI2 := armeabi

# OpenGL drivers config file path
BOARD_EGL_CFG := device/lg/gt540/egl.cfg

# Dependant, not to be taken literally!
BOARD_GLOBAL_CFLAGS += -DHAVE_FM_RADIO

# Dependant, not to be taken literally!
BOARD_KERNEL_BASE := 0x02600000

# this will be device specific, and by doing cat /proc/mtd will give you the correct sizes
BOARD_BOOTIMAGE_PARTITION_SIZE     := 0x00480000
BOARD_RECOVERYIMAGE_PARTITION_SIZE := 0x00480000
BOARD_SYSTEMIMAGE_PARTITION_SIZE   := 0x0cf80000
BOARD_USERDATAIMAGE_PARTITION_SIZE := 0x0d020000
BOARD_FLASH_BLOCK_SIZE := 131072

That is an excerpt, notice how we specify kernel's base address, this is how the boot.imggets generated after compilation is done and yet again, gets dropped into out/target/product/lg/gt540/boot.img. Also, more importantly, we're telling the build system to use the target platform for cross-compiling the sources (*TARGET_BOARD_PLATFORM*/*TARGET_CPU_ABI*) There will be more information in there such as conditional flags to pass to the compiler, for an example. we specified the directive HAVE_FM_RADIOto tell it, when it comes to handling the source for the FM radio system, to conditionally compile parts of the source. Again, this is hardware specific and mileage will vary, also this applies to the address for boot. In a nutshell, this is saying 'Yo Builder, read the damn variables and remember them and apply them when cross-compiling those source files!'

这是摘录,注意我们如何指定内核的基地址,这是boot.img编译完成后生成的获取方式,然后再次放入out/target/product/lg/gt540/boot.img. 此外,更重要的是,我们告诉构建系统使用目标平台来交叉编译源代码 (*TARGET_BOARD_PLATFORM*/*TARGET_CPU_ABI*) 那里会有更多信息,例如传递给编译器的条件标志,例如一个例子。我们指定了指令HAVE_FM_RADIO来告诉它在处理 FM 无线电系统的源时,有条件地编译源的部分。同样,这是特定于硬件的,里程会有所不同,这也适用于引导地址。简而言之,这就是说'Yo Builder,阅读该死的变量并记住它们并在交叉编译这些源文件时应用它们!'

Now that the internals of each of those Android build make-files are shown.

现在显示了每个 Android 构建生成文件的内部结构。

Now, onto the vendor/part of it, in AOSP, simply, once again, correlation and corresponds with the device/tree, as in continuing with this example, vendor/lg/gt540/which gets picked up by the lunch. There's more make files in there but the general consensus is there's a directory called proprietarywhich contains the proprietary libs (due to close-source etc) that gets copied over. The copying over of the libraries gets specified in the file device-vendor-blobs.mk, in this case, gt540-vendor-blobs.mk.

现在,vendor/关于它的一部分,在 AOSP 中,再次简单地将相关性和对应于device/树,就像继续这个例子一样,vendor/lg/gt540/它被lunch. 那里有更多的 make 文件,但普遍的共识是有一个名为的目录proprietary,其中包含被复制的专有库(由于关闭源等)。库的复制在文件device-vendor-blobs.mk 中指定,在本例中为gt540-vendor-blobs.mk.

When the magic happens by doing the following:

当魔术发生时,请执行以下操作:

. build/envsetup.sh

This is reading in the entire entries found in each of the device/subdirectories and "remembers them", so the build system knows what type of target is used etc.

这是读取在每个device/子目录中找到的整个条目并“记住它们”,因此构建系统知道使用什么类型的目标等。

When the . lunchgets invoked, a menu appears prompting to pick the device that is required to build. Now the last and final step to do the build...

. lunch被调用时,会出现一个菜单,提示选择构建所需的设备。现在进行构建的最后一步也是最后一步......

make -j5 > buildlog.log 2>&1

I run multitailon another terminal and monitor the buildlog.logfile to check and make sure its building.

multitail在另一个终端上运行并监视buildlog.log文件以检查并确保其构建。

This last step will depend on how many cores you have (n cores + 1 as a rule) and it takes a while to build, GB build takes 40mins on my laptop running Arch Linux 64bit, ICS build takes about 2hrs 30 mins. So mileage will vary on what type of horsepower your machine has.

最后一步将取决于您拥有多少内核(通常为 n 个内核 + 1 个)并且构建需要一段时间,在我的运行 Arch Linux 64 位的笔记本电脑上构建 GB 需要 40 分钟,ICS 构建需要大约 2 小时 30 分钟。因此,里程会因您机器的马力类型而异。

When the build is done, a little bell goes off and at the bottom of the said log file, I see this:

构建完成后,一个小铃铛响起,在所述日志文件的底部,我看到:

Combining NOTICE files: out/target/product/xxxxx/obj/NOTICE.html
Target system fs image: out/target/product/xxxxx/obj/PACKAGING/systemimage_intermediates/system.img
Install system fs image: out/target/product/xxxxx/system.img
out/target/product/xxxx/system.img+ total size is 108776448

As matter of interest JBQ (Jean Baptiste Queru - the 'boss' for managing/distributing the source from Google), his build step is this...

作为 JBQ(Jean Baptiste Queru - 管理/分发 Google 源代码的“老板”)感兴趣的问题,他的构建步骤是这样的......

make -j32 

Yup! 32 cores! That..... is pretty powerful.

是的!32核!那个……太强大了。

回答by RomanHotsiy

There is some information here: http://elinux.org/Android_Device

这里有一些信息:http: //elinux.org/Android_Device

回答by Abhay

An excellent resource for anyone building Android for a device is here: http://com.odroid.com/sigong/nf_file_board/nfile_board_view.php?bid=98

对于为设备构建 Android 的任何人来说,这里都有一个很好的资源:http: //com.odroid.com/sigong/nf_file_board/nfile_board_view.php?bid=98

(A Practical Real-World Approach To Android Platform Development In ODROID)

(在 ODROID 中开发 Android 平台的实用方法)

Though some of the stuff in there is particular to the ODROID board, it still offers great insight into the inner workings of Android and the necessary customization for a new board.

尽管其中的一些内容是 ODROID 板特有的,但它仍然提供了对 Android 内部工作原理和新板的必要定制的深入了解。

回答by Justin Buser

If you're looking to get into the hardware side of things probably the single most informative resource I've found has been:

如果你想进入硬件方面,我发现的最有信息量的资源可能是:

http://source.android.com/compatibility/overview.html

http://source.android.com/compatibility/overview.html

Read through the documentation they wrote for manufacturers looking to build android devices, it's the most thorough/complete reference you will find.

通读他们为希望构建 android 设备的制造商编写的文档,这是您将找到的最全面/最完整的参考。