S32V编译内核模块

1# Build standalone kernel modules
2export ARCH=arm64
3export CROSS_COMPILE=<builddir>/tmp/sysroots/x86_64-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-
4export <Your kernel build>=<builddir>/tmp/work/<boardtype>-fsl-linux/linux-s32v2xx/4.1.26-r0/build
1export ARCH=arm64
2export CROSS_COMPILE=/home/yocto/hedong/SourceCode/baolong-sourcecode/baolong4_1_26/BSP_12.0/Yocto_s32v234_bsp12.0/build_s32v234evb_release/tmp/sysroots/x86_64-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux-
3export KERNEL_DIR=/home/yocto/hedong/SourceCode/baolong-sourcecode/baolong4_1_26/BSP_12.0/Yocto_s32v234_bsp12.0/build_s32v234evb_release/tmp/work/s32v234evb-fsl-linux/linux-s32v2xx/4.1.26-r0/build
4
5export TOOLCHAIN=/home/yocto/hedong/SourceCode/baolong-sourcecode/baolong4_1_26/BSP_12.0/Yocto_s32v234_bsp12.0/build_s32v234evb_release/tmp/sysroots/x86_64-linux/usr/bin/aarch64-fsl-linux
6export PATH=$TOOLCHAIN:$PATH
7export LINUX_S32V234_DIR=/home/yocto/hedong/SourceCode/baolong-sourcecode/baolong4_1_26/4.1.26-bsp-12.0_hd/kernel-source

编译驱动出错 Link to heading

1root@ubuntu:/home/yocto/hedong/bsp_12_0_s32v/s32v234_sdk/libs/utils/oal/kernel/build-v234ce-gnu-linux-d# make
2make KCPPFLAGS=""-O3 -D __KERNEL_MODULE -D __ARMV8 -I /home/yocto/hedong/bsp_12_0_s32v/s32v234_sdk/libs/utils/oal/kernel/build-v234ce-gnu-linux-d/../include/ -I /home/yocto/hedong/bsp_12_0_s32v/s32v234_sdk/libs/utils/oal/kernel/build-v234ce-gnu-linux-d/../../common/include/ -I /home/yocto/hedong/bsp_12_0_s32v/s32v234_sdk/libs/utils/oal/kernel/build-v234ce-gnu-linux-d/../../../../../include/ -I /home/yocto/hedong/SourceCode/baolong-sourcecode/baolong4_1_26/4.1.26-bsp-12.0_hd/kernel-source/arch/arm64/include -I /home/yocto/hedong/SourceCode/baolong-sourcecode/baolong4_1_26/4.1.26-bsp-12.0_hd/kernel-source/arch/arm64/include/generated "" ARCH=arm64 CROSS_COMPILE=/home/yocto/hedong/SourceCode/baolong-sourcecode/baolong4_1_26/BSP_12.0/Yocto_s32v234_bsp12.0/build_s32v234evb_release/tmp/sysroots/x86_64-linux/usr/bin/aarch64-fsl-linux/aarch64-fsl-linux- -C /home/yocto/hedong/SourceCode/baolong-sourcecode/baolong4_1_26/4.1.26-bsp-12.0_hd/kernel-source  M=/home/yocto/hedong/bsp_12_0_s32v/s32v234_sdk/libs/utils/oal/kernel/build-v234ce-gnu-linux-d modules 
3make: invalid option -- 'D'
4make: invalid option -- 'D'
5make: *** empty string invalid as file name.  Stop.
6make: *** [all] Error 2

问题原因:CFLGS中也是用了引号"",使用了两次引号,出现以下错误。

1$(MAKE) KCPPFLAGS="$(CFLGS)" ARCH=arm64 CROSS_COMPILE=$(TOOLCHAIN)/aarch64-fsl-linux- -C $(KERNELDIR)  M=$(PWD) modules

编译应用出错 Link to heading

1root@ubuntu:/home/yocto/hedong/s32v234_sdk/demos/isp/isp_sonyimx224_csi_dcu/build-v234ce-gnu-linux-o# make
2Current SDK ROOT is /home/yocto/hedong/s32v234_sdk
3.C0_headdep.mk: updating main-cpp.C0.d
4/bin/bash: aarch64-linux-gnu-g++: command not found
5  arm64/gnu/debug CX main-cpp.o
6/bin/bash: aarch64-linux-gnu-g++: command not found
7make: *** [main-cpp.o] Error 1

问题原因:没有将交叉编译工具链的路径添加到PATH环境中去。

