米尔电子
直播中

h1654155781.3968

11年用户 65经验值
擅长:电源/新能源 控制/MCU RF/无线
私信 关注

【米尔-瑞米派兼容树莓派扩展模块-试用体验】EtherCAT移植

下载EtherCAT IGH源码

到官网下载1.5版本的EtherCAT源码,如图4-1:

https://gitlab.com/etherlab.org/ethercat/-/tree/stable-1.5?ref_type=heads

81aed38678bccea87f64fc2fe865be05.png

解压EtherCAT源码

hjx@myir-server:/renesas/04_Sources$ tar -xvf ethercat-stable-1.5.tar.bz2
hjx@myir-server:/renesas/04_Sources$ cd ethercat-stable-1.5

编译EtherCAT源码

  • 生成configure文件
  1. hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5$ ./bootstrap
    • touch ChangeLog
    • mkdir -p m4
    • autoreconf -i
  2. libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'autoconf'.
  3. libtoolize: copying file 'autoconf/ltmain.sh'
  4. libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
  5. libtoolize: copying file 'm4/libtool.m4'
  6. libtoolize: copying file 'm4/ltoptions.m4'
  7. libtoolize: copying file 'm4/ltsugar.m4'
  8. libtoolize: copying file 'm4/ltversion.m4'
  9. libtoolize: copying file 'm4/lt~obsolete.m4'
  10. configure.ac:56: installing 'autoconf/ar-lib'
  11. configure.ac:55: installing 'autoconf/compile'
  12. configure.ac:58: installing 'autoconf/config.guess'
  13. configure.ac:58: installing 'autoconf/config.sub'
  14. configure.ac:42: installing 'autoconf/install-sh'
  15. configure.ac:42: installing 'autoconf/missing'
    ruby
    examples/dc_user/Makefile.am: installing autoconf/depcomp'
  • configure设置

hjx@myir-server:/renesas/04_Sources/ethercat-stable-1.5$ mkdir output
hjx@myir-server:
/renesas/04_Sources/ethercat-stable-1.5$ ./configure --prefix=/home/hjx/renesas/04_Sources/ethercat-stable-1.5/output --with-linux-dir=/home/hjx/renesas/04_Sources/myir-renesas-linux --enable-8139too=no --enable-generic=yes --host=aarch64-poky-linux

(--prefix=/home/hjx/renesas/04_Sources/output 指定输出目录、--with-linux-dir=/home/hjx/renesas/04_Sources/myir-renesas-linux指定内核源码目录)

configure: loading site script /opt/remi-sdk/site-config-aarch64-poky-linux
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for aarch64-poky-linux-strip... aarch64-poky-linux-strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for a sed that does not truncate output... (cached) sed
checking for aarch64-poky-linux-pkg-config... no
checking for pkg-config... /opt/remi-sdk/sysroots/x86_64-pokysdk-linux/usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking whether make supports the include directive... yes (GNU style)
..........
...............
config.status: creating examples/xenomai/Makefile
config.status: creating examples/xenomai_posix/Makefile
config.status: creating include/Makefile
config.status: creating lib/Makefile
config.status: creating lib/libethercat.pc
config.status: creating master/Kbuild
config.status: creating master/Makefile
config.status: creating script/Makefile
config.status: creating script/init.d/Makefile
config.status: creating script/init.d/ethercat
config.status: creating script/sysconfig/Makefile
config.status: creating tool/Makefile
config.status: creating tty/Kbuild
config.status: creating tty/Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
  • 编译源码
    hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5$ make
    make all-recursive
    make[1]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
    Making all in include
    make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
    make[2]: Nothing to be done for 'all'.
    make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
    Making all in script
    make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script'
    Making all in init.d
    make[3]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/init.d'
    make[3]: Nothing to be done for 'all'.
    make[3]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/init.d'
    Making all in sysconfig
    make[3]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/sysconfig'
    make[3]: Nothing to be done for 'all'.
    make[3]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/sysconfig'
    ......
    ......
    make[3]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples/user'
    make[3]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
    make[3]: Nothing to be done for 'all-am'.
    make[3]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
    make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
    make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
    make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
    make[1]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'

    • 编译modules
  • hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5$ make modules
    make[1]: Entering directory '/home/hjx/renesas/04_Sources/myir-renesas-linux'
    CC [M] /home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples/mini/mini.o
    LD [M] /home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples/mini/ec_mini.o
    CC [M] /home/hjx/renesas/04_Sources/ethercat-stable-1.5/master/cdev.o
    CC [M] /home/hjx/renesas/04_Sources/ethercat-stable-1.5/master/coe_emerg_ring.o
    CC [M] /home/hjx/renesas/04_Sources/ethercat-stable-1.5/master/datagram.o
    ...........
    ............
    make[1]: Leaving directory '/home/hjx/renesas/04_Sources/myir-renesas-linux'

    4.3. 安装EtherCAT

安装成功后前面指定/home/hjx/renesas/04_Sources/ethercat-stable-1.5/output目录下有编译生成的各种用户空间的文件。

