大神的原帖https://zhoujianshi.github.io/articles/ … index.html
我想把大神的“通用虚拟网卡”移植到f1c100s,但是关于Makefile遇到问题:
obj-m := eth_uart.o
KERNEL_DIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all: eth_uart.c
make -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
clean:
rm -f *.o *.ko *.mod.c *.symvers *.order
.PHONY:clean
其中的“KERNEL_DIR := /lib/modules/$(shell uname -r)/build”应该指向那个目录呢?
最近编辑记录 kekemuyu (2019-10-19 18:45:21)
离线
你下载的 f1c100s 的内核目录
还有PWD这个目录呢?也是内核的某个目录吗?
离线
交叉编译内核模块可能还需要配置一些参数,这是编译时报错:
WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.
CC [M] /home/kekemuyu/virnet/eth_uart.o
In file included from ./include/linux/poll.h:6:0,
from /home/kekemuyu/virnet/eth_uart.c:1:
./include/linux/compiler.h:242:10: 致命错误:asm/barrier.h:没有那个文件或目录
#include <asm/barrier.h>
^~~~~~~~~~~~~~~
编译中断。
make[2]: *** [scripts/Makefile.build:323:/home/kekemuyu/virnet/eth_uart.o] 错误 1
make[1]: *** [Makefile:1508:_module_/home/kekemuyu/virnet] 错误 2
make[1]: 离开目录“/home/kekemuyu/virnet/linux”
make: *** [Makefile:6:all] 错误 2
最近编辑记录 kekemuyu (2019-10-19 21:14:20)
离线
命令行有没有加 ARCH=arm
加了,应该是路径问题:
obj-m := eth_uart.o
KERNEL_DIR := /home/kekemuyu/virnet/linux
PWD := $(shell pwd)
all: eth_uart.c
make -C $(KERNEL_DIR) SUBDIRS=$(PWD) CROSS_COMPILE=arm-linux- ARCH=arm modules
clean:
rm -f *.o *.ko *.mod.c *.symvers *.order
.PHONY:clean
离线
包含问题解决了,linux内核没有asm,但是有asm_generic,改成asm即可。但是又报错:
WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.
CC [M] /home/kekemuyu/virnet/eth_uart.o
In file included from ./include/uapi/linux/sysinfo.h:5:0,
from ./include/uapi/linux/kernel.h:5,
from ./include/linux/cache.h:5,
from ./include/linux/time.h:5,
from ./include/linux/ktime.h:24,
from ./include/linux/poll.h:7,
from /home/kekemuyu/virnet/eth_uart.c:1:
./include/linux/types.h:131:9: 错误:未知的类型名‘u64’
typedef u64 sector_t;
^~~
./include/linux/types.h:132:9: 错误:未知的类型名‘u64’
typedef u64 blkcnt_t;
^~~
./include/linux/types.h:155:9: 错误:未知的类型名‘u32’
typedef u32 dma_addr_t;
^~~
./include/linux/types.h:165:9: 错误:未知的类型名‘u32’
typedef u32 phys_addr_t;
^~~
In file included from ./include/linux/list.h:9:0,
from ./include/linux/preempt.h:11,
from ./include/linux/spinlock.h:51,
from ./include/linux/seqlock.h:36,
from ./include/linux/time.h:6,
from ./include/linux/ktime.h:24,
from ./include/linux/poll.h:7,
from /home/kekemuyu/virnet/eth_uart.c:1:
./include/linux/kernel.h:6:10: 致命错误:stdarg.h:没有那个文件或目录
#include <stdarg.h>
^~~~~~~~~~
编译中断。
make[2]: *** [scripts/Makefile.build:323:/home/kekemuyu/virnet/eth_uart.o] 错误 1
make[1]: *** [Makefile:1508:_module_/home/kekemuyu/virnet] 错误 2
make[1]: 离开目录“/home/kekemuyu/virnet/linux”
make: *** [Makefile:6:all] 错误 2
离线
第一次编译内核模块有点朦,现在有点懂了,这个内核编译比较特殊,因为用到了asm文件夹与平台相关(linux/arch/arm),需要拷贝到内核的相应的文件夹下。这次成功编译。
eth_uart.c eth_uart.mod.c eth_uart.o Makefile Module.symvers
eth_uart.ko eth_uart.mod.o linux modules.order
最近编辑记录 kekemuyu (2019-10-19 22:54:02)
离线