TipsAndTricks/KernelDevelopmentWithEsdk
Overview
This article describes an efficient workflow for Linux kernel development using Yocto Project. The goal is to get the build, deploy and test cycle to under a minute. We will be working with the generix86-64 BSP and the Intel Minnowboard Turbot in this article but the process is the same for any platform and CPU architecture.
The extensible SDK (eSDK) is a key part of this workflow for a number of reasons
- It contains the target toolchain which is not easily accessible in the bitbake environment
- It contains devtool which gives use an easy way of getting the the kernel source your target is using (if using linux-yocto or linux-intel)
- devtool will also automatically create patches for your kernel updates and add them to the the kernel recipe
There are two separate steps to this process
- Build or download an eSDK for your platform
- Install and use that eSDK to build your kernel
Build Extensible SDK
Open a new terminal window, we'll refer to this terminal as your 'bitbake terminal'. First we'll checkout poky and configure bitbake environment.
$ git clone -b pyro git://git.yocoproject.org/poky $ source poky/oe-init-build-env
Now we need to do some configuration for the Minnowboard image.
- Set MACHINE (as default is qemux86)
- Enable kernel modules (disabled by default for minimal images)
Add the following to conf/local.conf
MACHINE = "genericx86-64" MACHINE_ESSENTIAL_EXTRA_RRECOMMENDS += "kernel-modules"
Now build an extensible SDK installer for the Minnowboard in the bitbake terminal
$ bitbake core-image-minimal -c populate_sdk_ext
The eSDK installer can be found in /path_to_build_directory/kernel-dev/tmp/deploy/sdk/
./tmp/deploy/sdk/poky-glibc-x86_64-core-image-minimal-core2-64-toolchain-ext-2.3.sh
Alternatively, if you are not using a yocto-linux kernel, you can use a prebuilt eSDK installer that included the toolchain you need. For example, the pyro core-image-minimal esdk release for core2-64 is located [here]. If you downloaded the installer, make it executable.
Install Extensible SDK
Run the installer as follows. Note use of -d option to specify destination. By default installer wants to use /opt/poky that requires administrator privileges.
$ ./poky-glibc-x86_64-core-image-minimal-corei7-64-toolchain-ext-2.3.sh -d /path/to/esdk Poky (Yocto Project Reference Distro) Extensible SDK installer version 2.3 ========================================================================== You are about to install the SDK to "/home/hbruce/Tools/yocto/kernel". Proceed[Y/n]? Y Extracting SDK...............................................done Setting it up... Extracting buildtools... Preparing build system... Parsing recipes: 100% |##########################################| Time: 0:00:08 Initialising tasks: 100% |#######################################| Time: 0:00:06 Checking sstate mirror object availability: 100% |###############| Time: 0:00:00 Parsing recipes: 100% |##########################################| Time: 0:00:05 Initialising tasks: 100% |#######################################| Time: 0:00:00 done SDK has been successfully set up and is ready to be used. Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g. $ . /home/hbruce/Tools/yocto/kernel/environment-setup-corei7-64-poky-linux
Take note of the final line, this shows you the environment setup script you must run each time you want to use the eSDK.
Setup your ESDK build environment (ESDK terminal)
YOU MUST OPEN A NEW TERMINAL WHEN USING THE ESDK. DO NOT RE-USE YOUR BITBAKE TERMINAL. Open a new terminal and setup your build environment. We'll refer to this terminal as your 'ESDK terminal'. Run the setup script given by the installer.
$ source /path/to/esdk/environment-setup-core2-64-poky-linux "SDK environment now set up; additionally you may now run devtool to perform development tasks. Run devtool --help for further details.
If you see this
WARNING: attempting to use the extensible SDK in an environment set up to run bitbake - this may lead to unexpected results. Please source this script in a new shell session instead."
You didn't open a new terminal!
Build initial image with ESDK
In the ESDK terminal, build the image
$ devtool build-image Parsing recipes: 100% |##########################################| Time: 0:00:05 Parsing of 830 .bb files complete (0 cached, 830 parsed). 1299 targets, 47 skipped, 0 masked, 0 errors. WARNING: No packages to add, building image core-image-minimal unmodified Loading cache: 100% |############################################| Time: 0:00:00 Loaded 1299 entries from dependency cache. NOTE: Resolving any missing task queue dependencies Initialising tasks: 100% |#######################################| Time: 0:00:07 Checking sstate mirror object availability: 100% |###############| Time: 0:00:00 NOTE: Executing SetScene Tasks NOTE: Executing RunQueue Tasks NOTE: Tasks Summary: Attempted 2866 tasks of which 2604 didn't need to be rerun and all succeeded. NOTE: Successfully built core-image-minimal. You can find output files in /path/to/esdk/tmp/deploy/images/genericx86-64
Now flash to image to USB stick, assuming USB stick is on /dev/sdd
$ sudo dd if=tmp/deploy/images/genericx86-64/core-image-minimal-genericx86-64.wic of=/dev/sdd bs=1MB $ sync
Boot Minnowboard with this image and check all is OK.
Prepare to make changes to kernel
First we must use devtool to checkout the kernel source code in its workspace.
$ devtool modify virtual/kernel Loading cache: 100% |############################################| Time: 0:00:00 Loaded 1299 entries from dependency cache. NOTE: Mapping virtual/kernel to linux-yocto Loading cache: 100% |############################################| Time: 0:00:00 Loaded 1299 entries from dependency cache. NOTE: Executing RunQueue Tasks NOTE: Executing do_fetch... NOTE: Executing do_unpack... NOTE: Tasks Summary: Attempted 2 tasks of which 0 didn't need to be rerun and all succeeded. NOTE: Executing RunQueue Tasks NOTE: Executing do_kernel_checkout... NOTE: Tasks Summary: Attempted 3 tasks of which 2 didn't need to be rerun and all succeeded. NOTE: Patching... NOTE: Executing RunQueue Tasks NOTE: Executing do_validate_branches... NOTE: Executing do_kernel_metadata... NOTE: Executing do_patch... NOTE: Tasks Summary: Attempted 6 tasks of which 3 didn't need to be rerun and all succeeded. NOTE: Generating kernel config NOTE: Executing RunQueue Tasks NOTE: Executing do_prepare_recipe_sysroot... NOTE: Executing do_kernel_configme... NOTE: Executing do_configure... NOTE: Tasks Summary: Attempted 9 tasks of which 6 didn't need to be rerun and all succeeded. NOTE: Copying kernel config to srctree NOTE: Source tree extracted to /home/hbruce/Tools/yocto/kernel/workspace/sources/linux-yocto NOTE: Recipe linux-yocto now set up to build from /home/hbruce/Tools/yocto/kernel/workspace/sources/linux-yocto
Checkout the kernel source tree and construct .config
Check out the Linux kernel source and construct a .config from the Yocto kernel configuration segments. The sources can be found in /path_to_build_directory/kernel-dev/workspace/sources/linux-yocto.
devtool modify linux-yocto
If you are just using a kernel from somewhere else, for example kernel.org, you can just clone it instead of using devtool modify in this step.
Setup your ESDK build environment (ESDK terminal)
Open a new terminal and setup your build environment. We'll refer to this terminal as your 'ESDK terminal'
. /path_to_esdk/environment-setup-corei7-64-poky-linux
NOTE: If you see the message below you will really need to open a new terminal :).
"SDK environment now set up; additionally you may now run devtool to perform development tasks. Run devtool --help for further details. WARNING: attempting to use the extensible SDK in an environment set up to run bitbake - this may lead to unexpected results. Please source this script in a new shell session instead."
Build your kernel (ESDK terminal)
Navigate to your workspace directory e.g /path_to_build_directory/kernel-dev/workspace/sources/linux-yocto and build the kernel
make
Modify your kernel and commit your changes (ESDK terminal)
You can navigate to the Linux source directory (/path_to_build_directory/kernel-dev/workspace/sources/linux-yocto) and modify the kernel. Commit your kernel changes.
Build an image with your kernel changes (optional) (bitbake terminal)
devtool build-image core-image-minimal
For faster iteration, in 2.4 some wic commands are being included to allow you to insert the kernel in an image without going through the full recreation of the image. For older releases you can do:
sudo kpartx -a <foo>.wic sudo mount /dev/mapper/loopNpM /mnt/wic-partionM
In this case, it will be the next available loopback device. If you are not using any , it will be loop0. so in the std case it would look like
sudo mount /dev/mapper/loop0p1 /mnt/wic-partion1
Then you could dd the kernel into the kernel partion. Then unmount and unkaprtx...
sudo umount mnt/wic-partionM sudo kaprtx -d /dev/loopN
Note that this requires root/sudo rights. The assumption here is most kernel devs would have this or could do it in a vm/container.
Export patches and create a bbappend file (bitbake terminal)
To export your commits to patches and a bbappend file use the following command.
devtool finish linux-yocto /path_to_poky_directory/meta-yocto-bsp/
The patches and the bbappend can be found in /path_to_poky_directory/meta-yocto-bsp/recipes-kernel/linux.
Build image with your modified kernel (bitbake terminal)
You can now build an image which will include your kernel patches.
Execute the following command from your build directory ( e.g /path_to_build_directory/kernel-dev/)
bitbake core-image-minimal