在编译驱动时发现skb_frag_off函数跟内核下出现了冲突,报错如下:
make -C /home/work/.kb/build-ls/ M=/home/drivers/ngbe-1.2.5/src modules
make[1]: Entering directory '/home/work/.kb/build-ls'
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_main.o
In file included from /home/drivers/ngbe-1.2.5/src/ngbe_osdep.h:30:0,
from /home/drivers/ngbe-1.2.5/src/ngbe_type.h:61,
from /home/drivers/ngbe-1.2.5/src/ngbe.h:40,
from /home/drivers/ngbe-1.2.5/src/ngbe_main.c:43:
/home/drivers/ngbe-1.2.5/src/kcompat.h:7393:28: error: redefinition of ‘skb_frag_off’
static inline unsigned int skb_frag_off(const skb_frag_t *frag)
^~~~~~~~~~~~
In file included from /home/work/linux-ft/include/linux/if_ether.h:23:0,
from /home/work/linux-ft/include/uapi/linux/ethtool.h:19,
from /home/work/linux-ft/include/linux/ethtool.h:18,
from /home/work/linux-ft/include/linux/netdevice.h:41,
from /home/drivers/ngbe-1.2.5/src/ngbe_main.c:22:
/home/work/linux-ft/include/linux/skbuff.h:2795:28: note: previous definition of ‘skb_frag_off’ was here
static inline unsigned int skb_frag_off(const skb_frag_t *frag)
^~~~~~~~~~~~
make[4]: *** [/home/work/linux-ft/scripts/Makefile.build:304: /home/drivers/ngbe-1.2.5/src/ngbe_main.o] Error 1
make[3]: *** [/home/work/linux-ft/Makefile:1546: _module_/home/drivers/ngbe-1.2.5/src] Error 2
make[2]: *** [Makefile:146: sub-make] Error 2
make[1]: *** [Makefile:24: __sub-make] Error 2
make[1]: Leaving directory '/home/work/.kb/build-ls'
make: *** [Makefile:37: modules] Error 2
打开驱动的头文件查看
#ifndef HAVE_DEFINE_SKB_FRAG_OFF
static inline unsigned int skb_frag_off(const skb_frag_t *frag)
{
return frag->page_offset;
}
#endif
存在预编译选项在包含HAVE_DEFINE_SKB_FRAG_OFF宏是才会将此函数声明编译进去
所以原因是我是交叉编译环境,makefile是自己写的,没有考虑这些宏才出现了冲突,直接注释掉驱动头文件中的函数声明即可:
#ifndef HAVE_DEFINE_SKB_FRAG_OFF
//static inline unsigned int skb_frag_off(const skb_frag_t *frag)
//{
// return frag->page_offset;
//}
#endif
再次执行编译,驱动生成!
make -C /home/work/.kb/build-ls/ M=/home/drivers/ngbe-1.2.5/src modules
make[1]: Entering directory '/home/work/.kb/build-ls'
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_main.o
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_ethtool.o
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_lib.o
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_mbx.o
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_sriov.o
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_param.o
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_phy.o
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_procfs.o
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_hw.o
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_ptp.o
CC [M] /home/drivers/ngbe-1.2.5/src/kcompat.o
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_debugfs.o
CC [M] /home/drivers/ngbe-1.2.5/src/ngbe_sysfs.o
LD [M] /home/drivers/ngbe-1.2.5/src/ngbe.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "ngbe_pcie_do_recovery" [/home/drivers/ngbe-1.2.5/src/ngbe.ko] undefined!
CC /home/drivers/ngbe-1.2.5/src/ngbe.mod.o
LD [M] /home/drivers/ngbe-1.2.5/src/ngbe.ko
make[1]: Leaving directory '/home/work/.kb/build-ls'
有好的办法请留言!