本文介绍使用Yocto Project Linux 内核时要执行的几项常见任务。这些任务包括为主机开发系统准备内核开发,准备层,修补内核,配置内核等。内核开发最好使用devtool 而不是通过传统的内核工作流方法来完成,下面会介绍这两个方案的信息。
使用devtool 准备开发
$ cd ~/poky
$ source oe-init-build-env
- 准备
local.conf 文件:默认情况下,MACHINE 变量设置为“qemux86 ”,如果你在32位模式下为QEMU 仿真器构建,则可以正常运行。但是,如果不是,则需要在构建目录中找到MACHINE 的conf/local.conf 文件中 正确设置 变量 。 - 为修补程序创建图层:
$ cd ~/poky/build
$ bitbake-layers create-layer ../../meta-mylayer
$ cd ~/poky/build
$ bitbake-layers add-layer ../../meta-mylayer
$ cd ~/poky/build
$ bitbake core-image-minimal -c populate_sdk_ext
$ cd ~/poky/build/tmp/deploy/sdk
$ ./poky-glibc-x86_64-core-image-minimal-i586-toolchain-ext-2.7.1.sh
- 设置新终端以使用可扩展
SDK :必须要打开一个新的终端来使用新的SDK ,不能使用之前使用的BitBake shell 。
$ source ~/poky_sdk/environment-setup-i586-poky-linux
- 构建全新镜像:准备在内核上工作的最后一步是使用
devtool 在刚刚为SDK 设置并初始化的新终端中构建初始镜像:
$ devtool build-image
准备一个Layer
- 创建图层的结构:
conf 目录保存配置文件,recipes-kernel 目录保存追加文件和最终补丁文件。
$ cd $HOME
$ mkdir meta-mylayer
$ mkdir meta-mylayer/conf
$ mkdir meta-mylayer/recipes-kernel
$ mkdir meta-mylayer/recipes-kernel/linux
$ mkdir meta-mylayer/recipes-kernel/linux/linux-yocto
- 创建层配置文件:移动到
meta-mylayer/conf 目录,创建layer.conf 文件:
# 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"
- 创建内核配方附加文件:移动到
meta-mylayer/recipes-kernel/linux 目录并创建内核的附加文件。本例使用linux-yocto-4.12 内核。因此,append 文件的名称为linux-yocto_4.12.bbappend :
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI_append += "file://patch-file-one"
SRC_URI_append += "file://patch-file-two"
SRC_URI_append += "file://patch-file-three"
使用devtool 开发内核
下面这个过程中的步骤展示了如何使用可扩展SDK 和devtool 对内核进行打补丁。
$ source ~/poky_sdk/environment-setup-i586-poky-linux
$ devtool modify linux-yocto
$ cd ~/poky_sdk/workspace/sources/linux-yocto
# Edit the init/calibrate.c file
$ devtool build linux-yocto
$ cd ~
$ devtool build-image core-image-minimal
$ runqemu qemux86
# dmesg | less
$ cd ~/poky_sdk/workspace/sources/linux-yocto
$ git status
$ git add init/calibrate.c
$ git commit -m "calibrate: Add printk example"
$ devtool finish linux-yocto ~/meta-mylayer
$ cd ~/poky/build
$ bitbake core-image-minimal
使用传统方式开发内核
$ cd poky/build/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+gitAUTOINC+eda4d18...
...967-r0/linux-qemux86-standard-build/source
# Edit the init/calibrate.c file
$ cd poky/build/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+gitAUTOINC+eda4d18...
...967-r0/linux-qemux86-standard-build/
$ source ~/poky_sdk/environment-setup-i586-poky-linux
$ make menuconfig
$ make
$ cd poky/build/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+gitAUTOINC+eda4d18...
...967-r0/linux-qemux86-standard-build/source
$ git status
$ git add init/calibrate.c
$ git commit -m "calibrate: Add printk example"
|