上一篇文章介绍了制作Orangepi5制作实时内核的系统镜像方法,ethercat-igh只能运行在有实时性的linux系统上
制作适用于Orangepi5的带有preempt-rt内核的Armbian_25_小时的博客-CSDN博客
1、下载ethercat-igh主站源码
git clone https://gitlab.com/etherlab.org/ethercat.git
2、编译安装
cd ethercat
./bootstrap
./configure --enable-8139too=no
make
make modules
sudo make install
sudo make modules_install
sudo depmod
在上说过程中会出现一些错误,下面一项一项解决
错误1: 在执行 ./configure --enable-8139too=no 时会报错,内容如下
configure: error: Failed to find Linux sources. Use --with-linux-dir!
原因: 这个是由于没有安装linux源码导致的。
解决方法:可将上一篇文章中编译镜像时生成的源码安装包拿过来安装,文件路径及名称 armbian/build/output/debs/linux-headers-legacy-rockchip-rk3588_23.08.0-trunk--5.10.110-Scbae-D664a-P9b0d-C999999Hfe66-HK01ba-Vc222-B3b41_arm64.deb 源码安装后路径是/usr/src/linux-headers-5.10.110-rockchip-rk3588 然后执行
cd /usr/src/linux-headers-5.10.110-rockchip-rk3588
sudo make scripts
错误2: 在执行make modules 时会报错,内容如下
/home/cnc/work/ethercat/master/master.c: In function 'ec_master_domain_count':
/home/cnc/work/ethercat/master/master.c:2095:18: warning: passing argument 1 of 'ec_lock_down' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
error, forbidden warning:master.c:2095
2095 | ec_lock_down(&master->domains_lock);
| ^~~~~~~~~~~~~~~~~~~~~
In file included from /home/cnc/work/ethercat/master/ethernet.h:44,
from /home/cnc/work/ethercat/master/master.c:58:
/home/cnc/work/ethercat/master/locks.h:70:44: note: expected 'ec_lock_t *' {aka 'struct semaphore *'} but argument is of type 'const ec_lock_t *' {aka 'const struct semaphore *'}
70 | static inline void ec_lock_down(ec_lock_t *sem) { down(sem); }
| ~~~~~~~~~~~^~~
/home/cnc/work/ethercat/master/master.c:2099:16: warning: passing argument 1 of 'ec_lock_up' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
error, forbidden warning:master.c:2099
2099 | ec_lock_up(&master->domains_lock);
| ^~~~~~~~~~~~~~~~~~~~~
/home/cnc/work/ethercat/master/locks.h:72:42: note: expected 'ec_lock_t *' {aka 'struct semaphore *'} but argument is of type 'const ec_lock_t *' {aka 'const struct semaphore *'}
72 | static inline void ec_lock_up(ec_lock_t *sem) { up(sem); }
| ~~~~~~~~~~~^~~
make[3]: *** [scripts/Makefile.build:273: /home/cnc/work/ethercat/master/master.o] Error 1
make[3]: *** Deleting file '/home/cnc/work/ethercat/master/master.o'
make[2]: *** [scripts/Makefile.build:516: /home/cnc/work/ethercat/master] Error 2
make[1]: *** [Makefile:1917: /home/cnc/work/ethercat] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.10.110-rockchip-rk3588'
make: *** [Makefile:945: modules] Error 2
原因: 这是因为编译的时候,由于代码不符合标准,类型转换的时候,没有强制转化(比如将int型赋值给char型,需要强制转换)或者定义了某些变量或者函数却没有使用.这些都会出现警告,而警告将会被看做错误来处理。
解决方案:修改usr/src/linux-headers-5.10.110-rockchip-rk3588/scripts/gcc-wrapper.py将函数 interpret_warning(line) 的内容用pass替换掉,这样它就不会将警告当成错误处理了。
3、配置网络设备信息
使用ifconfig命令获取到网卡的mac地址,输出信息中ether开头的就是网卡MAC。
ether 91:15:a6:55:07:ac
从上面的可以看到网卡地址为: 91:15:a6:55:07:ac。
修改这个文件/usr/local/etc/sysconfig/ethercat
sudo gedit /usr/local/etc/sysconfig/ethercat
修改内容:
MASTER0_DEVICE=“91:15:a6:55:07:ac”
DEVICE_MODULES=“generic”
4、配置用户态库
cd /etc/udev/rules.d
sudo gedit 99-ethercat.rules
向文件中添加下面内容:
KERNEL==“EtherCAT[0-9]”, MODE=“0777”
然后执行下面命令,有时候不执行好像也可以。
sudo udevadm control --reload-rules
5、配置实时权限
sudo gedit /etc/security/limits.conf
-
在该文件的最下方按照如下格式添加一行:
<username> hard rtprio 99 -
比如说改成这个样子: #username hard rtprio 99
6、运行与停止主站
运行主站:
sudo /usr/local/etc/init.d/ethercat start
运行上述启动主站命令后如果显示 Starting EtherCAT master 1.6.0-rc1 done 说明主站安装成功
运行主站也可以用sudo ethercatctl start 这个命令不显示结果
停止主站:
sudo /usr/local/etc/init.d/ethercat stop
停止主站也可以用sudo ethercatctl stop