3.基于Yocto工程新建layer和驱动模块
时间:10-02
整理:3721RD
点击:
Yocto是一个开源项目,目的是构建一个嵌入式Linux系统。在其他方面,Yocto项目基于openembedded主机(OE)项目,采用bitbake工具,构建嵌入式Linux系统。WaRP7使用的版本是2.1.3。Yocto官方文档内容非常多,我们这里只是列出我感兴趣的部分,文件系统和kernel相关。
1)与文件系统相关的recipes:
build-appliance-image;core-image-base;core-image-clutter;core-image-directfb;core-image-full-cmdline;core-image-lsb;core-image-lsb-dev;core-image-lsb-sdk;core-image-minimal;core-image-minimal-dev;core-image-minimal-initramfs;core-image-minimal-mtdutils;core-image-rt;core-image-rt-sdk;core-image-sato;core-image-sato-dev;core-image-sato-sdk;core-image-testmaster;core-image-testmaster-initramfs;core-image-weston;core-image-x11
2)与kernel相关的编译命令:
1.配置menuconfig指令:
bitbake -c menuconfig -v linux-warp7
2.单独编译kernel、模块、设备树
bitbake -c compile -f -v linux-warp7
bitbake linux-warp7 -c compile_kernelmodules -f -v 这个没有测试过
bitbake -c deploy -f -v linux-warp7 这个没有测试过
按照下面的步骤新加一个应用程序:
1.参数设置
- gaozh@i7:~/warp7_yocto$ MACHINE=imx7s-warp source setup-environment build
- Welcome to Freescale Community BSP
- The Yocto Project has extensive documentation about OE including a
- reference manual which can be found at:
- http://yoctoproject.org/documentation
- For more information about OpenEmbedded see their website:
- http://www.openembedded.org/
- You can now run 'bitbake <target>'
- Common targets are:
- core-image-minimal
- meta-toolchain
- meta-toolchain-sdk
- adt-installer
- meta-ide-support
- Your configuration files at build have not been touched.
查看qftlayer应用程序编译脚本
gaozh@i7:~/warp7_yocto/sources/meta-qft$ vim recipes-example/example/qftlayer_0.1.bb 可以获得编译好的应用程序的名字是helloworld。
- #
- # This file was derived from the 'Hello World!' example recipe in the
- # Yocto Project Development Manual.
- #
- SUMMARY = "Simple helloworld application"
- SECTION = "examples"
- LICENSE = "MIT"
- LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
- SRC_URI = "file://helloworld.c"
- S = "${WORKDIR}"
- do_compile() {
- ${CC} helloworld.c -o helloworld
- }
- do_install() {
- install -d ${D}${bindir}
- install -m 0755 helloworld ${D}${bindir}
- }
- gaozh@i7:~/warp7_yocto/sources/meta-qft$ vim 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"
- IMAGE_INSTALL_append = "qftlayer"
- BBFILE_COLLECTIONS += "qft"
- BBFILE_PATTERN_qft = "^${LAYERDIR}/"
- BBFILE_PRIORITY_qft = "6"
5.编译新建layer
- gaozh@i7:~/warp7_yocto/build$ bitbake qftlayer
- Parsing recipes: 100% |#################################################################################################################| Time: 00:00:27
- Parsing of 1665 .bb files complete (0 cached, 1665 parsed). 2199 targets, 189 skipped, 0 masked, 0 errors.
- NOTE: Resolving any missing task queue dependencies
- Build Configuration:
- BB_VERSION = "1.30.0"
- BUILD_SYS = "x86_64-linux"
- NATIVELSBSTRING = "universal"
- TARGET_SYS = "arm-poky-linux-gnueabi"
- MACHINE = "imx7s-warp"
- DISTRO = "poky"
- DISTRO_VERSION = "2.1.3"
- TUNE_FEATURES = "arm armv7ve vfp thumb neon callconvention-hard cortexa7"
- TARGET_FPU = "hard"
- meta
- meta-poky = "HEAD:50fdd784231299bedb008f20adeaeeca3eb1452d"
- meta-oe
- meta-multimedia = "HEAD:55c8a76da5dc099a7bc3838495c672140cedb78e"
- meta-fsl-arm = "HEAD:e2254e7b2ded0c2b66b1226f879b3a6d52037b2d"
- meta-fsl-arm-extra = "HEAD:2c28e636ec15c2cfd49bc9cebe0bbbcfde95bc7b"
- meta-fsl-demos = "HEAD:a165068f8a0d1cf29aabe4b4053f28be1c2aa492"
- meta-qft = "<unknown>:<unknown>"
- NOTE: Preparing RunQueue
- NOTE: Executing SetScene Tasks
- NOTE: Executing RunQueue Tasks
- NOTE: Tasks Summary: Attempted 379 tasks of which 379 didn't need to be rerun and all succeeded.
- gaozh@i7:~/warp7_yocto/build$ bitbake core-image-minimal
- Loading cache: 100% |##################################################################################################################| ETA: 00:00:00
- Loaded 2200 entries from dependency cache.
- NOTE: Resolving any missing task queue dependencies
- Build Configuration:
- BB_VERSION = "1.30.0"
- BUILD_SYS = "x86_64-linux"
- NATIVELSBSTRING = "universal"
- TARGET_SYS = "arm-poky-linux-gnueabi"
- MACHINE = "imx7s-warp"
- DISTRO = "poky"
- DISTRO_VERSION = "2.1.3"
- TUNE_FEATURES = "arm armv7ve vfp thumb neon callconvention-hard cortexa7"
- TARGET_FPU = "hard"
- meta
- meta-poky = "HEAD:50fdd784231299bedb008f20adeaeeca3eb1452d"
- meta-oe
- meta-multimedia = "HEAD:55c8a76da5dc099a7bc3838495c672140cedb78e"
- meta-fsl-arm = "HEAD:e2254e7b2ded0c2b66b1226f879b3a6d52037b2d"
- meta-fsl-arm-extra = "HEAD:2c28e636ec15c2cfd49bc9cebe0bbbcfde95bc7b"
- meta-fsl-demos = "HEAD:a165068f8a0d1cf29aabe4b4053f28be1c2aa492"
- meta-qft = "<unknown>:<unknown>"
- NOTE: Preparing RunQueue
- NOTE: Executing SetScene Tasks
- NOTE: Executing RunQueue Tasks
- NOTE: Tasks Summary: Attempted 2088 tasks of which 2082 didn't need to be rerun and all succeeded.
gaozh@i7:~/warp7_yocto/build/tmp/deploy/images/imx7s-warp$ sudo mount -t ext4 core-image-minimal-imx7s-warp.ext4 /home/gaozh/rootfs/
注意文件路径
按照下面的步骤新加驱动模块:
1.创建驱动源代码和编译脚本
- gaozh@i7:~/warp7_yocto/sources/meta-qft$ mkdir recipes-kernel
- gaozh@i7:~/warp7_yocto/sources/meta-qft$ mkdir recipes-kernel/kernel-module
- gaozh@i7:~/warp7_yocto/sources/meta-qft$ mkdir recipes-kernel/kernel-module/files
- gaozh@i7:~/warp7_yocto/sources/meta-qft$ vim recipes-kernel/kernel-module/kernel-module_0.1.bb
- SUMMARY = "Example of how to build an external Linux kernel module"
- LICENSE = "GPLv2"
- LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"
- inherit module
- SRC_URI = "file://Makefile \
- file://hello.c \
- file://COPYING \
- "
- S = "${WORKDIR}"
gaozh@i7:~/warp7_yocto/sources/meta-qft$ vim recipes-kernel/kernel-module/files/hello.c
gaozh@i7:~/warp7_yocto/sources/meta-qft$ vim recipes-kernel/kernel-module/files/Makfile
直接拷贝yocoto工程提供的参数文件,当然也可以直接在Makefile中删除。
cp ~/warp7_yocto/sources/poky/meta-skeleton/recipes-kernel/hello-mod/files/COPYING ./COPYING
驱动模块加载脚本
2.编译
- gaozh@i7:~/warp7_yocto/build$ bitbake kernel-module
- Loading cache: 100% |##################################################################################################################| ETA: 00:00:00
- Loaded 2201 entries from dependency cache.
- Parsing recipes: 100% |################################################################################################################| Time: 00:00:00
- Parsing of 1666 .bb files complete (1665 cached, 1 parsed). 2200 targets, 189 skipped, 0 masked, 0 errors.
- NOTE: Resolving any missing task queue dependencies
- Build Configuration:
- BB_VERSION = "1.30.0"
- BUILD_SYS = "x86_64-linux"
- NATIVELSBSTRING = "universal"
- TARGET_SYS = "arm-poky-linux-gnueabi"
- MACHINE = "imx7s-warp"
- DISTRO = "poky"
- DISTRO_VERSION = "2.1.3"
- TUNE_FEATURES = "arm armv7ve vfp thumb neon callconvention-hard cortexa7"
- TARGET_FPU = "hard"
- meta
- meta-poky = "HEAD:50fdd784231299bedb008f20adeaeeca3eb1452d"
- meta-oe
- meta-multimedia = "HEAD:55c8a76da5dc099a7bc3838495c672140cedb78e"
- meta-fsl-arm = "HEAD:e2254e7b2ded0c2b66b1226f879b3a6d52037b2d"
- meta-fsl-arm-extra = "HEAD:2c28e636ec15c2cfd49bc9cebe0bbbcfde95bc7b"
- meta-fsl-demos = "HEAD:a165068f8a0d1cf29aabe4b4053f28be1c2aa492"
- meta-qft = "<unknown>:<unknown>"
- NOTE: Preparing RunQueue
- NOTE: Executing SetScene Tasks
- NOTE: Executing RunQueue Tasks
- NOTE: Tasks Summary: Attempted 440 tasks of which 430 didn't need to be rerun and all succeeded.
- gaozh@i7:~/warp7_yocto/build$ bitbake core-image-minimal
- Loading cache: 100% |##################################################################################################################| ETA: 00:00:00
- Loaded 2201 entries from dependency cache.
- NOTE: Resolving any missing task queue dependencies
- Build Configuration:
- BB_VERSION = "1.30.0"
- BUILD_SYS = "x86_64-linux"
- NATIVELSBSTRING = "universal"
- TARGET_SYS = "arm-poky-linux-gnueabi"
- MACHINE = "imx7s-warp"
- DISTRO = "poky"
- DISTRO_VERSION = "2.1.3"
- TUNE_FEATURES = "arm armv7ve vfp thumb neon callconvention-hard cortexa7"
- TARGET_FPU = "hard"
- meta
- meta-poky = "HEAD:50fdd784231299bedb008f20adeaeeca3eb1452d"
- meta-oe
- meta-multimedia = "HEAD:55c8a76da5dc099a7bc3838495c672140cedb78e"
- meta-fsl-arm = "HEAD:e2254e7b2ded0c2b66b1226f879b3a6d52037b2d"
- meta-fsl-arm-extra = "HEAD:2c28e636ec15c2cfd49bc9cebe0bbbcfde95bc7b"
- meta-fsl-demos = "HEAD:a165068f8a0d1cf29aabe4b4053f28be1c2aa492"
- meta-qft = "<unknown>:<unknown>"
- NOTE: Preparing RunQueue
- NOTE: Executing SetScene Tasks
- NOTE: Executing RunQueue Tasks
- NOTE: Tasks Summary: Attempted 2102 tasks of which 2089 didn't need to be rerun and all succeeded.
下面第一幅图是编译此驱动模块以前,运行kernel的目录结构
下面是编译此驱动模块的保存路径。
总结:第一次接触Yocto工程,难免会遇到很多问题,其实就是对新事物一些常识性的知识不了解。因为时间关系就不在研究Yocto工程本身的功能,仅仅熟悉一下一个Yocto工程中Linux kernel dts配置文件和driver代码在哪里?如何使用。补充:应用程序和驱动的运行结果。
root@imx7s-warp:~# helloworld
qftlayer Hello World!
root@imx7s-warp:~# insmod /lib/modules/4.1.32-4.1-1.0.x-imx-warp7\+g511f37a/
extra/ modules.alias.bin modules.dep modules.order modules.symbols.bin
kernel/ modules.builtin modules.dep.bin modules.softdep
modules.alias modules.builtin.bin modules.devname modules.symbols
root@imx7s-warp:~# insmod /lib/modules/4.1.32-4.1-1.0.x-imx-warp7\+g511f37a/extra/hello.ko
qft kernel module Hello World!
root@imx7s-warp:~# rmmod /lib/modules/4.1.32-4.1-1.0.x-imx-warp7\+g511f37a/extra/helloqft kernel module Goodbye Cruel World!
.ko