微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > 嵌入式系统设计讨论 > 3.基于Yocto工程新建layer和驱动模块

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.参数设置

  1. gaozh@i7:~/warp7_yocto$ MACHINE=imx7s-warp source setup-environment build

  2. Welcome to Freescale Community BSP

  3. The Yocto Project has extensive documentation about OE including a
  4. reference manual which can be found at:
  5. http://yoctoproject.org/documentation

  6. For more information about OpenEmbedded see their website:
  7. http://www.openembedded.org/

  8. You can now run 'bitbake <target>'

  9. Common targets are:
  10. core-image-minimal
  11. meta-toolchain
  12. meta-toolchain-sdk
  13. adt-installer
  14. meta-ide-support

  15. Your configuration files at build have not been touched.

复制代码

2.新建layer,注意路径


  查看qftlayer应用程序编译脚本
   gaozh@i7:~/warp7_yocto/sources/meta-qft$ vim recipes-example/example/qftlayer_0.1.bb 可以获得编译好的应用程序的名字是helloworld。

  1. #
  2. # This file was derived from the 'Hello World!' example recipe in the
  3. # Yocto Project Development Manual.
  4. #

  5. SUMMARY = "Simple helloworld application"
  6. SECTION = "examples"
  7. LICENSE = "MIT"
  8. LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

  9. SRC_URI = "file://helloworld.c"

  10. S = "${WORKDIR}"

  11. do_compile() {
  12.              ${CC} helloworld.c -o helloworld
  13. }

  14. do_install() {
  15.              install -d ${D}${bindir}
  16.              install -m 0755 helloworld ${D}${bindir}
  17. }

复制代码

