Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

内核与编译路径不同时驱动编译错误 #5755

Closed
ririyeye opened this issue Oct 23, 2024 · 9 comments · Fixed by #5766
Closed

内核与编译路径不同时驱动编译错误 #5755

ririyeye opened this issue Oct 23, 2024 · 9 comments · Fixed by #5766
Labels
Milestone

Comments

@ririyeye
Copy link
Contributor

ririyeye commented Oct 23, 2024

Xmake 版本

v2.8.5+master

操作系统版本和架构

ubuntu23.10

描述问题

linux 内核正常情况下编译是直接进去目录 make config -> make 这样编译路径和代码路径是相同的
很多sdk给的编译脚本内核路径和编译路径是不一样的
我们假设内核代码路径是A , 编译路径是 B
那他们配置编译使用
make -C ${A} O=${B} a_config
make -C ${A} O=${B}
这样的编译命令

这样的话编译驱动模块的时候
make -C ${A} M=${pwd} module时候会报Kernel configuration is invalid. 因为在A这个目录下根本没有配置文件
需要加上 -O ${B} 参数带上内核的配置文件的路径
make -C ${A} O=${B} M=${pwd} module 这样的编译命令才能正确编译模块

期待的结果

希望xmake也能支持这样的模块编译 同样的 需要加入外部传入kernel编译路径

工程配置

ifneq ($(KERNELRELEASE),)
obj-m := hello.o
hello-objs := ./src/hello.o ./src/add.o
else
KERN_DIR ?= /home/wangyang/luckfox-pico/sysdrv/source/kernel
PWD := $(shell pwd)

default:
$(MAKE) ARCH=arm CROSS_COMPILE=/home/wangyang/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf- -C $(KERN_DIR) V=1 M=$(PWD) O=/home/wangyang/luckfox-pico/sysdrv/source/objs_kernel modules
endif

