根據需要需要把依賴dpdk的kni module移植,所以就學習了下模塊編譯makefile,總結如下
Makefile內容如下
obj-m += rte_kni.o #要生成的module文件名爲rte_kni.ko
#指定生成module需要的所有.o文件
rte_kni-objs:=kni_misc.o kni_ethtool.o kni_net.o ethtool/ixgbe/ixgbe_main.o ethtool/ixgbe/ixgbe_api.o ethtool/ixgbe/ixgbe_common.o ethtool/ixgbe/ixgbe_ethtool.o ethtool/ixgbe/ixgbe_82599.o ethtool/ixgbe/ixgbe_82598.o ethtool/ixgbe/ixgbe_x540.o ethtool/ixgbe/ixgbe_phy.o ethtool/ixgbe/kcompat.o ethtool/igb/e1000_82575.o ethtool/igb/e1000_i210.o ethtool/igb/e1000_api.o ethtool/igb/e1000_mac.o ethtool/igb/e1000_manage.o ethtool/igb/e1000_mbx.o ethtool/igb/e1000_nvm.o ethtool/igb/e1000_phy.o ethtool/igb/igb_ethtool.o ethtool/igb/igb_hwmon.o ethtool/igb/igb_main.o ethtool/igb/igb_debugfs.o ethtool/igb/igb_param.o ethtool/igb/igb_procfs.o ethtool/igb/igb_vmdq.o
PWD:=$(shell pwd)
KERNEL_VERSION=/lib/modules/`uname -r`/build
#指定編譯過程中需要引用的文件路徑
CFLAGS += -I$(PWD)/ethtool/ixgbe -I$(PWD)/ethtool/igb
CFLAGS += -Wall -Werror
#編譯入口
all:
make -C $(KERNEL_VERSION) M=$(PWD) modules
clean:
make -C $(KERNEL_VERSION) M=$(PWD) clean
kni模塊主要文件可通過下面網址看到http://www.dpdk.org/browse/dpdk/commit/?id=3fc5ca2f63529ec5ad7b1b75f517d61dc7613bd9
將Makefile放在kni路徑下
make
即可生成module,module文件爲rte_kni.ko
加載模塊
提示錯誤insmod: error inserting 'rte_kni.ko': -1 Unknown symbol in module
dmesg日誌顯示
rte_kni: Unknown symbol hwmon_device_register
rte_kni: Unknown symbol hwmon_device_unregister
通過modinfo rte_kni.ko查看依賴hwmon模塊
加載依賴模塊
modprobe hwmon
然後
insmod rte_kni.ko kthread_mode=multiple
安裝成功 dmesg日誌如下
KNI: ######## DPDK kni module loading ########
KNI: loopback disabled
KNI: ######## DPDK kni module loaded ########