3.添加新建layer加载设置

  1. gaozh@i7:~/warp7_yocto/sources/meta-qft$ vim conf/layer.conf
  2. # We have a conf and classes directory, add to BBPATH
  3. BBPATH .= ":${LAYERDIR}"

  4. # We have recipes-* directories, add to BBFILES
  5. BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
  6.         ${LAYERDIR}/recipes-*/*/*.bbappend"

  7. IMAGE_INSTALL_append = "qftlayer"

  8. BBFILE_COLLECTIONS += "qft"
  9. BBFILE_PATTERN_qft = "^${LAYERDIR}/"
  10. BBFILE_PRIORITY_qft = "6"

复制代码

4.添加新建layer到yocto工程


5.编译新建layer

  1. gaozh@i7:~/warp7_yocto/build$ bitbake qftlayer
  2. Parsing recipes: 100% |#################################################################################################################| Time: 00:00:27
  3. Parsing of 1665 .bb files complete (0 cached, 1665 parsed). 2199 targets, 189 skipped, 0 masked, 0 errors.
  4. NOTE: Resolving any missing task queue dependencies

  5. Build Configuration:
  6. BB_VERSION        = "1.30.0"
  7. BUILD_SYS         = "x86_64-linux"
  8. NATIVELSBSTRING   = "universal"
  9. TARGET_SYS        = "arm-poky-linux-gnueabi"
  10. MACHINE           = "imx7s-warp"
  11. DISTRO            = "poky"
  12. DISTRO_VERSION    = "2.1.3"
  13. TUNE_FEATURES     = "arm armv7ve vfp thumb neon       callconvention-hard       cortexa7"
  14. TARGET_FPU        = "hard"
  15. meta              
  16. meta-poky         = "HEAD:50fdd784231299bedb008f20adeaeeca3eb1452d"
  17. meta-oe           
  18. meta-multimedia   = "HEAD:55c8a76da5dc099a7bc3838495c672140cedb78e"
  19. meta-fsl-arm      = "HEAD:e2254e7b2ded0c2b66b1226f879b3a6d52037b2d"
  20. meta-fsl-arm-extra = "HEAD:2c28e636ec15c2cfd49bc9cebe0bbbcfde95bc7b"
  21. meta-fsl-demos    = "HEAD:a165068f8a0d1cf29aabe4b4053f28be1c2aa492"
  22. meta-qft          = "<unknown>:<unknown>"

  23. NOTE: Preparing RunQueue
  24. NOTE: Executing SetScene Tasks
  25. NOTE: Executing RunQueue Tasks
  26. NOTE: Tasks Summary: Attempted 379 tasks of which 379 didn't need to be rerun and all succeeded.
  27. gaozh@i7:~/warp7_yocto/build$ bitbake core-image-minimal
  28. Loading cache: 100% |##################################################################################################################| ETA:  00:00:00
  29. Loaded 2200 entries from dependency cache.
  30. NOTE: Resolving any missing task queue dependencies

  31. Build Configuration:
  32. BB_VERSION        = "1.30.0"
  33. BUILD_SYS         = "x86_64-linux"
  34. NATIVELSBSTRING   = "universal"
  35. TARGET_SYS        = "arm-poky-linux-gnueabi"
  36. MACHINE           = "imx7s-warp"
  37. DISTRO            = "poky"
  38. DISTRO_VERSION    = "2.1.3"
  39. TUNE_FEATURES     = "arm armv7ve vfp thumb neon       callconvention-hard       cortexa7"
  40. TARGET_FPU        = "hard"
  41. meta              
  42. meta-poky         = "HEAD:50fdd784231299bedb008f20adeaeeca3eb1452d"
  43. meta-oe           
  44. meta-multimedia   = "HEAD:55c8a76da5dc099a7bc3838495c672140cedb78e"
  45. meta-fsl-arm      = "HEAD:e2254e7b2ded0c2b66b1226f879b3a6d52037b2d"
  46. meta-fsl-arm-extra = "HEAD:2c28e636ec15c2cfd49bc9cebe0bbbcfde95bc7b"
  47. meta-fsl-demos    = "HEAD:a165068f8a0d1cf29aabe4b4053f28be1c2aa492"
  48. meta-qft          = "<unknown>:<unknown>"

  49. NOTE: Preparing RunQueue
  50. NOTE: Executing SetScene Tasks
  51. NOTE: Executing RunQueue Tasks
  52. NOTE: Tasks Summary: Attempted 2088 tasks of which 2082 didn't need to be rerun and all succeeded.

复制代码

6.查看新建layer,因为下载不方便,所以我们采取另外的方式验证
gaozh@i7:~/warp7_yocto/build/tmp/deploy/images/imx7s-warp$ sudo mount -t ext4 core-image-minimal-imx7s-warp.ext4 /home/gaozh/rootfs/
注意文件路径


按照下面的步骤新加驱动模块:
1.创建驱动源代码和编译脚本

  1. gaozh@i7:~/warp7_yocto/sources/meta-qft$ mkdir recipes-kernel
  2. gaozh@i7:~/warp7_yocto/sources/meta-qft$ mkdir recipes-kernel/kernel-module
  3. gaozh@i7:~/warp7_yocto/sources/meta-qft$ mkdir recipes-kernel/kernel-module/files
  4. gaozh@i7:~/warp7_yocto/sources/meta-qft$ vim recipes-kernel/kernel-module/kernel-module_0.1.bb

复制代码


  1. SUMMARY = "Example of how to build an external Linux kernel module"
  2. LICENSE = "GPLv2"
  3. LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"

  4. inherit module

  5. SRC_URI = "file://Makefile \
  6.            file://hello.c \
  7.            file://COPYING \
  8.           "

  9. S = "${WORKDIR}"

复制代码

# "kernel-module-" prefix as required by the oe-core build environment.

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.编译

  1. gaozh@i7:~/warp7_yocto/build$ bitbake kernel-module
  2. Loading cache: 100% |##################################################################################################################| ETA:  00:00:00
  3. Loaded 2201 entries from dependency cache.
  4. Parsing recipes: 100% |################################################################################################################| Time: 00:00:00
  5. Parsing of 1666 .bb files complete (1665 cached, 1 parsed). 2200 targets, 189 skipped, 0 masked, 0 errors.
  6. NOTE: Resolving any missing task queue dependencies

  7. Build Configuration:
  8. BB_VERSION        = "1.30.0"
  9. BUILD_SYS         = "x86_64-linux"
  10. NATIVELSBSTRING   = "universal"
  11. TARGET_SYS        = "arm-poky-linux-gnueabi"
  12. MACHINE           = "imx7s-warp"
  13. DISTRO            = "poky"
  14. DISTRO_VERSION    = "2.1.3"
  15. TUNE_FEATURES     = "arm armv7ve vfp thumb neon       callconvention-hard       cortexa7"
  16. TARGET_FPU        = "hard"
  17. meta              
  18. meta-poky         = "HEAD:50fdd784231299bedb008f20adeaeeca3eb1452d"
  19. meta-oe           
  20. meta-multimedia   = "HEAD:55c8a76da5dc099a7bc3838495c672140cedb78e"
  21. meta-fsl-arm      = "HEAD:e2254e7b2ded0c2b66b1226f879b3a6d52037b2d"
  22. meta-fsl-arm-extra = "HEAD:2c28e636ec15c2cfd49bc9cebe0bbbcfde95bc7b"
  23. meta-fsl-demos    = "HEAD:a165068f8a0d1cf29aabe4b4053f28be1c2aa492"
  24. meta-qft          = "<unknown>:<unknown>"

  25. NOTE: Preparing RunQueue
  26. NOTE: Executing SetScene Tasks
  27. NOTE: Executing RunQueue Tasks
  28. NOTE: Tasks Summary: Attempted 440 tasks of which 430 didn't need to be rerun and all succeeded.
  29. gaozh@i7:~/warp7_yocto/build$ bitbake core-image-minimal
  30. Loading cache: 100% |##################################################################################################################| ETA:  00:00:00
  31. Loaded 2201 entries from dependency cache.
  32. NOTE: Resolving any missing task queue dependencies

  33. Build Configuration:
  34. BB_VERSION        = "1.30.0"
  35. BUILD_SYS         = "x86_64-linux"
  36. NATIVELSBSTRING   = "universal"
  37. TARGET_SYS        = "arm-poky-linux-gnueabi"
  38. MACHINE           = "imx7s-warp"
  39. DISTRO            = "poky"
  40. DISTRO_VERSION    = "2.1.3"
  41. TUNE_FEATURES     = "arm armv7ve vfp thumb neon       callconvention-hard       cortexa7"
  42. TARGET_FPU        = "hard"
  43. meta              
  44. meta-poky         = "HEAD:50fdd784231299bedb008f20adeaeeca3eb1452d"
  45. meta-oe           
  46. meta-multimedia   = "HEAD:55c8a76da5dc099a7bc3838495c672140cedb78e"
  47. meta-fsl-arm      = "HEAD:e2254e7b2ded0c2b66b1226f879b3a6d52037b2d"
  48. meta-fsl-arm-extra = "HEAD:2c28e636ec15c2cfd49bc9cebe0bbbcfde95bc7b"
  49. meta-fsl-demos    = "HEAD:a165068f8a0d1cf29aabe4b4053f28be1c2aa492"
  50. meta-qft          = "<unknown>:<unknown>"

  51. NOTE: Preparing RunQueue
  52. NOTE: Executing SetScene Tasks
  53. NOTE: Executing RunQueue Tasks
  54. NOTE: Tasks Summary: Attempted 2102 tasks of which 2089 didn't need to be rerun and all succeeded.

复制代码

3.验证
下面第一幅图是编译此驱动模块以前,运行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

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top