clean:
rm -rf .o *~ core .depend ..cmd .ko .mod.c .tmp_versions
rm -rf src/
.o src/
~ core src/.depend src/..cmd src/.ko src/*.mod.c src/.tmp_versions

附加信息和错误日志

tests/projects/linux/driver/hello_makefile/Makefile模块编译日志 上面是没改的 下面改过参数 -O ${buildpath}
wangyang@wangyang:~/xmake/tests/projects/linux/driver/hello_makefile$ make V=1
make ARCH=arm CROSS_COMPILE=/home/wangyang/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf- -C /home/wangyang/luckfox-pico/sysdrv/source/kernel V=1 M=/home/wangyang/xmake/tests/projects/linux/driver/hello_makefile modules
make[1]: Entering directory '/home/wangyang/luckfox-pico/sysdrv/source/kernel'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || (
echo >&2;
echo >&2 " ERROR: Kernel configuration is invalid.";
echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";
echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it.";
echo >&2 ;
/bin/false)

ERROR: Kernel configuration is invalid.
include/generated/autoconf.h or include/config/auto.conf are missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.

Makefile:672: include/config/auto.conf: No such file or directory
make[1]: *** [Makefile:758: include/config/auto.conf] Error 1
make[1]: Leaving directory '/home/wangyang/luckfox-pico/sysdrv/source/kernel'
make: *** [Makefile:9: default] Error 2
wangyang@wangyang:/xmake/tests/projects/linux/driver/hello_makefile$
wangyang@wangyang:
/xmake/tests/projects/linux/driver/hello_makefile$
wangyang@wangyang:~/xmake/tests/projects/linux/driver/hello_makefile$ make V=1
make ARCH=arm CROSS_COMPILE=/home/wangyang/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf- -C /home/wangyang/luckfox-pico/sysdrv/source/kernel V=1 M=/home/wangyang/xmake/tests/projects/linux/driver/hello_makefile O=/home/wangyang/luckfox-pico/sysdrv/source/objs_kernel modules
make[1]: Entering directory '/home/wangyang/luckfox-pico/sysdrv/source/kernel'
make -C /home/wangyang/luckfox-pico/sysdrv/source/objs_kernel -f /home/wangyang/luckfox-pico/sysdrv/source/kernel/Makefile modules
make[2]: Entering directory '/home/wangyang/luckfox-pico/sysdrv/source/objs_kernel'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || (
echo >&2;
echo >&2 " ERROR: Kernel configuration is invalid.";
echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";
echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it.";
echo >&2 ;
/bin/false)
make -f /home/wangyang/luckfox-pico/sysdrv/source/kernel/scripts/Makefile.build obj=/home/wangyang/xmake/tests/projects/linux/driver/hello_makefile
single-build=
need-builtin=1 need-modorder=1
/home/wangyang/luckfox-pico/sysdrv/source/kernel/scripts/gcc-wrapper.py /home/wangyang/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc -Wp,-MMD,/home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/./src/.hello.o.d -nostdinc -isystem /home/wangyang/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/../lib/gcc/arm-rockchip830-linux-uclibcgnueabihf/8.3.0/include -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/arch/arm/include -I./arch/arm/include/generated -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/include -I./include -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/arch/arm/include/uapi -I./arch/arm/include/generated/uapi -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/include/uapi -I./include/generated/uapi -include /home/wangyang/luckfox-pico/sysdrv/source/kernel/include/linux/kconfig.h -include /home/wangyang/luckfox-pico/sysdrv/source/kernel/include/linux/compiler_types.h -D__KERNEL__ -mlittle-endian -fmacro-prefix-map=/home/wangyang/luckfox-pico/sysdrv/source/kernel/= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-ipa-sra -mabi=aapcs-linux -mfpu=vfp -funwind-tables -mthumb -Wa,-mimplicit-it=always -Wa,-mno-warn-deprecated -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Os --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fstack-protector -Werror -Wimplicit-fallthrough -Wno-unused-but-set-variable -Wno-unused-const-variable -fomit-frame-pointer -g -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -DMODULE -DKBUILD_BASENAME='"hello"' -DKBUILD_MODNAME='"hello"' -D__KBUILD_MODNAME=kmod_hello -c -o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/./src/hello.o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/./src/hello.c
/home/wangyang/luckfox-pico/sysdrv/source/kernel/scripts/gcc-wrapper.py /home/wangyang/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc -Wp,-MMD,/home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/./src/.add.o.d -nostdinc -isystem /home/wangyang/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/../lib/gcc/arm-rockchip830-linux-uclibcgnueabihf/8.3.0/include -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/arch/arm/include -I./arch/arm/include/generated -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/include -I./include -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/arch/arm/include/uapi -I./arch/arm/include/generated/uapi -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/include/uapi -I./include/generated/uapi -include /home/wangyang/luckfox-pico/sysdrv/source/kernel/include/linux/kconfig.h -include /home/wangyang/luckfox-pico/sysdrv/source/kernel/include/linux/compiler_types.h -D__KERNEL__ -mlittle-endian -fmacro-prefix-map=/home/wangyang/luckfox-pico/sysdrv/source/kernel/= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-ipa-sra -mabi=aapcs-linux -mfpu=vfp -funwind-tables -mthumb -Wa,-mimplicit-it=always -Wa,-mno-warn-deprecated -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Os --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fstack-protector -Werror -Wimplicit-fallthrough -Wno-unused-but-set-variable -Wno-unused-const-variable -fomit-frame-pointer -g -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -DMODULE -DKBUILD_BASENAME='"add"' -DKBUILD_MODNAME='"hello"' -D__KBUILD_MODNAME=kmod_hello -c -o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/./src/add.o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/./src/add.c
/home/wangyang/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-ld -EL -z noexecstack -r -o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/hello.o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/./src/hello.o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/./src/add.o
{ echo /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/./src/hello.o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/./src/add.o; echo; } > /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/hello.mod
{ echo /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/hello.ko; :; } | awk '!x[$0]++' - > /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/modules.order
make -f /home/wangyang/luckfox-pico/sysdrv/source/kernel/scripts/Makefile.modpost
sed 's/.ko$/.o/' /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/modules.order | scripts/mod/modpost -o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/Module.symvers -e -i Module.symvers -T -
make -f /home/wangyang/luckfox-pico/sysdrv/source/kernel/scripts/Makefile.modfinal
/home/wangyang/luckfox-pico/sysdrv/source/kernel/scripts/gcc-wrapper.py /home/wangyang/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc -Wp,-MMD,/home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/.hello.mod.o.d -nostdinc -isystem /home/wangyang/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/../lib/gcc/arm-rockchip830-linux-uclibcgnueabihf/8.3.0/include -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/arch/arm/include -I./arch/arm/include/generated -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/include -I./include -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/arch/arm/include/uapi -I./arch/arm/include/generated/uapi -I/home/wangyang/luckfox-pico/sysdrv/source/kernel/include/uapi -I./include/generated/uapi -include /home/wangyang/luckfox-pico/sysdrv/source/kernel/include/linux/kconfig.h -include /home/wangyang/luckfox-pico/sysdrv/source/kernel/include/linux/compiler_types.h -D__KERNEL__ -mlittle-endian -fmacro-prefix-map=/home/wangyang/luckfox-pico/sysdrv/source/kernel/= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -fno-ipa-sra -mabi=aapcs-linux -mfpu=vfp -funwind-tables -mthumb -Wa,-mimplicit-it=always -Wa,-mno-warn-deprecated -D__LINUX_ARM_ARCH__=7 -march=armv7-a -msoft-float -Uarm -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Os --param=allow-store-data-races=0 -Wframe-larger-than=1024 -fstack-protector -Werror -Wimplicit-fallthrough -Wno-unused-but-set-variable -Wno-unused-const-variable -fomit-frame-pointer -g -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -DMODULE -DKBUILD_BASENAME='"hello.mod"' -DKBUILD_MODNAME='"hello"' -D__KBUILD_MODNAME=kmod_hello -c -o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/hello.mod.o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/hello.mod.c
/home/wangyang/luckfox-pico/tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf-ld -r -EL -z noexecstack --build-id=sha1 -T scripts/module.lds -o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/hello.ko /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/hello.o /home/wangyang/xmake/tests/projects/linux/driver/hello_makefile/hello.mod.o; true
make[2]: Leaving directory '/home/wangyang/luckfox-pico/sysdrv/source/objs_kernel'
make[1]: Leaving directory '/home/wangyang/luckfox-pico/sysdrv/source/kernel

@ririyeye ririyeye added the bug label Oct 23, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: Driver compilation error when kernel and compilation paths are different

@ririyeye
Copy link
Contributor Author

写错了 不是
make -C ${A} -O ${B} M=${pwd} module
而是
make -C ${A} O=${B} M=${pwd} module

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Wrong writing, no
make -C ${A} -O ${B} M=${pwd} module
Rather
make -C ${A} O=${B} M=${pwd} module

@waruqi
Copy link
Member

waruqi commented Oct 24, 2024

不知道你在说啥,xmake 编译驱动 又不用 makefile ,内核源码也是自己下载安装,跟 make 有啥关系。。你有试过么。

https://github.com/xmake-io/xmake/blob/dev/tests/projects/linux/driver/hello/xmake.lua

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I don’t know what you are talking about. xmake compiles the driver without a makefile. The kernel source code is also downloaded and installed by yourself. What does it have to do with make. . Have you tried it?

https://github.com/xmake-io/xmake/blob/dev/tests/projects/linux/driver/hello/xmake.lua

@ririyeye
Copy link
Contributor Author

xmake 在这个模式下会报 rule(platform.linux.driver): cannot get cflags from make!
主要是这个xmake/rules/platform/linux/driver/driver_modules.lua 90行这里

        local argv = {"-C", sdkdir, "V=1", "M=" .. tmpdir, "modules"}

需要加上O=${B} 这样的参数
但只是这样加上这个参数的话 上面那个错误不会报可以获取到编译参数 但最后编译阶段会报错

不知道你在说啥,xmake 编译驱动 又不用 makefile ,内核源码也是自己下载安装,跟 make 有啥关系。。你有试过么。

https://github.com/xmake-io/xmake/blob/dev/tests/projects/linux/driver/hello/xmake.lua

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


In this mode, xmake will report rule(platform.linux.driver): cannot get cflags from make!
Mainly this xmake/rules/platform/linux/driver/driver_modules.lua line 90 here

        local argv = {"-C", sdkdir, "V=1", "M=" .. tmpdir, "modules"}

You need to add parameters like O=${B}
But if you just add this parameter like this, the above error will not be reported and you can get the compilation parameters, but an error will be reported in the final compilation stage.

I don’t know what you are talking about. xmake compiles the driver without a makefile. The kernel source code is also downloaded and installed by yourself. What does it have to do with make. . Have you tried it?

https://github.com/xmake-io/xmake/blob/dev/tests/projects/linux/driver/hello/xmake.lua

@waruqi
Copy link
Member

waruqi commented Oct 24, 2024

make -C ${A} M=${pwd} module时候会报Kernel configuration is invalid. 因为在A这个目录下根本没有配置文件

这个错误一直有,不过似乎不影响编译,之前都没问题。#3291

但只是这样加上这个参数的话 上面那个错误不会报可以获取到编译参数 但最后编译阶段会报错

你可以自己调下,调通了,来个 pr 过来

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


When making -C ${A} M=${pwd} module, it will report Kernel configuration is invalid. Because there is no configuration file in the directory A.

This error has always occurred, but it doesn't seem to affect compilation. There were no problems before. #3291

But if you just add this parameter like this, the above error will not be reported and you can get the compilation parameters, but an error will be reported in the final compilation stage.

You can adjust it yourself. Once it is adjusted, come and do a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants