当前位置: 首页 > 工具软件 > kernel-msm > 使用案例 >

yocto编译包含kernel-devsrc的sdk

宿淳
2023-12-01

目录

增加kernel-devsrc

编译sdk

编译驱动 

找不到头文件 

找不到fixdep

找不到modpost

使用make scripts


增加kernel-devsrc

TOOLCHAIN_TARGET_TASK_append中增加kernel-devsrc,可以把内核模块开发所需的kerenl-devsrc编译进sdk。

--- a/src/poky/meta-qti-bsp/recipes-products/images/qcs40x/qcs40x-base-image.inc
+++ b/src/poky/meta-qti-bsp/recipes-products/images/qcs40x/qcs40x-base-image.inc
@@ -4,7 +4,7 @@ RDEPENDS  += "${@bb.utils.contains('TARGET_ARCH', 'arm','lib64-edk2','edk2',d)}"
 RDEPENDS  += "${@bb.utils.contains('TARGET_ARCH', 'arm','lib64-abl-ubifs','abl-ubifs',d)}"

 # Target SDK Packages
-TOOLCHAIN_TARGET_TASK_append_sa2150p += "glib-2.0-dev"
+TOOLCHAIN_TARGET_TASK_append_sa2150p += "glib-2.0-dev kernel-devsrc"

 # Packages to be included in rootfs creation.
 IMAGE_INSTALL += "packagegroup-core-boot"

编译sdk

编译sdk,这个过程很漫长,需要3个多小时。

cd src/poky
source meta-quectel-eap/scripts/ag215s/ag215s-oem-build.sh
bitbake -f machine-image -c populate_sdk

编译驱动 

使用编译出来的sdk编译驱动。

#!/bin/bash

KSRC=/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build
export PATH=${PATH}:/opt/ag215s/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/aarch64-oe-linux
export CROSS_COMPILE=aarch64-oe-linux-
export ARCH=arm64

make modules M=`pwd` -C ${KSRC}

找不到头文件 

提示找不到asm/types.h文件。

make: Entering directory '/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build'
  CC [M]  /data/OSS/utils/modules/zdebug.o
In file included from ./include/linux/compiler.h:164,
                 from ./include/linux/init.h:5,
                 from /data/OSS/utils/modules/zdebug.c:11:
./include/uapi/linux/types.h:5:10: fatal error: asm/types.h: No such file or directory
 #include <asm/types.h>
          ^~~~~~~~~~~~~
compilation terminated.
scripts/Makefile.build:367: recipe for target '/data/OSS/utils/modules/zdebug.o' failed
make[1]: *** [/data/OSS/utils/modules/zdebug.o] Error 1
Makefile:1741: recipe for target '_module_/data/OSS/utils/modules' failed
make: *** [_module_/data/OSS/utils/modules] Error 2
make: Leaving directory '/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build'

修改kernel-devsrc.bb后重新编译sdk。

--- a/src/poky/meta/recipes-kernel/linux/kernel-devsrc.bb
+++ b/src/poky/meta/recipes-kernel/linux/kernel-devsrc.bb
@@ -93,6 +93,10 @@ do_install() {
        # be dealt with.
        # cp -a scripts $kerneldir/build

+       if [ -d arch/${ARCH}/include/generated ]; then
+            cp -a --parents arch/${ARCH}/include/generated $kerneldir/build/
+       fi
+
         if [ -d arch/${ARCH}/scripts ]; then
            cp -a arch/${ARCH}/scripts $kerneldir/build/arch/${ARCH}
        fi

找不到fixdep

头文件找到了,又出找不到fixdep幺蛾子。

make: Entering directory '/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build'
  CC [M]  /data/OSS/utils/modules/zdebug.o
/bin/sh: scripts/basic/fixdep: No such file or directory
scripts/Makefile.build:367: recipe for target '/data/OSS/utils/modules/zdebug.o' failed
make[1]: *** [/data/OSS/utils/modules/zdebug.o] Error 1
Makefile:1740: recipe for target '_module_/data/OSS/utils/modules' failed
make: *** [_module_/data/OSS/utils/modules] Error 2
make: Leaving directory '/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build'

找不到modpost

从yocto编译目录复制文件fixdep到oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build/scripts/basic/fixdep,又提示找不到modpost文件。

make: Entering directory '/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build'
  Building modules, stage 2.
  MODPOST 1 modules
/bin/sh: scripts/mod/modpost: No such file or directory
scripts/Makefile.modpost:108: recipe for target '__modpost' failed
make[1]: *** [__modpost] Error 127
Makefile:1743: recipe for target 'modules' failed
make: *** [modules] Error 2
make: Leaving directory '/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build'

继续复制modpost文件到oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build/scripts/mod/modpost,再次编译,ko文件终于编译成功。

make: Entering directory '/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build'
  CC [M]  /data/OSS/utils/modules/zdebug.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /data/OSS/utils/modules/zdebug.mod.o
  LD [M]  /data/OSS/utils/modules/zdebug.ko
make: Leaving directory '/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build'

使用make scripts

缺少fixdep、modpost文件,可以通过进入用于驱动模块开发的内核源码目录,make scripts来解决。

#!/bin/bash

KSRC=/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build
export PATH=${PATH}:/opt/ag215s/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/aarch64-oe-linux
export CROSS_COMPILE=aarch64-oe-linux-
export ARCH=arm64

if [ "$1" = "clean" ]; then
        make clean -C ${KSRC}
        make clean M=`pwd` -C ${KSRC}
else
        make scripts -C ${KSRC}
        make modules M=`pwd` -C ${KSRC}
fi

编译结果

  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/bin2c
  HOSTCC  scripts/dtc/dtc.o
  HOSTCC  scripts/dtc/flattree.o
  HOSTCC  scripts/dtc/fstree.o
  HOSTCC  scripts/dtc/data.o
  HOSTCC  scripts/dtc/livetree.o
  HOSTCC  scripts/dtc/treesource.o
  HOSTCC  scripts/dtc/srcpos.o
  HOSTCC  scripts/dtc/checks.o
  HOSTCC  scripts/dtc/util.o
  HOSTCC  scripts/dtc/dtc-lexer.lex.o
  HOSTCC  scripts/dtc/dtc-parser.tab.o
  HOSTLD  scripts/dtc/dtc
  HOSTCC  scripts/genksyms/genksyms.o
  HOSTCC  scripts/genksyms/parse.tab.o
  HOSTCC  scripts/genksyms/lex.lex.o
  HOSTLD  scripts/genksyms/genksyms
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/modpost.o
  CC      scripts/mod/devicetable-offsets.s
  CHK     scripts/mod/devicetable-offsets.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTLD  scripts/mod/modpost
  HOSTCC  scripts/selinux/genheaders/genheaders
  HOSTCC  scripts/selinux/mdp/mdp
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/sortextable
  HOSTCC  scripts/asn1_compiler
  HOSTCC  scripts/sign-file
  HOSTCC  scripts/extract-cert
/data/OSS/utils/modules
make: Entering directory '/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build'
  CC [M]  /data/OSS/utils/modules/zdebug.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /data/OSS/utils/modules/zdebug.mod.o
  LD [M]  /data/OSS/utils/modules/zdebug.ko
make: Leaving directory '/opt/ag215s/oecore-x86_64/sysroots/aarch64-oe-linux/lib/modules/4.14.206/build'

 经过无数次失败后,终于可以发布sdk用于开发驱动模块了。

 类似资料: