Integrated kernel building

from: http://wiki.cyanogenmod.com/wiki/Integrated_kernel_building

Contents

[hide]

Inlining the kernel (and modules) build into the ROM

Why does CM want the kernel built together with Android?

Before CM9, we depended on having prebuilt kernels in every device repository. These were compiled separately from the framework and required the device maintainer to manually update the kernel image and modules any time a change is done. In addition, kernels were not using a consistent naming scheme, many were not managed by the CyanogenMod Gerrit, and were often compiled using compilers other than the one found in the Android toolchain. This has lead to major inconsistencies, and difficulty for others to match the maintainers build.

Solution overview

As of CyanogenMod 9, we are deprecating the usage of prebuilt kernel images. The build system has been modified to ask for (and build) the kernel source.

Deploying the kernel source at the proper location

The minimal requirement is that the kernel's source tree for that device be present at kernel/vendor-name/device-name.

Officially supported devices

For devices which are part of mainline CyanogenMod and have their kernels in CM's github, this can be accomplished by usage of CyanogenMod's roomservice feature. Create a cm.dependencies file (if it doesn't exist yet) at the root of your device tree, with the following syntax:



[
 {
   "repository": "name-of-repository-in-the-CyanogenMod-github",
   "target_path": "kernel/<vendorname>/<devicename>",
   "branch": "name-of-branch"
 }
]


This will take care of downloading the source automatically into the right location.

Work-in-progress, unofficial, or otherwise non-integrated devices

For devices which don't have their kernel source at the CM github, usage of local_manifest.xml is recommended in order to deploy the source at the right location, and keeping it synchronized.

Devices using shared kernel repositories

If your device shares a kernel with others, the default kernel/devicename path will lead to unnecessary duplication of source trees, so usage of the TARGET_KERNEL_SOURCE configuration variable is advised. All devices sharing that source should have the following line in their BoardConfig.mk files:

TARGET_KERNEL_SOURCE := kernel/vendor-name/unique-shared-source-name

Configuring the device to build the kernel

After the source is in place, configuration of the device to build the kernel is trivial. Just add the TARGET_KERNEL_CONFIG variable to your BoardConfig.mk file, pointing to the configuration file name for your device (as present in arch/arm/configs). For example:

TARGET_KERNEL_CONFIG := cyanogenmod_mydevice_defconfig

This will trigger the full kernel build, including the modules (if present) as specified in that configuration. Any modules built will be deployed at /system/lib/modules/ in the final image

If your device requires uImage, also ensure the following is present in your 'BoardConfig.mk'

BOARD_USES_UBOOT := true

Building out-of-tree kernel modules

If your device needs modules that aren't part of the kernel source tree, those can also be built automatically. Some hardware (Texas Instruments' TIWLAN adapters, Broadcom's BCM adapters) is directly supported by CM repositories, but if that isn't your case we suggest you add your module's source to either your device repository, or an isolated path in your kernel source.

To build these modules, the TARGET_KERNEL_MODULES variable can be used, pointing to a make target that will build and install such modules. Definition of such a target is the device author's responsibility, the only restriction is that it is a normal makefile recipe. To include, for example, the TI WLAN modules, this can be used:

TIWLAN_MODULES:
       make -C hardware/ti/wlan/wl1283/platforms/os/linux/ KERNEL_DIR=$(KERNEL_OUT) ARCH="arm" CROSS_COMPILE="arm-eabi-" TNETW=1273 RANDOM_MAC=n REPORT_LOG=n
       mv hardware/ti/wlan/wl1283/platforms/os/linux/tiwlan_drv.ko $(KERNEL_MODULES_OUT)
       make -C hardware/ti/wlan/wl1283_softAP/platforms/os/linux/ KERNEL_DIR=$(KERNEL_OUT) ARCH="arm" CROSS_COMPILE="arm-eabi-" TNETW=1273 REPORT_LOG=n
       mv hardware/ti/wlan/wl1283_softAP/platforms/os/linux/tiap_drv.ko $(KERNEL_MODULES_OUT)
    
TARGET_KERNEL_MODULES := TIWLAN_MODULES

As a rule of thumb, you can just paste your current standalone build commands into a make recipe, replacing the kernel source path with the $(KERNEL_OUT) variable.

Fallback to prebuilts

If for some reason the kernel source can't be present, you can still fall back to prebuilt binaries, by defining the TARGET_PREBUILT_KERNEL variable, like this:

TARGET_PREBUILT_KERNEL := device/<vendor>/<device>/kernel

Full example

The following is the p920's configuration, which attempts to build the kernel, uses external modules, and has a prebuilt fallback:


# Try to build the kernel
TARGET_KERNEL_CONFIG := cyanogenmod_cosmo_defconfig
# Keep this as a fallback
TARGET_PREBUILT_KERNEL := device/lge/p920/kernel

KERNEL_EXTERNAL_MODULES:
	make -C hardware/ti/wlan/wl1283/platforms/os/linux/ KERNEL_DIR=$(KERNEL_OUT) ARCH="arm" CROSS_COMPILE="arm-eabi-" TNETW=1273 RANDOM_MAC=n REPORT_LOG=n
	mv hardware/ti/wlan/wl1283/platforms/os/linux/tiwlan_drv.ko $(KERNEL_MODULES_OUT)
	make -C hardware/ti/wlan/wl1283_softAP/platforms/os/linux/ KERNEL_DIR=$(KERNEL_OUT) ARCH="arm" CROSS_COMPILE="arm-eabi-" TNETW=1273 REPORT_LOG=n
	mv hardware/ti/wlan/wl1283_softAP/platforms/os/linux/tiap_drv.ko $(KERNEL_MODULES_OUT)

TARGET_KERNEL_MODULES := KERNEL_EXTERNAL_MODULES

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章