hjx@myir-server:~/renesas/04_Sources/ethercat-stable-1.5$ make install
Making install in include
make[1]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
make[2]: Nothing to be done for 'install-exec-am'.
/bin/mkdir -p '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/output/include'
/usr/bin/install -c -m 644 ecrt.h ectty.h '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/output/include'
make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
make[1]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/include'
Making install in script
make[1]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script'
Making install in init.d
make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/init.d'
make[3]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/script/init.d'
make[3]: Nothing to be done for 'install-exec-am'.
...........
..........
make[3]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
make[1]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5/examples'
make[1]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
make[2]: Entering directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'
make[1]: Leaving directory '/home/hjx/renesas/04_Sources/ethercat-stable-1.5'

将EtharCAT相关文件打包

在/home/hjx/renesas/04_Sources/ethercat-stable-1.5/output目录下创建modules文件夹,并复制ec_generic.ko和ec_master.ko到modules下

hjx@myir-server:/renesas/04_Sources/ethercat-stable-1.5$ mkdir -p output/modules
hjx@myir-server:
/renesas/04_Sources/ethercat-stable-1.5$ cp devices/ec_generic.ko output/modules/
hjx@myir-server:/renesas/04_Sources/ethercat-stable-1.5$ cp master/ec_master.ko output/modules/
hjx@myir-server:
/renesas/04_Sources/ethercat-stable-1.5$ ls output
bin etc include lib modules sbin share

  • 压缩output输出文件
    hjx@myir-server:/renesas/04_Sources/ethercat-stable-1.5$ tar -jcvf output.tar.bz2 output/
    output/
    output/etc/
    output/etc/ethercat.conf
    output/etc/init.d/
    output/etc/init.d/ethercat
    output/etc/sysconfig/
    output/etc/sysconfig/ethercat
    output/sbin/
    output/sbin/ethercatctl
    output/include/
    output/include/ectty.h
    output/include/ecrt.h
    output/modules/
    output/modules/ec_master.ko
    output/modules/ec_generic.ko
    output/share/
    output/share/bash-completion/
    output/share/bash-completion/completions/
    output/share/bash-completion/completions/ethercat
    output/bin/
    output/bin/ethercat
    output/lib/
    output/lib/libethercat.so
    output/lib/pkgconfig/
    output/lib/pkgconfig/libethercat.pc
    output/lib/libethercat.so.1.2.0
    output/lib/cmake/
    output/lib/cmake/ethercat/
    output/lib/cmake/ethercat/ethercat-config.cmake
    output/lib/libethercat.a
    output/lib/libethercat.la
    output/lib/libethercat.so.1
    hjx@myir-server:
    /renesas/04_Sources/ethercat-stable-1.5$ ls output.tar.bz2
    output.tar.bz2

    至此IGH交叉编译完成,下面是在对应arm目标板上的操作。

4.5. 移植EtherCAT相关库到开发板

将上面制作好的output.tar.bz2传到开发板上,然后解压出来。

root@myir-remi-1g:~# tar -xvf output.tar.bz2
output/
output/etc/
output/etc/ethercat.conf
output/etc/init.d/
output/etc/init.d/ethercat
output/etc/sysconfig/
output/etc/sysconfig/ethercat
output/sbin/
output/sbin/ethercatctl
output/include/
output/include/ectty.h
output/include/ecrt.h
output/modules/
output/modules/ec_master.ko
output/modules/ec_generic.ko
output/share/
output/share/bash-completion/
output/share/bash-completion/completions/
output/share/bash-completion/completions/ethercat
output/bin/
output/bin/ethercat
output/lib/
output/lib/libethercat.so
output/lib/pkgconfig/
output/lib/pkgconfig/libethercat.pc
output/lib/libethercat.so.1.2.0
output/lib/cmake/
output/lib/cmake/ethercat/
output/lib/cmake/ethercat/ethercat-config.cmake
output/lib/libethercat.a
output/lib/libethercat.la
output/lib/libethercat.so.1

将output目录下各文件目录的内容复制到板子根文件系统根目录下相应目录下,例如:cp bin/ethercat /bin/(include目录不用复制)

root@myir-remi-1g:/output# ls
bin etc include lib modules sbin share
root@myir-remi-1g:
/output# cp bin/ethercat /bin/
root@myir-remi-1g:/output# cp etc/ethercat.conf /etc/
root@myir-remi-1g:
/output# cp etc/init.d/* /etc/init.d
root@myir-remi-1g:/output# cp -r etc/sysconfig/ /etc/
root@myir-remi-1g:
/output# cp lib/libethercat.* /lib64/
root@myir-remi-1g:/output# cp -r lib/pkgconfig /lib64/
root@myir-remi-1g:
/output# cp modules/ec_master.ko /lib/modules/5.10.83-cip1-yocto-standard/
root@myir-remi-1g:~/output# cp sbin/ethercatctl /sbin/

启动EtherCAT

配置主站的MAC地址
root@myir-remi-1g:# depmod
root@myir-remi-1g:
# modprobe ec_master main_devices=1E:ED:19:27:1A:B3

启动EtherCAT
root@myir-remi-1g:~# /etc/init.d/ethercat start
Starting EtherCAT master 1.5.2 done

更多回帖

发帖
×
20
完善资料,
赚取积分