1# aarch64-fsl-linux
2export TOOLCHAIN=/home/yocto/hedong/SourceCode/baolong-sourcecode/baolong4_1_26/BSP_12.0/Yocto_s32v234_bsp12.0/build_s32v234evb_release/tmp/sysroots/x86_64-linux/usr/bin/aarch64-fsl-linux
3# aarch64-linux-gnu
4export TOOLCHAIN=/home/yocto/zhaolong/baolong-sourcecode/baolong4_1_26/crossing_compiler/gcc-linaro-4.9-2014.11-x86_64_aarch64-linux-gnu/bin
5
6# 最后导入环境变量
7export PATH=$TOOLCHAIN:$PATH

内核文件校验问题 Link to heading

1[    0.000000] Linux version 4.1.26-rt29+gfc72c8d (ubuntu@ubuntu) (gcc version 4.9.3 20150311 (prerelease) (Linaro GCC 4.9-2015.03) ) #2 SMP PREEMPT Mon Jun 19 12:03:22 CST 2017
2[    0.000000] Linux version 4.1.26-rt29 (b46809@ulm) (gcc version 4.9.3 20150413 (prerelease) (Linaro GCC 4.9-2015.05) ) #1 SMP PREEMPT Wed Apr 12 20:47:45 CEST 2017

gfc72c8d内核后缀会导致驱动加载兼容性问题。

 1root@ubuntu:.../kernel-source# grep -rn "gfc72c8d"
 2Binary file .tmp_vmlinux2 matches
 3Binary file .tmp_vmlinux1 matches
 4Binary file vmlinux.o matches
 5Binary file init/built-in.o matches
 6Binary file init/version.o matches
 7Binary file vmlinux matches
 8Binary file kernel/sys.o matches
 9Binary file kernel/module.o matches
10Binary file kernel/built-in.o matches
11include/config/kernel.release:1:4.1.26-rt29+gfc72c8d
12include/generated/utsrelease.h:1:#define UTS_RELEASE "4.1.26-rt29+gfc72c8d"
13Binary file drivers/built-in.o matches
14Binary file drivers/base/firmware_class.o matches
15Binary file drivers/base/built-in.o matches
16Binary file arch/arm64/boot/Image matches
17.scmversion:1:+gfc72c8d	# 由于这个文件添的校验,修改此处为空或者缺少此文件会产生"-dirty"的后缀。

如带-dirty的后缀:

1#define UTS_RELEASE "4.1.26-rt29-dirty"
 1root@ubuntu:.../kernel-source# grep -rn ./scripts/setlocalversion 
 2Makefile:951:	echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
 3Makefile:1491:	@echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
 4scripts/package/Makefile:48:	$(CONFIG_SHELL) $(srctree)/scripts/setlocalversion --save-scmversion
 5
 6vi ./scripts/setlocalversion  +80
 7	# Check for uncommitted changes
 8	if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
 9			printf '%s' -dirty
10			#printf '%s' -test
11	fi

该文件中“printf”与“echo”打印的数据都会体现在“UTS_RELEASE”中。

1include/generated/utsrelease.h:1:#define UTS_RELEASE "4.1.26-rt29+gfc72c8d"

驱动的加载与UTS_RELEASE宏有关,直接修改include/linux/utsrelease.h文件的版本宏,驱动可正常加载。

编写驱动加载脚本 Link to heading

 1vi insmod.sh
 2
 3insmod /modules/sram.ko
 4insmod /modules/viulite.ko
 5insmod /modules/jpegdcd.ko
 6insmod /modules/h264dcd.ko
 7insmod /modules/oal_cma.ko
 8insmod /modules/csi.ko
 9insmod /modules/cam.ko
10insmod /modules/seq.ko
11insmod /modules/fdma.ko
12insmod /modules/h264enc.ko
13insmod /modules/galcore.ko contiguousSize=0x2000000

insmod.sh脚本写到/etc/init.d/rcS 文件中。

其他说明 Link to heading

您反馈的问题应该是Yocto中linaro的gcc工具链路径失效了,最新的Linux BSP(0)版本中修复了这个问题, 请您通过以下链接下载最新的Linux BSP,Yocto,以及相关文档: http://www.nxp.com/webapp/swlicensing/sso/downloadSoftware.sp?catid=SW32XX-LINUXBSP01D 您可能需要注册一个NXP账号来申请Linux BSP的下载权限。

  1. Linux的编译有两种方式:通过Yocto编译;配置工具链手动编译。在第二种情况下,用到的工具链和编译VSDK中的demo所需的工具链是一样的。 Yocto编译出来的Linux只是基本的OS,一些外设的驱动源码在VSDK中,另外一些demo工程也可以参考SDK中的例子。 所以,您可以利用Yocto来编译Linux,用VSDK来编译可能用到的驱动和开发应用程序。

See also in kernel Link to heading