IgH Master环境搭建

目标:实时linux内核中运行IgH主站,ethercat的用户态工具能看到主站信息。

一、需要的软件

1,vbox虚拟机

https://www.virtualbox.org/,下载VirtualBox 7.0,
备注:windows中不要用wsl开发,wsl运行unbuntu后,没有grub相关的目录,update-grub无法正确更新引导分区。

2,Ubuntu 20.04

http://releases.ubuntu.com/20.04/ ,下载ubuntu-20.04.6-desktop-amd64.iso

3,rt linux

方法一,打补丁方式(本文采用的方法):
原生kernel:https://mirrors.edge.kernel.org/pub/linux/kernel/
实时补丁:https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/

方法二,下载已经打好补丁的kernel:
https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git/refs/tags

4,IgH主站

https://gitlab.com/etherlab.org/ethercat/-/branches,下载stable-1.5源码

二、运行rt linux

1,ubuntu20.04环境

vbox安装ubuntu-20.04.6-desktop-amd64.iso

2,配置ubuntu系统

参考博文,https://blog.csdn.net/geshifei/article/details/111937461

  • 若无法打开terminal,参考下面解决:

CTRL + ALT + F3 # 进入命令行模式(需要返回桌面时CTRL + ALT + F1)

root@ubuntu-20:/home/gsf# vim /etc/default/locale

把文件中的 “en_US” 改成 “en_US.UTF-8”

保存退出

root@ubuntu-20:/home/gsf# locale-gen --purge

root@ubuntu-20:/home/gsf# reboot

  • 安装编译IgH用到的工具:root@ubuntu-20:/home/gsf# apt-get install autoconf autogen libtool

3,编译rt linux

