HOWTO Rebuild and Customize Your Kernel in Desktop Factory


This document discusses the different facilities within Desktop Factory which can be used to customize or otherwise modify your linux kernel, and the recommended methods of rebuilding your kernel thereafter.

Once the kernel has been built, it is often necessary to modify it to suit the needs of your particular custom hardware or project. There are a few different ways to modify your linux kernel: kernel patches, the kernel configuration file, and directly modifying source files in the kernel source tree. Once modifications are made to your kernel, there are different approaches for rebuilding it within Factory, depending on what and how the modifications are made. Below are some tips to get your kernel rebuilt once these modifications have been made.


Kernel Configuration

The most basic way to utilize a custom kernel is to point Factory to the location of your customized kernel configuration file. By default Factory's kernel configuration option points to the kernel configuration within the factory builder:


Notice the file:// in the URI and the use of $(BASE_DIR) to point to the top level factory builder directory. This file is what will be copied into the kernel working directory during Factory's configuration step for the kernel. This step, along with the kernel build step, can be forced at any time by using the 'kernel-restage' make target to set the kernel to be rebuilt, followed by 'make' to kick off the build. The value of TSWO_KERNEL_CONFIG will be re-evaluated after the 'kernel-restage' make target is run.

The kernel configuration (kernel .config) can be modified via 'make kernel-menuconfig' run from the top-level Factory directory. Note that this kernel .config (with working copy located in build_*/linux-VERSION/ directory) is the configuration file for the linux kernel itself, allowing you to toggle various support within the kernel, or specify to build kernel loadable modules, while the Factory workorder (.config file located in the top-level Factory directory) is used to define options and software selections to configure the Factory-produced BSP/SDK. To make modifications to your kernel .config through menuconfig, run the following from the top-level factory directory:

make kernel-menuconfig

This target makes sure the default configuration from TSWO_KERNEL_CONFIG has been fetched and copied into an uncompressed kernel source before invoking the Linux kernel's menuconfig target for you. If the Linux kernel's menuconfig target returns successful, the resulting .config in the kernel working directory is copied back to the src/dl/kernel/ cache location. Note that if this modified configuration is desired for future uses, it should be copied from the source download cache or from the Linux kernel's working directory into a persistent location. This location could then be used as the value for TSWO_KERNEL_CONFIG.

Modifying the kernel configuration will cause the kernel to be rebuilt when make is next invoked. The kernel can always be forced to rebuild using the 'kernel-restage' make target to set the kernel for rebuilding and is a good habit to get into when modifying your kernel .config or source code.

Kernel Source Modifications

Modifications to the kernel sources within the Factory build_*/linux-VERSION/ directory can be made in order to quickly test modifications to the kernel prior to creating local kernel patches. Upon making modifications to source files within the kernel build directory, the kernel will need to be rebuilt using these modified source files. Setting the kernel to be rebuilt can be accomplished via the 'kernel-restage' make target. As mentioned above, this will flag the kernel to be rebuilt the next time 'make' is invoked from the top-level Factory directory. This will reuse the kernel configuration as is, but rebuild the kernel with the modified source files in the build_*/linux-VERSION/ directory.

Typically, once these modifications are finalized, they can be converted into patches and used with the Local Kernel Patch facilities within Factory.

Local Kernel Patches

Factory sets a default series of patches for your Linux kernel in the Factory Workorder (.config file in the top-level Factory directory) that are applied to the stock kernel sources prior to building. This default set of patches includes any upstream patches for a given kernel, as well as target-specific patches necessary to utilize various functionality for a given target. In addition to this default series of patches provided by Timesys, there is also the ability to add Local Kernel Patches. These are user-specified patches that will be applied on top of the default set of patches. Once local patches are created, create the src/local directory for the kernel patches. In the top-level Factory directory run:

$ mkdir -p src/local/k/kernel/kernel-VERSION

Then copy your custom local patches to src/local/k/kernel/kernel-VERISON/, add those patches - space de-limited, to TSWO_kernel_LOCAL_PATCHES in your Factory .config; or, via Factory menuconfig. Then, a 'make kernel-distclean' will be required to remove the kernel source files in the build_*/ directory, as well as the source tarball and default kernel patches (local patches stored in src/local/* will not be removed). The next time 'make' is invoked from the top-level Factory directory, the kernel sources will be fetched, default patches will be applied, followed by the local kernel patches previously listed in TSWO_kernel_LOCAL_PATCHES, and the kernel will be rebuilt.

NOTE: This kernel-distclean make target is a destructive operation; any modification to source files located in the build_*/linux-VERSION directory WILL BE LOST when running 'make kernel-distclean'. Be sure to make a backup of these files if modifications are to be retained.