From 04c77b9fb532e43fbc936c624f0c65124dee4ceb Mon Sep 17 00:00:00 2001 From: Scott Rifenbark Date: Wed, 10 Aug 2011 14:21:23 -0700 Subject: documentation/dev-manual/dev-manual-kernel-appendix.xml: re-write I performed a major re-write of this section that touched all aspects of it. This was necessary due to the fact I could not get the example running because of not understanding the repo location and branch needs to set it up. (From yocto-docs rev: 160e66d0c8ddf11584c53306def916a45a05f62b) Signed-off-by: Scott Rifenbark Signed-off-by: Richard Purdie --- .../dev-manual/dev-manual-kernel-appendix.xml | 505 +++++++++++++++------ 1 file changed, 362 insertions(+), 143 deletions(-) (limited to 'documentation') diff --git a/documentation/dev-manual/dev-manual-kernel-appendix.xml b/documentation/dev-manual/dev-manual-kernel-appendix.xml index 5aed90f95b..ac344985bd 100644 --- a/documentation/dev-manual/dev-manual-kernel-appendix.xml +++ b/documentation/dev-manual/dev-manual-kernel-appendix.xml @@ -6,16 +6,13 @@ Kernel Modification Example - Kernel modification involves changing or adding configurations to an existing kernel, or - adding recipes to the kernel that are needed to support specific hardware features. - The process is similar to creating a Board Support Package (BSP) except that it invloves - isolating your work in a kernel layer and the use of menuconfig - to help make configuration data easily identifiable. - - - - This section presents a simple example that shows how to modify the kernel. - The example uses a three-step approach that is convenient for making kernel modifications. + Kernel modification involves changing or adding configurations to an existing kernel, + adding recipes to the kernel that are needed to support specific hardware features, or even + changing the source code itself. + This section presents some simple examples that modify the kernel source code, + change the kernel configuration, and add a kernel source recipe. + -
- Modifying a Kernel Example +
+ Modifying the Kernel Source Code - The example changes kernel configurations to support the VFAT filesystem and - allow the user to print out a simple text file from the mounted VFAT filesystem. - The filesystem used will be an image filesystem rather than a filesystem on some - external drive such as a USB stick or external drive. - The example uses the linux-yocto-2.6.37 kernel. - + This example adds some simple QEMU emulator console output at boot time by + adding printk statements to the kernel's + calibrate.c source code file. + Booting the modified image causes the added messages to appear on the emulator's + console. + For a general flow of the example, see @@ -44,11 +41,72 @@ earlier in this manual. -
- Setting Up Yocto Project +
+ Understanding the Files You Need + + + Before you modify the kernel you need to know what Git repositories and file + structures you need. + Briefly, you need the following: + + A local Yocto Project files Git repository + The poky-extras Git repository placed + within the local Yocto Project files Git repository + A bare clone of the Linux Yocto kernel that you want to modify + + A copy of that bare clone in which you make your source + modifcations + + + + + The following illustration summarizes what you need: + + + + + + + + Here is a brief description of the four areas: + + Local Yocto Project Files: This Git + repository contains all the metadata that supports building images in the + Yocto Project build environment. + Note that the Git repository in our example also contains the + poky-extras Git repository, which contains the + kernel metadata specific to building a kernel image. + The Local Yocto Project files Git repository also contains the build directory + and configuration files that let you control the build. + poky-extras: This + Git repository contains the meta-kernel-dev layer, + which is where you make changes that append to the kernel build recipes. + You edit .bbappend files to point the build to your + local kernel source files and to define the kernel being built. + This Git repository is a gathering place for extensions to the Linux Yocto + (or really any) kernel recipes that faciliate the creation and development + of kernel features, BSPs or configuration + Bare Clone of the Linux Yocto Git Repository: + This bare Git repository tracks the upstream Git repository of the Linux Yocto kernel + you are changing. + As mentioned, when you build the Linux Yocto kernel image you point to this repository + so that the build process can locate the locally changed source files. + When you modify the kernel image you must work with a bare clone. + + Copy of the Linux Yocto Kernel Bare Clone: + This Git repository contains the actual source files that you modify. + Any changes you make to files in this location need to ultimately be pushed + to the bare clone using the git push command. + + + +
+ +
+ Setting Up the Local Yocto Project Files Git Repository - You need to have the Yocto Project files available on your host system. You can get files through tarball extraction or by cloning the poky Git repository. See the bulleted item @@ -58,183 +116,344 @@ - Once you have the local poky Git repository set up, + This example assumes the name of the Git repository is poky. + Once you have the repository set up, you have many development branches from which you can work. From inside the repository you can see the branch names and the tag names used in the Git repository using either of the following two commands: + $ cd poky $ git branch -a $ git tag -l - For this example we are going to use the Yocto Project 1.1 Release, - which maps to the 1.1 branch in the repository. - These commands create a local branch named 1.1 + For this example, we are going to use the Yocto Project 1.1_M3 Release, + which maps to the 1.1_M3 branch in the repository. + These commands create a local branch named 1.1_M3 that tracks the remote branch of the same name. - $ cd poky - $ git checkout -b 1.1 origin/1.1 - Switched to a new branch '1.1' + $ git checkout -b 1.1_M3 origin/1.1_M3 + Branch 1.1_M3 set up to track remote branch 1.1_M3 from origin. + Switched to a new branch '1.1_M3'
-
- Getting a Local Copy of the Kernel Files +
+ Setting Up the <filename>poky-extras</filename> Git Repository - You need to have a local copy of the Linux Yocto kernel files on your system. - Yocto Project files available on your host system. - You must create a local Git repository of these files. + This example places the poky-extras Git repository inside + of poky. See the bulleted item - Linux Yocto Kernel in + The + poky-extras Git Repository in Getting Setup earlier in this manual for information on how to get these files.
-
- Create a Layer for Your Kernel Work +
+ Setting Up the Bare Clone and its Copy - It is always good to isolate your work using your own layer. - Doing so allows you to experiment and easily start over should things go wrong. - This example uses a layer named meta-vfatsupport. + This example modifies the linux-yocto-2.6.37 kernel. + Thus, you need to create a bare clone of that kernel and then make a copy of the + bare clone. + See the bulleted item + Linux Yocto Kernel in + Getting Setup earlier in this manual + for information on how to do that. - When you set up a layer for kernel work you should follow general layout - guidelines layers. - For example, if you were creating a BSP you would want to follow the layout - described in the - - Example Filesystem Layout section of the Board Support Package (BSP) Development - Guide. - For kernel layers, you can start with a skeleton layer - named meta-skeleton found in your local - Yocto Project file directory structure (the poky Git - repository or the directory structure resulting from unpacking the Yocto Project - release tarball). + The bare clone exists simply as the receiving end of git push + commands after you make edits and commits inside the copy of the clone. + The copy (linux-yocto-2.6.37 in this example) has to have + a local branch created and checked out for your work. + The following commands create and checkout the branch: + + $ cd ~/linux-yocto-2.6.37 + $ git checkout -b common-pc-base origin/yocto/standard/common-pc/base + Branch common-pc-base set up to track remote branch yocto/standard/common-pc/base from origin. + Switched to a new branch 'common-pc-base' + +
- - To create your kernel layer simply copy the meta-skeleton - layer and rename it meta-vfatsupport. - The following command sets up the layer inside the poky - Git repository: +
+ Building and Booting the Default QEMU Kernel Image + + + In this example before we make changes to the kernel image we will build it first + and see how it boots inside the QEMU emulator. + + Because a full build can take hours, you should check two variables in the + build directory that is created after you source the + oe-init-build-env script. + You can find these variables + BB_NUMBER_THREADS and PARALLEL_MAKE + in the build/conf directory in the + local.conf configuration file. + By default, these variables are commented out. + If your host development system supports multi-core and multi-thread capabilities + you can uncomment these statements and set the variables to significantly shorten + the full build time. + As a guideline, set BB_NUMBER_THREADS to twice the number + of cores your machine supports and set PARALLEL_MAKE to one and + a half times the number of cores your machine supports. + + These commands build the default qemux86 image: $ cd ~/poky - $ cp -r meta-skeleton meta-vfatsupport + $ source oe-init-build-env + + ### Shell environment set up for builds. ### + + You can now run 'bitbake <target>' + + Common targets are: + core-image-minimal + core-image-sato + meta-toolchain + meta-toolchain-sdk + adt-installer + meta-ide-support + + You can also run generated qemu images with a command like 'runqemu qemux86' + + $ bitbake -k core-image-minimal - In the new layer you will find areas for configuration changes - (conf) and recipe changes (recipes-skeleton). + The source command sets up the build environment, while the + following bitbake command starts the build. - - You need to modify the structure a bit for your work. - These commands add some further structure and names that the Yocto Project build - environment expect: + + After the build completes, you can start the QEMU emulator using the resulting image + qemux86 as follows: - $ mkdir meta-vfatsupport/images - $ mkdir meta-vfatsupport/recipes-bsp - $ mv meta-vfatsupport/recipes-skeleton meta-vfatsupport/recipes-kernel - $ mkdir meta-vfatsupport/recipes-kernel/linux - $ mkdir meta-vfatsupport/recipes-kernel/linux/linux-yocto + $ runqemu qemux86 - The last piece you need for your layer is a - linux-yocto_git.bbappend file inside - meta-vfatsupport/recipes-kernel/linux. - This file needs the following content to make the build process aware of the - new layer's location: + As the image boots in the emulator, console messages and status appear across the + terminal window. + Because the output scrolls by quickly it is difficult to read. + To examine the output you can log into the system using the + login root with no password. + Once you are logged in, you can issue the following command to scroll through the + console output: - FILESEXTRAPATHS := "${THISDIR}/${PN}" + # dmesg | less - [WRITER'S NOTE: We need a better meta-skeleton layer - that is part of poky. - It should have a structure that includes images, - recipes-bsp, recipes-kernel, and - so forth. - For now this step of the example is brute-forcing the structure with shell - commands to set up the minimum structure and include the - .bbappend file. + Take note of the output as you will want to look for your inserted print command output + later in the example.
-
- Be Sure the Image is Available - +
+ Changing the Source Code and Pushing it to the Bare Clone + - For the example you need an image that you can use when you run the QEMU emulator. - By default, support of VFAT filesystems will not be supported in this image. - The example will test that in a subsequent section. + The file you change in this example is named calibrate.c + and is located in the linux-yocto-2.6.37 Git repository + in init. + For this example simply insert several printk statements + at the beginning of the calibrate_delay function. + Now let's look at the changes to the source code. + Here is the unaltered code at the start of this function: + + void __cpuinit calibrate_delay(void) + { + unsigned long ticks, loopbit; + int lps_precision = LPS_PREC; + static bool printed; + + if (preset_lpj) { + . + . + . + + + + + This example uses the following five printk statements + just after defining lps_precision: + + void __cpuinit calibrate_delay(void) + { + unsigned long ticks, loopbit; + int lps_precision = LPS_PREC; + printk("*************************************\n"); + printk("* *\n"); + printk("* HELLO YOCTO KERNEL *\n"); + printk("* *\n"); + printk("*************************************\n"); + static bool printed; + + if (preset_lpj) { + . + . + . + + + + + After making and saving your changes, you need to stage them for the push. + The following Git commands stage and commit your changes: + + $ git add calibrate.c + $ git commit --signoff + + + + + Once the source code has been modified you need to use Git to push the changes to + the bare clone. + If you do not push the changes then the Yocto Project build system will not pick + the changed source files. + + + + To push the changes do the following: + + $ git push origin common-pc-base:yocto/standard/common-pc/base + + + + + For general information on how to push a change using Git, see [WRITER'S NOTE: need + the link to the submitting a change section]. + +
+ +
+ Changing Build Parameters for Your Build + + + At this point the source has been changed and pushed. + Now you need to define some variables used by the Yocto Project build system to locate your + source. + You essentially need to identify where to find the kernel recipe and the changed source code. + You also need to be sure some basic configurations are in place that identify the + type of machine you are building and to help speed up the build should your host support + multiple-core and thread capabilities. + + + + Do the following to make sure the build parameters are set up for the example. + Once you set up these build parameters they should not have to change unless you + change the target architecture of the machine you are building or you move + the bare clone, copy of the clone, or the poky-extras repository: + + Build for the Correct Target Architecture - The + local.conf in the build directory defines the build's + target architecture. + By default, + MACHINE is set to qemux86, which + specifies a 32-bit Intel Architecture target machine suitable for the + QEMU emulator. + So for this example, MACHINE is correctly configured. + + Optimize Build Time - Also in the + local.conf file are two variables that can speed your + build time if your host supports multi-core and multi-thread capabilities: + BB_NUMBER_THREADS and PARALLEL_MAKE. + If the host system has multiple cores then you can optimize build time + by setting BB_NUMBER_THREADS to twice the number of + cores and setting PARALLEL_MAKE to one and a half times the + number of cores. + Identify Your meta-kernel-dev + Layer - The BBLAYERS variable in the + bblayers.conf found in the + poky/build/conf directory needs to have the path to your local + meta-kernel-dev layer. + By default, the BBLAYERS variable contains paths to + meta and meta-yocto in the + poky Git repository. + Add the path to your meta-kernel-dev location. + Here is an example: + + BBLAYERS = " \ + /home/scottrif/poky/meta \ + /home/scottrif/poky/meta-yocto \ + /home/scottrif/poky/poky-extras/meta-kernel-dev \ + " + + Identify Your Source Files - In the + linux-yocto-2.6.37.bbappend file located in the + poky-extras/meta-kernel-dev/recipes-kernel/linux + directory you need to identify the location of the + local source code, which in this example is the bare clone named + linux-yocto-2.6.37.git. + To do this, set the KSRC_linux_yocto to point to your + local linux-yocto-2.6.37.git Git repository by adding the + following statement: + + KSRC_linux_yocto ?= /home/scottrif/linux-yocto-2.6.37.git + + Specify the Kernel Machine - Also in the + linux-yocto-2.6.37.bbappend you need to specify + the kernel machine with the following statement: + + KMACHINE_qemux86 = "yocto/standard/common-pc/base" + + + +
+ +
+ Building and Booting the Modified QEMU Kernel Image + + + Next, you need to build the modified image. + Do the following: + + Your environment should be set up since you previously sourced + the oe-init-build-env script. + If it isn't, source the script again from the poky + again. + Be sure any old images are cleaned out by running the + cleanall BitBake task as follows: + + $ bitbake -c cleanall linux-yocto + + Build the kernel image using this command: + + $ bitbake -k core-image-minimal + + - In theory, you can get an image suitable for QEMU one of two ways: - - Download a pre-built kernel image and matching ext3 - file system from the Yocto Project - Index of downloads. - See Index of Downloads earlier in the - manual for more information about this source repository. - You can also see - - Using Pre-Build Binaries and QEMU - in the Yocto Project Quick Start for information on how to find and choose - images ready to run in QEMU. - Build an image and matching ext3 - filesystem using the poky Git repository on your local - development system. - + Next, boot the modified image in the QEMU emulator using this command: + + $ runqemu qemux86 + - + - This example continues by building the image. - If you want to see more on building an image in general, see - - Building an Image in the Yocto Project Quick Start. + Log into the machine using root with no password and then + use the following shell command to scroll through the console's boot output. + + # dmesg | less + - The following steps result in a QEMU image and filesystem for - an x86 (32-bit) target machine that can run in the emulator. - - Prepare the Build Environment - Source the - script to set up the build environment: - - $ cd ~/poky - $ source oe-init-build-env - - Change Configurations to Speed Up the Build - If your - development system supports multiple cores you can remove the comments in the - BB_NUMBER_THREADS and PARALLEL_MAKE - statements and adjust the arguments to optimize the build time. - For example, a development host that has four cores could use - 8 and j 6 to get the best use of - your host's multi-core and thread capabilities. - Start the Build - Use BitBake to start the - build: - - $ bitbake -k core-image-sato - - Depending on your host system's load and capabilities the build takes some time. - Once it completes you will have the kernel image needed to continue the example. - The image and filesystem reside in the build directory at - poky/build/tmp/deploy/images. - - + You should see the results of your printk statements + as part of the output.
+
-
+ -