我正在尝试在 Linux v5.10.1 (SpinalSaxon) https://github.com/SpinalHDL 下对 FPGA 上的 Linux 模块进行交叉编译。工具链版本为 8.3.0-1.2 (xpack-riscv-none-embed-gcc)。我下载了 v5.10.1 并提取了内核头文件进行编译,当在目标上加载模块时,它告诉我无效的 ELF 头文件。
Linux 内核头文件有什么问题?我下载了与 Buildroot 中提到的相同的版本。在 Buildroot 上,内核头文件与正在构建的内核相同。之后,我尝试使用 riscv-none-embed-gcc(与 SaxonSpinal Linux 构建相同的工具链)交叉编译 helloworld.c,当在目标上执行时,我有
helloworld [201]:helloworld[10000+3000] 中 0x000100ac 处的未处理信号 4 代码 0x1
我应该使用什么工具链在我的 FPGA 上进行交叉编译?
为交叉编译模块准备 Linux 头文件
#!/bin/bash
export PATH=~/opt/xpack-riscv-none-embed-gcc/bin:$PATH
Prefix=riscv-none-embed-
KernelHeader=$PWD/KernelHeaders/
cd / {"=>path to my kernel v5.10.1"}
make ARCH=riscv CROSS_COMPILE=$Prefix O=$KernelHeader mrproper;
make ARCH=riscv CROSS_COMPILE=$Prefix O=$KernelHeader defconfig;
make -j 8 ARCH=riscv CROSS_COMPILE=$Prefix O=$KernelHeader modules_prepare;
################## Makefile ######################### ################
#If KERNELRELEASE is defined, we've been invoked from the kernel build system and can use its language
ifneq ($(KERNELRELEASE),)
obj-m := tiempo_ipc.o
#Otherwize we were called directly from the command line ; invlok kbuild system
else
KERNELDIR ?="./KernelHeaders/"
PWD := $(shell pwd)
.PHONY : modules
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
.PHONY: clean
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
CFLAGS_tiempo_ipc.o := -DDEBUG
######################编译###################### #################
#!/bin/bash
export PATH=$PATH:/home/tiempo/opt/xpack-riscv-none-embed-gcc/bin
#build module
make ARCH=riscv CROSS_COMPILE=riscv-none-embed-
#info module
echo""
echo "module information"
modinfo tiempo_ipc.ko