mirror of
https://git.yoctoproject.org/poky
synced 2026-02-05 16:28:43 +01:00
dev-manual, kernel-dev, sdk-manual: Moved patching kernel section
Moved the "Patching the Kernel" section, which was in the dev-manual to the kernel-dev manual. During the move, renamed the section to "Using devtool to Patch the Kernel". This move bothered a lot of links so I had to fix them in various manuals. (From yocto-docs rev: a000be1eddf33e4d7de8f350e076d48e27ca4b98) Signed-off-by: Scott Rifenbark <srifenbark@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
2c0c962dd9
commit
a99c2c5581
@@ -75,9 +75,8 @@
|
||||
See the "<link linkend='creating-and-preparing-a-layer'>Creating and Preparing a Layer</link>"
|
||||
section for some general resources.
|
||||
You can also see the
|
||||
"<ulink url='&YOCTO_DOCS_DEV_URL;#set-up-your-layer-for-the-build'>Set Up Your Layer for the Build</ulink>" section
|
||||
of the Yocto Project Development Manual for a detailed
|
||||
example.
|
||||
"<link linkend='set-up-your-layer-for-the-build'>Set Up Your Layer for the Build</link>"
|
||||
section for a detailed example.
|
||||
</para>
|
||||
|
||||
<section id='creating-the-append-file'>
|
||||
@@ -295,9 +294,10 @@
|
||||
</para>
|
||||
|
||||
<para>
|
||||
For a detailed example showing how to patch the kernel, see the
|
||||
"<ulink url='&YOCTO_DOCS_DEV_URL;#patching-the-kernel'>Patching the Kernel</ulink>"
|
||||
section in the Yocto Project Development Manual.
|
||||
For a detailed example showing how to patch the kernel using
|
||||
<filename>devtool</filename>, see the
|
||||
"<link linkend='using-devtool-to-patch-the-kernel'>Using <filename>devtool</filename> to Patch the Kernel</link>"
|
||||
section.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
@@ -449,6 +449,354 @@
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section id="using-devtool-to-patch-the-kernel">
|
||||
<title>Using <filename>devtool</filename> to Patch the Kernel</title>
|
||||
|
||||
<para>
|
||||
Patching the kernel involves changing or adding configurations to an existing kernel,
|
||||
changing or adding recipes to the kernel that are needed to support specific hardware features,
|
||||
or even altering the source code itself.
|
||||
<note>
|
||||
You can use the <filename>yocto-kernel</filename> script
|
||||
found in the <ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
|
||||
under <filename>scripts</filename> to manage kernel patches and configuration.
|
||||
See the "<ulink url='&YOCTO_DOCS_BSP_URL;#managing-kernel-patches-and-config-items-with-yocto-kernel'>Managing kernel Patches and Config Items with yocto-kernel</ulink>"
|
||||
section in the Yocto Project Board Support Packages (BSP) Developer's Guide for
|
||||
more information.</note>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
This example creates a simple patch by adding some QEMU emulator console
|
||||
output at boot time through <filename>printk</filename> statements in the kernel's
|
||||
<filename>calibrate.c</filename> source code file.
|
||||
Applying the patch and booting the modified image causes the added
|
||||
messages to appear on the emulator's console.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The example assumes a clean build exists for the <filename>qemux86</filename>
|
||||
machine in a
|
||||
<ulink url='&YOCTO_DOCS_REF_URL;#source-directory'>Source Directory</ulink>
|
||||
named <filename>poky</filename>.
|
||||
Furthermore, the
|
||||
<ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
|
||||
is <filename>build</filename> and is located in
|
||||
<filename>poky</filename> and the kernel is based on the
|
||||
Linux 3.4 kernel.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Also, for more information on patching the kernel, see the
|
||||
"<link linkend='applying-patches'>Applying Patches</link>"
|
||||
section.
|
||||
</para>
|
||||
|
||||
<section id='create-a-layer-for-your-changes'>
|
||||
<title>Create a Layer for your Changes</title>
|
||||
|
||||
<para>
|
||||
The first step is to create a layer so you can isolate your
|
||||
changes.
|
||||
Rather than use the <filename>yocto-layer</filename> script
|
||||
to create the layer, this example steps through the process
|
||||
by hand.
|
||||
If you want information on the script that creates a general
|
||||
layer, see the
|
||||
"<ulink url='&YOCTO_DOCS_DEV_URL;#creating-a-general-layer-using-the-yocto-layer-script'>Creating a General Layer Using the yocto-layer Script</ulink>"
|
||||
section in the Yocto Project Development Manual.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
These two commands create a directory you can use for your
|
||||
layer:
|
||||
<literallayout class='monospaced'>
|
||||
$ cd ~/poky
|
||||
$ mkdir meta-mylayer
|
||||
</literallayout>
|
||||
Creating a directory that follows the Yocto Project layer naming
|
||||
conventions sets up the layer for your changes.
|
||||
The layer is where you place your configuration files, append
|
||||
files, and patch files.
|
||||
To learn more about creating a layer and filling it with the
|
||||
files you need, see the
|
||||
"<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>"
|
||||
section in the Yocto Project Development Manual.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id='finding-the-kernel-source-code'>
|
||||
<title>Finding the Kernel Source Code</title>
|
||||
|
||||
<para>
|
||||
Each time you build a kernel image, the kernel source code
|
||||
is fetched and unpacked into the following directory:
|
||||
<literallayout class='monospaced'>
|
||||
${S}/linux
|
||||
</literallayout>
|
||||
See the "<ulink url='&YOCTO_DOCS_DEV_URL;#finding-the-temporary-source-code'>Finding Temporary Source Code</ulink>"
|
||||
section in the Yocto Project Development Manual and the
|
||||
<ulink url='&YOCTO_DOCS_REF_URL;#var-S'><filename>S</filename></ulink>
|
||||
variable for more information about where source is kept
|
||||
during a build.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
For this example, we are going to patch the
|
||||
<filename>init/calibrate.c</filename> file
|
||||
by adding some simple console <filename>printk</filename> statements that we can
|
||||
see when we boot the image using QEMU.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id='creating-the-patch'>
|
||||
<title>Creating the Patch</title>
|
||||
|
||||
<para>
|
||||
Two methods exist by which you can create the patch:
|
||||
<ulink url='&YOCTO_DOCS_SDK_URL;#using-devtool-in-your-sdk-workflow'><filename>devtool</filename></ulink>
|
||||
and
|
||||
<ulink url='&YOCTO_DOCS_DEV_URL;#using-a-quilt-workflow'>Quilt</ulink>.
|
||||
For kernel patches, the Git workflow is more appropriate.
|
||||
This section assumes the Git workflow and shows the steps
|
||||
specific to this example.
|
||||
<orderedlist>
|
||||
<listitem><para>
|
||||
<emphasis>Change the working directory</emphasis>:
|
||||
Change to where the kernel source code is before making
|
||||
your edits to the <filename>calibrate.c</filename> file:
|
||||
<literallayout class='monospaced'>
|
||||
$ cd ~/poky/build/tmp/work/qemux86-poky-linux/linux-yocto-${PV}-${PR}/linux
|
||||
</literallayout>
|
||||
Because you are working in an established Git repository,
|
||||
you must be in this directory in order to commit your changes
|
||||
and create the patch file.
|
||||
<note>The <ulink url='&YOCTO_DOCS_REF_URL;#var-PV'><filename>PV</filename></ulink> and
|
||||
<ulink url='&YOCTO_DOCS_REF_URL;#var-PR'><filename>PR</filename></ulink> variables
|
||||
represent the version and revision for the
|
||||
<filename>linux-yocto</filename> recipe.
|
||||
The <filename>PV</filename> variable includes the Git meta and machine
|
||||
hashes, which make the directory name longer than you might
|
||||
expect.
|
||||
</note></para></listitem>
|
||||
<listitem><para>
|
||||
<emphasis>Edit the source file</emphasis>:
|
||||
Edit the <filename>init/calibrate.c</filename> file to have the
|
||||
following changes:
|
||||
<literallayout class='monospaced'>
|
||||
void calibrate_delay(void)
|
||||
{
|
||||
unsigned long lpj;
|
||||
static bool printed;
|
||||
int this_cpu = smp_processor_id();
|
||||
|
||||
printk("*************************************\n");
|
||||
printk("* *\n");
|
||||
printk("* HELLO YOCTO KERNEL *\n");
|
||||
printk("* *\n");
|
||||
printk("*************************************\n");
|
||||
|
||||
if (per_cpu(cpu_loops_per_jiffy, this_cpu)) {
|
||||
.
|
||||
.
|
||||
.
|
||||
</literallayout></para></listitem>
|
||||
<listitem><para><emphasis>Stage and commit your changes</emphasis>:
|
||||
These Git commands display the modified file, stage it, and then
|
||||
commit the file:
|
||||
<literallayout class='monospaced'>
|
||||
$ git status
|
||||
$ git add init/calibrate.c
|
||||
$ git commit -m "calibrate: Add printk example"
|
||||
</literallayout></para></listitem>
|
||||
<listitem><para><emphasis>Generate the patch file</emphasis>:
|
||||
This Git command creates the a patch file named
|
||||
<filename>0001-calibrate-Add-printk-example.patch</filename>
|
||||
in the current directory.
|
||||
<literallayout class='monospaced'>
|
||||
$ git format-patch -1
|
||||
</literallayout>
|
||||
</para></listitem>
|
||||
</orderedlist>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id='set-up-your-layer-for-the-build'>
|
||||
<title>Set Up Your Layer for the Build</title>
|
||||
|
||||
<para>These steps get your layer set up for the build:
|
||||
<orderedlist>
|
||||
<listitem><para><emphasis>Create additional structure</emphasis>:
|
||||
Create the additional layer structure:
|
||||
<literallayout class='monospaced'>
|
||||
$ cd ~/poky/meta-mylayer
|
||||
$ mkdir conf
|
||||
$ mkdir recipes-kernel
|
||||
$ mkdir recipes-kernel/linux
|
||||
$ mkdir recipes-kernel/linux/linux-yocto
|
||||
</literallayout>
|
||||
The <filename>conf</filename> directory holds your configuration files, while the
|
||||
<filename>recipes-kernel</filename> directory holds your append file and
|
||||
your patch file.</para></listitem>
|
||||
<listitem><para><emphasis>Create the layer configuration file</emphasis>:
|
||||
Move to the <filename>meta-mylayer/conf</filename> directory and create
|
||||
the <filename>layer.conf</filename> file as follows:
|
||||
<literallayout class='monospaced'>
|
||||
# We have a conf and classes directory, add to BBPATH
|
||||
BBPATH .= ":${LAYERDIR}"
|
||||
|
||||
# We have recipes-* directories, add to BBFILES
|
||||
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
|
||||
${LAYERDIR}/recipes-*/*/*.bbappend"
|
||||
|
||||
BBFILE_COLLECTIONS += "mylayer"
|
||||
BBFILE_PATTERN_mylayer = "^${LAYERDIR}/"
|
||||
BBFILE_PRIORITY_mylayer = "5"
|
||||
</literallayout>
|
||||
Notice <filename>mylayer</filename> as part of the last three
|
||||
statements.</para></listitem>
|
||||
<listitem><para><emphasis>Create the kernel recipe append file</emphasis>:
|
||||
Move to the <filename>meta-mylayer/recipes-kernel/linux</filename> directory and create
|
||||
the <filename>linux-yocto_3.4.bbappend</filename> file as follows:
|
||||
<literallayout class='monospaced'>
|
||||
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
|
||||
|
||||
SRC_URI += "file://0001-calibrate-Add-printk-example.patch"
|
||||
</literallayout>
|
||||
The <ulink url='&YOCTO_DOCS_REF_URL;#var-FILESEXTRAPATHS'><filename>FILESEXTRAPATHS</filename></ulink>
|
||||
and <ulink url='&YOCTO_DOCS_REF_URL;#var-SRC_URI'><filename>SRC_URI</filename></ulink>
|
||||
statements enable the OpenEmbedded build system to find the patch file.
|
||||
For more information on using append files, see the
|
||||
"<ulink url='&YOCTO_DOCS_DEV_URL;#using-bbappend-files'>Using .bbappend Files in Your Layer</ulink>"
|
||||
section in the Yocto Project Development Manual.
|
||||
</para></listitem>
|
||||
<listitem><para>
|
||||
<emphasis>Put the patch file in your layer</emphasis>:
|
||||
Move the <filename>0001-calibrate-Add-printk-example.patch</filename> file to
|
||||
the <filename>meta-mylayer/recipes-kernel/linux/linux-yocto</filename>
|
||||
directory.</para></listitem>
|
||||
</orderedlist>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id='set-up-for-the-build'>
|
||||
<title>Set Up for the Build</title>
|
||||
|
||||
<para>
|
||||
Do the following to make sure the build parameters are set up for the example.
|
||||
Once you set up these build parameters, they do not have to change unless you
|
||||
change the target architecture of the machine you are building:
|
||||
<itemizedlist>
|
||||
<listitem><para><emphasis>Build for the correct target architecture:</emphasis> Your
|
||||
selected <ulink url='&YOCTO_DOCS_REF_URL;#var-MACHINE'><filename>MACHINE</filename></ulink>
|
||||
definition within the <filename>local.conf</filename> file in the
|
||||
<ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>
|
||||
specifies the target architecture used when building the Linux kernel.
|
||||
By default, <filename>MACHINE</filename> is set to
|
||||
<filename>qemux86</filename>, which specifies a 32-bit
|
||||
<trademark class='registered'>Intel</trademark> Architecture
|
||||
target machine suitable for the QEMU emulator.</para></listitem>
|
||||
<listitem><para><emphasis>Identify your <filename>meta-mylayer</filename>
|
||||
layer:</emphasis> The
|
||||
<ulink url='&YOCTO_DOCS_REF_URL;#var-BBLAYERS'><filename>BBLAYERS</filename></ulink>
|
||||
variable in the
|
||||
<filename>bblayers.conf</filename> file found in the
|
||||
<filename>poky/build/conf</filename> directory needs to have the path to your local
|
||||
<filename>meta-mylayer</filename> layer.
|
||||
By default, the <filename>BBLAYERS</filename> variable contains paths to
|
||||
<filename>meta</filename>, <filename>meta-poky</filename>, and
|
||||
<filename>meta-yocto-bsp</filename> in the
|
||||
<filename>poky</filename> Git repository.
|
||||
Add the path to your <filename>meta-mylayer</filename> location:
|
||||
<literallayout class='monospaced'>
|
||||
BBLAYERS ?= " \
|
||||
$HOME/poky/meta \
|
||||
$HOME/poky/meta-poky \
|
||||
$HOME/poky/meta-yocto-bsp \
|
||||
$HOME/poky/meta-mylayer \
|
||||
"
|
||||
</literallayout></para></listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id='build-the-modified-qemu-kernel-image'>
|
||||
<title>Build the Modified QEMU Kernel Image</title>
|
||||
|
||||
<para>
|
||||
The following steps build your modified kernel image:
|
||||
<orderedlist>
|
||||
<listitem><para><emphasis>Be sure your build environment is initialized</emphasis>:
|
||||
Your environment should be set up since you previously sourced
|
||||
the
|
||||
<ulink url='&YOCTO_DOCS_REF_URL;#structure-core-script'><filename>&OE_INIT_FILE;</filename></ulink>
|
||||
script.
|
||||
If it is not, source the script again from <filename>poky</filename>.
|
||||
<literallayout class='monospaced'>
|
||||
$ cd ~/poky
|
||||
$ source &OE_INIT_FILE;
|
||||
</literallayout>
|
||||
</para></listitem>
|
||||
<listitem><para>
|
||||
<emphasis>Clean up</emphasis>:
|
||||
Be sure to clean the shared state out by using BitBake
|
||||
to run from within the Build Directory the
|
||||
<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>do_cleansstate</filename></ulink>
|
||||
task as follows:
|
||||
<literallayout class='monospaced'>
|
||||
$ bitbake -c cleansstate linux-yocto
|
||||
</literallayout></para>
|
||||
<para>
|
||||
<note>
|
||||
Never remove any files by hand from the
|
||||
<filename>tmp/deploy</filename>
|
||||
directory inside the
|
||||
<ulink url='&YOCTO_DOCS_REF_URL;#build-directory'>Build Directory</ulink>.
|
||||
Always use the various BitBake clean tasks to
|
||||
clear out previous build artifacts.
|
||||
For information on the clean tasks, see the
|
||||
"<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-clean'><filename>do_clean</filename></ulink>",
|
||||
"<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleanall'><filename>do_cleanall</filename></ulink>",
|
||||
and
|
||||
"<ulink url='&YOCTO_DOCS_REF_URL;#ref-tasks-cleansstate'><filename>do_cleansstate</filename></ulink>"
|
||||
sections all in the Yocto Project Reference
|
||||
Manual.
|
||||
</note>
|
||||
</para></listitem>
|
||||
<listitem><para>
|
||||
<emphasis>Build the image</emphasis>:
|
||||
Next, build the kernel image using this command:
|
||||
<literallayout class='monospaced'>
|
||||
$ bitbake -k linux-yocto
|
||||
</literallayout></para></listitem>
|
||||
</orderedlist>
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id='boot-the-image-and-verify-your-changes'>
|
||||
<title>Boot the Image and Verify Your Changes</title>
|
||||
|
||||
<para>
|
||||
These steps boot the image and allow you to see the changes
|
||||
<orderedlist>
|
||||
<listitem><para><emphasis>Boot the image</emphasis>:
|
||||
Boot the modified image in the QEMU emulator
|
||||
using this command:
|
||||
<literallayout class='monospaced'>
|
||||
$ runqemu qemux86
|
||||
</literallayout></para></listitem>
|
||||
<listitem><para><emphasis>Verify the changes</emphasis>:
|
||||
Log into the machine using <filename>root</filename> with no password and then
|
||||
use the following shell command to scroll through the console's boot output.
|
||||
<literallayout class='monospaced'>
|
||||
# dmesg | less
|
||||
</literallayout>
|
||||
You should see the results of your <filename>printk</filename> statements
|
||||
as part of the output.</para></listitem>
|
||||
</orderedlist>
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section id='using-an-iterative-development-process'>
|
||||
<title>Using an Iterative Development Process</title>
|
||||
|
||||
@@ -747,8 +1095,8 @@
|
||||
"<link linkend='applying-patches'>Applying Patches</link>"
|
||||
section.
|
||||
If you are not familiar with generating patches, refer to the
|
||||
"<ulink url='&YOCTO_DOCS_DEV_URL;#creating-the-patch'>Creating the Patch</ulink>"
|
||||
section in the Yocto Project Development Manual.
|
||||
"<link linkend='creating-the-patch'>Creating the Patch</link>"
|
||||
section.
|
||||
</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user