Yocto Project开发(八):Linux Kernel 开发

本文介绍使用Yocto Project Linux内核时要执行的几项常见任务。这些任务包括为主机开发系统准备内核开发,准备层,修补内核,配置内核等。内核开发最好使用devtool而不是通过传统的内核工作流方法来完成,下面会介绍这两个方案的信息。

使用devtool准备开发

  • 初始化BitBake环境
     $ cd ~/poky
     $ source oe-init-build-env
  • 准备local.conf文件:默认情况下,MACHINE变量设置为“qemux86”,如果你在32位模式下为QEMU仿真器构建,则可以正常运行。但是,如果不是,则需要在构建目录中找到MACHINEconf/local.conf文件中 正确设置 变量 。
  • 为修补程序创建图层:
     $ cd ~/poky/build
     $ bitbake-layers create-layer ../../meta-mylayer
  • 把图层通知BitBake构建环境
     $ cd ~/poky/build
     $ bitbake-layers add-layer ../../meta-mylayer          
  • 构建可扩展SDK
     $ cd ~/poky/build
     $ bitbake core-image-minimal -c populate_sdk_ext
  • 安装可扩展SDK
     $ 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开发内核

下面这个过程中的步骤展示了如何使用可扩展SDKdevtool对内核进行打补丁。

  • 使用以下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/
  • 使用可扩展SDK来构建开发内核:
     $ 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"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章