下载原生5.4.28内核(https://mirrors.edge.kernel.org/pub/linux/kernel/)
下载对应的实时补丁v5.4.28-rt19(https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/

打补丁:

root@ubuntu-20:/home/gsf/IgH# ls

linux-5.4.28.tar.gz patch-5.4.28-rt19.patch

root@ubuntu-20:/home/gsf/IgH#

解压kernel

root@ubuntu-20:/home/gsf/IgH# tar zxvf linux-5.4.28.tar.gz

打实时补丁

root@ubuntu-20:/home/gsf/IgH# cp patch-5.4.28-rt19.patch ./linux-5.4.28

root@ubuntu-20:/home/gsf/IgH# cd linux-5.4.28

root@ubuntu-20:/home/gsf/IgH/linux-5.4.28# patch -p1 < patch-5.4.28-rt19.patch

编译内核:

root@ubuntu-20:/home/gsf/IgH/linux-5.4.28# make menuconfig

General setup -> Preemption Model,选中Real-Time内核:

root@ubuntu-20:/home/gsf/IgH/linux-5.4.28# make-kpkg --rootcmd fakeroot --initrd kernel_image kernel_headers

如编译问题,参考附2。

安装内核:

root@ubuntu-20:/home/gsf/IgH/linux-5.4.28# cd ..

root@ubuntu-20:/home/gsf/IgH/linux-5.4.28# dpkg -i linux-headers-5.4.28-rt19_5.4.28-rt19-10.00.Custom_amd64.deb linux-image-5.4.28-rt19_5.4.28-rt19-10.00.Custom_amd64.deb

修改grub配置,重启ubuntu后可以选择内核::

root@ubuntu-20:/home/gsf# vim /etc/default/grub

If you change this file, run 'update-grub' afterwards to update

/boot/grub/grub.cfg.

For full documentation of the options in this file, see:

# info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0

#注释掉下面一行

#GRUB_TIMEOUT_STYLE=hidden

#默认超时值0,改成20

GRUB_TIMEOUT=20

GRUB_DISTRIBUTOR=lsb_release -i -s 2> /dev/null || echo Debian

#字符串"quiet splash"改成"text" GRUB_CMDLINE_LINUX_DEFAULT="text"

GRUB_CMDLINE_LINUX=""

root@ubuntu-20:/home/gsf# update-grub

4,启动rt linux

reboot重启系统,进入grup界面,选择刚刚编译的rt内核启动。

启动后,检查一下rt内核是否加载:

gsf@ubuntu-20:~$ uname -a

Linux ubuntu-20 5.4.28-rt19 #2 SMP PREEMPT Mon Sep 18 19:19:46 CST 2023 x86_64 x86_64 x86_64 GNU/Linux

三、运行IgH Master

1,编译IgH

https://gitlab.com/etherlab.org/ethercat/-/branches,下载ethercat-stable-1.5.tar

root@ubuntu-20:/home/gsf/IgH/ethercat-stable-1.5# ./bootstrap
root@ubuntu-20:/home/gsf/IgH/ethercat-stable-1.5# ./configure --enable-8139too=no (注:需要disable 8139too网卡,见附2)

root@ubuntu-20:/home/gsf/IgH/ethercat-stable-1.5# make all modules

root@ubuntu-20:/home/gsf/IgH/ethercat-stable-1.5# make modules_install install

root@ubuntu-20:/home/gsf/IgH/ethercat-stable-1.5# depmod

编译出来的inti脚本/usr/local/etc/init.d目录中的(不同linux发行版可能有区别,ubuntu20.04对应这个路径):

root@ubuntu-20:/home/gsf/IgH/ethercat-stable-1.5# ln -s /usr/local/etc/init.d/ethercat /etc/init.d/ethercat

root@ubuntu-20:/home/gsf/IgH/ethercat-stable-1.5#

root@ubuntu-20:/home/gsf/IgH/ethercat-stable-1.5# mkdir /etc/sysconfig

root@ubuntu-20:/home/gsf/IgH/ethercat-stable-1.5# cp /usr/local/etc/sysconfig/ethercat /etc/sysconfig/ethercat

root@ubuntu-20:/home/gsf/IgH/ethercat-stable-1.5#

2,配置ethercat device

root@ubuntu-20:/usr/local/etc/init.d# vim /etc/sysconfig/ethercat

#修改/etc/sysconfig/ethercat的两处位置

MASTER0_DEVICE="ifconfig命令看到的mac地址"

DEVICE_MODULES="generic"

3,启动IgH

root@ubuntu-20:/usr/local/etc/init.d# /etc/init.d/ethercat start

Starting EtherCAT master 1.5.2 done

如果启动出现错误,参考附3。

此时,IgH Master已经跑起来,可通过ethercat用户空间工具进行调试,比如:

附:

1,rt linux编译BTF报错

LD vmlinux.o MODPOST vmlinux.o MODINFO modules.builtin.modinfo BTF: .tmp_vmlinux.btf: pahole (pahole) is not available Failed to generate BTF for vmlinux Try to disable CONFIG_DEBUG_INFO_BTF make[1]: * [Makefile:1076: vmlinux] Error 1 make[1]: Leaving directory '/home/gsf/IgH/linux-5.4.28' make: * [debian/ruleset/targets/common.mk:301: debian/stamp/build/kernel] Error 2 root@ubuntu-20:/home/gsf/IgH/linux-5.4.28# vim .config root@ubuntu-20:/home/gsf/IgH/linux-5.4.28#

解决:config文件中关闭CONFIG_DEBUG_INFO_BTF选项。

2,IgH编译config出错

root@ubuntu-20:/home/gsf/IgH/ethercat-stable-1.5# ./configure

checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes

checking dynamic linker characteristics... (cached) GNU/Linux ld.so

checking how to hardcode library paths into programs... immediate

checking whether to build kernel modules... yes

checking for Linux kernel sources... /home/gsf/IgH/linux-5.4.28 (Kernel 5.4)

checking for Linux modules installation directory... ethercat

checking for kernel for 8139too driver... configure: error: kernel 5.4 not available for 8139too driver!

解决:当前内核不支持8139too网卡,disable掉8139too重新执行 ./configure --enable-8139too=no

3,IgH启动错误

root@ubuntu-20:/usr/local/etc/init.d# /etc/init.d/ethercat start

Starting EtherCAT master 1.5.2 modprobe: ERROR: could not insert 'ec_master': Invalid argument

failed

解决:参考“配置ethercat device”一节,修改 /etc/init.d/ethercat中的mac地址。

参考资料

  • rt linux 官网:https://wiki.linuxfoundation.org/realtime/start

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1.基于Igh-master1.5.2的多种Ethercat IO 模块及伺服电机的操作例子 2.基于Ethercat-Ighmaster二次开发库简化你的开发流程 所有源码及文档托管在码云平台,附件中有代码仓库地址 3.含有IghMaster1.5.2最新版本代码,编译脚本及安装到 最新的代码托管在: https://gitee.com/wllw7176/MyEthercat-IGH-1.5.2.git EtherCAT 1.5.2 编译及使用说明 1.交叉编译源码 源码中有内核模块编译,指令定模块目录 根据实际情况修改build_ethercat-1.5.2.sh中以下几个变量: output_dir='output' #编译输出目录 module_install_dir='module_install' #内核模块安装目录 kernel_source_dir='/mnt/fs_ext/imx6/linux-3.0.35' #内核源码目录 lib_modules_kernel_promt='3.0.35-2666-gbdde708' #内核版本号 host=arm-fsl-linux-gnueabi #交叉编译链前缀 注意要先编译内核,然后编译Ethrecat因为Ethercat依赖于内核通用网卡模块 以root用户运行./build_ethercat-1.5.2.sh #编译具体根据提示选择y/n就可以了 ---------------------------------------------------------------------------------------------------------------------------------------------- 手动安装Ethercat到ARM开发板: 2.内核模块安装 2.1 将output文件下通lib_modules_kernel_promt='3.0.35-2666-gbdde708'(build_ethercat-1.5.2.sh 中定义)放入开发板/lib/modules下 2.2 开发板中执行"depmod"命令 3. output里面的其它文件放入开发板对应位置 4. 设置参数 修改/etc/sysconfig/ethercat MASTER0_DEVICE="e4:f3:f5:c6:41:b6" #与ethercat绑定的Mac地址 DEVICE_MODULES="generic" #通用网卡就填generic,其余支持网卡换成模块名字就行 5.添加udev规则 echo KERNEL==\"EtherCAT[0-9]*\", MODE=\"0664\" > /etc/udev/rules.d/99-EtherCAT.rules 6. 启动服务 /etc/init.d/ethercat restart 出现以下信息表明移植成功 Shutting down EtherCAT master 1.5.2 done Starting EtherCAT master 1.5.2 ec_generic: Binding socket to interface 3 (eth0). done 7. 应用层测试 root@linaro-ubuntu-desktop:~# ethercat Please specify a command! Usage: ethercat [OPTIONS] [ARGUMENTS] Commands (can be abbreviated): alias Write alias addresses. config Show slave configurations. cstruct Generate slave PDO information in C language. data Output binary domain process data. debug Set the master's debug level. domains Show configured domains. download Write an SDO entry to a slave. eoe Display Ethernet over EtherCAT statictics. foe_read Read a file from a slave via FoE. foe_write Store a file on a slave via FoE. graph Output the bus topology as a graph. master Show master and Ethernet device information. pdos List Sync managers, PDO assignment and mapping. reg_read Output a slave's register contents. reg_write Write data to a slave's registers. rescan Rescan the bus. sdos List SDO dictionaries. sii_read Output a slave's SII contents. sii_write Write SII contents to a slave. slaves Display slaves on the bus. soe_read Read an SoE IDN from a slave. soe_write Write an SoE IDN to a slave. states Request application-layer states. upload Read an SDO entry from a slave. version Show version information. xml Generate slave information XML. Global options: --master -m Comma separated list of masters to select, ranges are allowed. Examples: '1,3', '5-7,9', '-3'. Default: '-' (all). --force -f Force a command. --quiet -q Output less information. --verbose -v Output more information. --help -h Show this help. Numerical values can be specified either with decimal (no prefix), octal (prefix '0') or hexadecimal (prefix '0x') base. Call 'ethercat --help' for command-specific help. 以上内容为基本的使用,进一步使用要结合ethercat说明文档和电机说明。 ---------------------------------------------------------------------------------------------------------------------------------------------- 自动安装Ethercat到ARM开发板: 将output目录复制到开发板然后运行output目录下install_to_arm.sh脚本 执行6,7步骤测试自动安装是否成功 ---------------------------------------------------------------------------------------------------------------------------------------------- 问题汇总: (1)Starting EtherCAT master 1.5.2 EtherCAT ERROR: MAC address may not be empty. FATAL: Error inserting ec_master (/lib/modules/3.0.35-2666-gbdde708-gbdbf2583/mnt/hgfs/win_linux_share/linux/download/ethercat-1.5.2/module_install/master/ec_master.ko): Invalid argument failed Mac地址为空,将对应的mac地址MASTER0_DEVICE="e4:f3:f5:c6:41:b6" (2)编译Ethercat 一定要保证所用编译器与内核与硬件平台一致,否则会出现内核模块不能使用或者其它未知问题 (3)内核源码要先编译通过,否则Ethercat模块将不能编译通过,因为Ethercat模块依赖于内核本身驱动模块。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值