The steps in this procedure show you how you can patch the
kernel using the extensible SDK and devtool
.
devtool
"
section.
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.
This example creates a simple patch by adding some QEMU emulator
console output at boot time through printk
statements in the kernel's calibrate.c
source
code file.
Applying the patch and booting the modified image causes the added
messages to appear on the emulator's console.
The example is a continuation of the setup procedure found in
the
"Getting Ready to Develop Using devtool
"
Section.
Check Out the Kernel Source Files:
First you must use devtool
to checkout
the kernel source code in its workspace.
Be sure you are in the terminal set up to do work
with the extensible SDK.
Use the following devtool
command
to check out the code:
$ devtool modify linux-yocto
ERROR: Taskhash mismatch 2c793438c2d9f8c3681fd5f7bc819efa versus be3a89ce7c47178880ba7bf6293d7404 for /path/to/esdk/layers/poky/meta/recipes-kernel/linux/linux-yocto_4.10.bb.do_unpackYou can safely ignore these messages. The source code is correctly checked out.
Edit the Source Files Follow these steps to make some simple changes to the source files:
Change the working directory:
In the previous step, the output noted where you can find
the source files (e.g.
~/poky_sdk/workspace/sources/linux-yocto
).
Change to where the kernel source code is before making
your edits to the calibrate.c
file:
$ cd ~/poky_sdk/workspace/sources/linux-yocto
Edit the source file:
Edit the init/calibrate.c
file to have
the following changes:
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)) { . . .
Build the Updated Kernel Source:
To build the updated kernel source, use
devtool
:
$ devtool build linux-yocto
Create the Image With the New Kernel:
Use the devtool build-image
command
to create a new image that has the new kernel.
$ cd ~ $ devtool build-image core-image-minimal
Test the New Image: For this example, you can run the new image using QEMU to verify your changes:
Boot the image: Boot the modified image in the QEMU emulator using this command:
$ runqemu qemux86
Verify the changes:
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
You should see the results of your
printk
statements
as part of the output when you scroll down the
console window.
Stage and commit your changes:
Within your eSDK terminal, change your working directory to
where you modified the calibrate.c
file and use these Git commands to stage and commit your
changes:
$ cd ~/poky_sdk/workspace/sources/linux-yocto $ git status $ git add init/calibrate.c $ git commit -m "calibrate: Add printk example"
Export the Patches and Create an Append File:
To export your commits as patches and create a
.bbappend
file, use the following
command in the terminal used to work with the extensible
SDK.
This example uses the previously established layer named
meta-mylayer
.
$ devtool finish linux-yocto ~/meta-mylayer
Once the command finishes, the patches and the
.bbappend
file are located in the
~/meta-mylayer/recipes-kernel/linux
directory.
Build the Image With Your Modified Kernel: You can now build an image that includes your kernel patches. Execute the following command from your Build Directory in the terminal set up to run BitBake:
$ cd ~/poky/build $ bitbake core-image-minimal