需求:移植ethercat至imx6q板,使用内核版本为4.1.15
准备工作:
1.在官网 http://www.etherlab.org/en/ethercat/ 下载ethercat-1.5.2.tar.bz2。
2.准备目标arm板运行的内核源码,编译通过。
3.安装或者解压目标arm板相应的交叉编译工具。
步骤:
1.解压IGH源码进入目录
#tar xjf ethercat-1.5.2.tar.bz2
#cd ethercat-1.5.2/
#./configure --prefix=/opt/ethercat-1.5.2/ --with-linux-dir=/opt/linux/xxx/kernel_imx --enable-8139too=no --enable-generic=yes CC=arm-none-linux-gnueabi-gcc --host=arm-none-linux-gnueabi
2.编译源码
#make
错误:
/home/mm/work/project/ethercat/ethercat-1.5.2/devices/generic.c: In function 'ec_gen_device_init':
/home/mm/work/project/ethercat/ethercat-1.5.2/devices/generic.c:152:77: error: macro "alloc_netdev" requires 4 arguments, but only 3 given
dev->netdev = alloc_netdev(sizeof(ec_gen_device_t *), &null, ether_setup);
^
/home/mm/work/project/ethercat/ethercat-1.5.2/devices/generic.c:152:19: error: 'alloc_netdev' undeclared (first use in this function)
dev->netdev = alloc_netdev(sizeof(ec_gen_device_t *), &null, ether_setup);
^
/home/mm/work/project/ethercat/ethercat-1.5.2/devices/generic.c:152:19: note: each undeclared identifier is reported only once for each function it appears in
/home/mm/work/project/ethercat/ethercat-1.5.2/devices/generic.c:146:10: warning: unused variable 'null' [-Wunused-variable]
char null = 0x00;
t/ethercat/ethercat-1.5.2/master/ethernet.c:151:72: error: macro "alloc_netdev" requires 4 arguments, but only 3 given
if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) {
^
/home/mm/work/project/ethercat/ethercat-1.5.2/master/ethernet.c:151:22: error: 'alloc_netdev' undeclared (first use in this function)
if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) {
修改:
sudo vi devices/generic.c
152行 dev->netdev = alloc_netdev(sizeof(ec_gen_device_t *), &null, ether_setup);
改为
dev->netdev = alloc_netdev(sizeof(ec_gen_device_t *), &null, NET_NAME_UNKNOWN, ether_setup);
sudo vi master/ethernet.c
151行if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) {
改为
if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name,NET_NAME_UNKNOWN, ether_setup))) {
3.指定交叉编译工具,编译modules
#make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules
//编译通过会对应生成ethercat-1.5.2/devices/ec_generic.ko和ethercat-1.5.2/master/ec_master.ko