ubuntu18/20:preempt-rt 补丁 + igh 主站搭建

日期:2023年11月2日

环境:工控机上新安装的 ubuntu20 系统

安装常用开发工具

步骤略:换源、更新和升级软件包、更改语言环境、安装常用软件:vscode、Typora、vim 编辑器等

sudo apt install make gcc g++ git net-tools cmake

安装 preempt-rt 补丁

下载内核和补丁

查看当前系统内核,终端执行

uname -a 

输出:

Linux robot 5.15.0-88-generic #98~20.04.1-Ubuntu SMP Mon Oct 9 16:43:45 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

内核版本5.15(其实具体是多少也不重要,尽量靠近,不靠近一般也没有问题)

Index of /pub/linux/kernel/projects/rt/ 查找可用的 rt 补丁版本。我下载的时候5.15开头的只有一个版本:5.15.137。

wget https://kernel.org/pub/linux/kernel/projects/rt/5.15/patches-5.15.137-rt71.tar.gz

下载 linux 内核,这里就下载和补丁版本一样的 到 Index of /pub/linux/kernel/v5.x/ 查找。但是,几百兆的文件 几十kb的下载速度,着急的话可以选择镜像站:

中科大镜像站:https://mirrors.ustc.edu.cn/kernel.org/
​
清华大学开源软件镜像站:https://mirrors.tuna.tsinghua.edu.cn/kernel/
​
阿里云开源镜像站:https://mirrors.aliyun.com/kernel/
​
网易开源镜像站:http://mirrors.163.com/kernel/
​
华为开发者社区:https://developer.huawei.com/consumer/cn/openSource/topic/2021-kernel

这里选用清华源,终端执行

wget https://mirrors.tuna.tsinghua.edu.cn/kernel/v5.x/linux-5.15.137.tar.gz

解压

先解压内核,再把补丁拷贝进内核目录

tar -xvf linux-5.15.137.tar.gz
tar -xvf patches-5.15.137-rt71.tar.gz
mv patches linux-5.15.137
cd linux-5.15.137/

合并补丁

将patches解压出来的文件合并。在终端粘贴下列命令

#!/bin/sh
cat ./patches/series | while read line
do
    patch -p1 < ./patches/$line
done

配置内核

注意,这里拷贝的内容与一开始 uname -a 指令查看的东西一致

sudo chrt 10 bash
make mrproper
cp /boot/config-5.15.0-88-generic .config

安装依赖包

sudo apt-get install libncurses-dev bison flex bc libelf-dev zstd
sudo apt-get install libssl-dev dwarves

进入菜单配置界面

make menuconfig

image-20231102132352095

进入“General setup”, 在"Preemption Model"中选择“Fully Preemptible Kernel(Real-Time)”

这里按 enter 键或者空格键会先保存好然后返回上一层,然后再用方向右键移到 exit 那里,然后返回上一层,找到 Device Drivers。

找到staging drivers ,(在比较后面,慢慢找),然后按空格键,把它去掉。

回到主目录,找到 Cryptographic API

  1. 在列表的最底部找到 Certificates for signature checking

  2. Provide system-wide ring of trusted keys

  3. Additional X.509 keys for default system keyring

  4. 从提示符中移除 “debian/canonical-certs.pem”,然后按OK。将此配置保存到 .config 并退出 TUI。

然后save 、exit。

可以使用lscpu指令查看当前cpu的逻辑核心数:4

lscpu
架构:           x86_64
CPU 运行模式:   32-bit, 64-bit
字节序:         Little Endian
CPU:             4
在线 CPU 列表:  0-3
每个核的线程数: 2
每个座的核数:   2
座:             1
NUMA 节点:      1
厂商 ID:        GenuineIntel
CPU 系列:       6
型号:           69
型号名称:       Intel(R) Core(TM) i5-4250U CPU @ 1.30GHz
步进:           1
CPU MHz:        2294.841
CPU 最大 MHz:   2600.0000
CPU 最小 MHz:   800.0000
BogoMIPS:       3791.50
虚拟化:         VT-x
L1d 缓存:       32K
L1i 缓存:       32K
L2 缓存:        256K
L3 缓存:        3072K
NUMA 节点0 CPU: 0-3

执行下面的指令,其中,'getconf_NPROCESSORS_ONLN' 表示内核数量是多少个。编译内核的操作会比较耗时,所以尽可能的开启多个逻辑核同时编译,可以减少编译时间。

make -j$(getconf _NPROCESSORS_ONLN)
## 或者  make -j4
## 安装内核模块
make modules_install 
## 安装内核
make install  
  1. 如果其中出现报错:make[1]: *** 没有规则可制作目标“debian/canonical-certs.pem”,由“certs/x509_certificate_list” 需求。 停止。解决方法:编辑.config文件,把下面的变量设置为

gedit .config
 
CONFIG_SYSTEM_TRUSTED_KEYS=""
CONFIG_SYSTEM_REVOCATION_KEYS=""
  1. 报错: * Missing file: arch/x86/boot/bzImage * You need to run "make" before "make install".

解决方法:执行 make bzImage。

查看编译后的内核大小:

du -sh
 
28G	.

(28g。。。)

修改 grub 启动配置文件

安装完内核之后,再手动更新一下grub。

update-grub

gedit编辑 /etc/default/grub 文件,改动三处:

将 "GRUB_TIMEOUT_STYLE=hidden" 注释掉(在前面加上“#”)。

将 "GRUB_TIMEOUT" 的值改为“10”。

将 "GRUB_CMDLINE_LINUX_DEFAULT" 的值改为“text”。

GRUB_DEFAULT="1>2" %1代表默认启动内核,2代表所启动内核位于列表中第2个(序号从0开始)

再更新一遍配置文件

update-grub

测试

reboot 重启后进入 GRUB 界面,选择带 rt 标识的系统。查看一下系统信息是否改变。

uname -a
Linux robot 5.15.137-rt71 #2 SMP PREEMPT_RT Thu Nov 2 17:04:43 CST 2023 x86_64 x86_64 x86_64 GNU/Linux

安装 rt-test

压力测试

安装压力测试工具和 CPU状态查看、温度查看工具等

sudo apt install -y stress htop psensor

安装 rt-tests

sudo apt install rt-tests

使用方法:

T: 0 序号为0的线程 P: 0 线程优先级为0 C: 9397 计数器。线程的时间间隔每达到一次,计数器加1 I: 1000 时间间隔为1000微秒(us) Min: 最小延时(us) Act: 最近一次的延时(us) Avg: 平均延时(us) Max: 最大延时(us)

查看自己 cpu 的内核数量,我这里是 4。先开好3个以上的终端,分别执行:

sudo cyclictest -t 4 -p 90 # 开四个线程,优先级为 90 ,数量和 cpu 核心数量一致
stress --cpu 4 # 数量与 cpu 核心数量一致
htop

cpu 温度在七十多,跑了两个小时左右,最大延迟 500微秒左右。

安装 igh 主站

下载、编译源码并安装

sudo apt install -y autoconf libtool libtool-bin
mkdir ec_igh && cd ec_igh
git clone https://gitlab.com/etherlab.org/ethercat.git
cd ethercat 
sudo ./bootstrap

可以先执行 sudo ./configure --help 查看所有选项,再根据自己的需要填参数。这里根据自己的需要,禁用 8139too 驱动,使用 CPU 时间戳计数器,对调度使用高精度计时器,安装目录更改为 /opt/etherlab (默认是 /usr/local,最好不要改,我这里是个人习惯),指定linux模块的安装路径(不指定也没关系,一样的)

sudo ./configure --enable-8139too=no --enable-cycles --enable-hrtimer --prefix=/opt/etherlab --with-module-dir=/usr/lib/modules/5.15.137-rt71 

环境检查完成,没有报错就可以往下执行编译安装。

sudo make
sudo make modules
sudo make install
sudo make modules_install 
  • 在 make install 的过程中,会输出打印 etherlab 的安装位置和一些说明:

  • Libraries have been installed in:
       /opt/etherlab/lib
    
    If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the '-LLIBDIR' flag during linking and do at least one of the following:
       - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the 'LD_RUN_PATH' environment variable
         during linking
       - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to '/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages.

    意思是,etherlab 的库安装到 /opt/etherlab/lib 。(如果不指定安装路径,默认安装到 /usr/local/lib )。如果要链接该库,需要配置 LD_LIBRARY_PATH 、LD_RUN_PATH 这两个环境变量。还要使用 -Wl,-rpath -Wl,LIBDIR 这些链接标志位。并在 /etc/ld.so.conf 文件增加相关路径。因此安装好后要有相应配置。

    • 在 make modules_install 时出现 arch/x86/Makefile:142: CONFIG_X86_X32 enabled but no binutils support 的提示,(但不是报错也不是警告,也许可以不管)。执行指令: sudo apt install binutils 显示已经安装了这个工具。

      一个可能的解决方法,(但我没试,因为下载速度太慢,到 99% 的时候突然段错误了。。。)到 Index of /gnu/binutils 下载新的。

      wget http://ftp.gnu.org/gnu/binutils/binutils-2.34.tar.gz
      tar -xzvf binutils-2.34.tar.gz
      cd binutils-2.34
      ./configure
      sudo make
      ld --version
      as --version
一些过程记录:
robot@robot:~/ec_igh/ethercat$ sudo ./configure --enable-8139too=no --enable-cycles --enable-hrtimer --prefix=/opt/etherlab --with-module-dir=/usr/lib/modules/5.15.137-rt71 
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
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... /usr/bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.27... yes
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for ar... ar
checking the archiver (ar) interface... ar
checking for g++... no
checking for c++... no
checking for gpp... no
checking for aCC... no
checking for CC... no
checking for cxx... no
checking for cc++... no
checking for cl.exe... no
checking for FCC... no
checking for KCC... no
checking for RCC... no
checking for xlC_r... no
checking for xlC... no
checking whether we are using the GNU C++ compiler... no
checking whether g++ accepts -g... no
checking dependency style of g++... none
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking whether to build kernel modules... yes
checking for Linux kernel sources... /home/robot/linux-5.15.137 (Kernel 5.15)
checking for Linux modules installation directory... /usr/lib/modules/5.15.137-rt71
checking whether to build the CCAT driver... no
checking for RTAI path... not specified.
checking for Xenomai path... not specified.
checking whether to build RTDM interface... no
checking whether to build the debug interface... no
checking whether to build the debug ring... no
checking whether to build with EoE support... yes
checking whether to use the CPU timestamp counter... yes
checking whether to use rtmutexes... no
checking whether to use high-resolution timers for scheduling... yes
checking whether to read alias addresses from registers... no
checking whether to force the reference clock to OP... no
checking whether to build the command-line tool... yes
checking whether to build the userspace library... yes
checking whether to build the tty driver... no
checking whether to allow identification wildcards... no
checking for number of Ethernet devices... 1 (Redundancy disabled)
checking whether to assign the SII to PDI... yes
checking whether to syslog in realtime context... yes
checking whether to use loop control registers... no
checking whether to skip SDO dictionary during slave scan... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Doxyfile
config.status: creating Kbuild
config.status: creating Makefile
config.status: creating devices/Kbuild
config.status: creating devices/Makefile
config.status: creating devices/ccat/Kbuild
config.status: creating devices/ccat/Makefile
config.status: creating devices/e1000/Kbuild
config.status: creating devices/e1000/Makefile
config.status: creating devices/e1000e/Kbuild
config.status: creating devices/e1000e/Makefile
config.status: creating devices/igb/Kbuild
config.status: creating devices/igb/Makefile
config.status: creating ethercat.spec
config.status: creating examples/Kbuild
config.status: creating examples/Makefile
config.status: creating examples/dc_rtai/Kbuild
config.status: creating examples/dc_rtai/Makefile
config.status: creating examples/dc_user/Makefile
config.status: creating examples/mini/Kbuild
config.status: creating examples/mini/Makefile
config.status: creating examples/rtai/Kbuild
config.status: creating examples/rtai/Makefile
config.status: creating examples/rtai_rtdm/Makefile
config.status: creating examples/rtai_rtdm_dc/Makefile
config.status: creating examples/tty/Kbuild
config.status: creating examples/tty/Makefile
config.status: creating examples/user/Makefile
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 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
robot@robot:~/ec_igh/ethercat$ sudo make -j4
make  all-recursive
make[1]: 进入目录“/home/robot/ec_igh/ethercat”
Making all in include
make[2]: 进入目录“/home/robot/ec_igh/ethercat/include”
make[2]: 对“all”无需做任何事。
make[2]: 离开目录“/home/robot/ec_igh/ethercat/include”
Making all in script
make[2]: 进入目录“/home/robot/ec_igh/ethercat/script”
/usr/bin/mkdir -p init.d && \
/usr/bin/sed -e 's,[@]VERSION[@],1.6.0-rc1,g' -e 's,[@]bindir[@],/opt/etherlab/bin,g' -e 's,[@]sbindir[@],/opt/etherlab/sbin,g' -e 's,[@]sysconfdir[@],/opt/etherlab/etc,g' < init.d/ethercat.in > init.d/ethercat
/usr/bin/sed -e 's,[@]VERSION[@],1.6.0-rc1,g' -e 's,[@]bindir[@],/opt/etherlab/bin,g' -e 's,[@]sbindir[@],/opt/etherlab/sbin,g' -e 's,[@]sysconfdir[@],/opt/etherlab/etc,g' < ethercatctl.in > ethercatctl
/usr/bin/sed -e 's,for use with ethercatctl,for use with init.d,g' < ethercat.conf > ethercat
/usr/bin/sed -e 's,[@]VERSION[@],1.6.0-rc1,g' -e 's,[@]bindir[@],/opt/etherlab/bin,g' -e 's,[@]sbindir[@],/opt/etherlab/sbin,g' -e 's,[@]sysconfdir[@],/opt/etherlab/etc,g' < ethercat.service.in > ethercat.service
make[2]: 离开目录“/home/robot/ec_igh/ethercat/script”
Making all in devices
make[2]: 进入目录“/home/robot/ec_igh/ethercat/devices”
Making all in ccat
make[3]: 进入目录“/home/robot/ec_igh/ethercat/devices/ccat”
make[3]: 对“all”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/devices/ccat”
Making all in e1000
make[3]: 进入目录“/home/robot/ec_igh/ethercat/devices/e1000”
make[3]: 对“all”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/devices/e1000”
Making all in e1000e
make[3]: 进入目录“/home/robot/ec_igh/ethercat/devices/e1000e”
make[3]: 对“all”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/devices/e1000e”
Making all in igb
make[3]: 进入目录“/home/robot/ec_igh/ethercat/devices/igb”
make[3]: 对“all”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/devices/igb”
make[3]: 进入目录“/home/robot/ec_igh/ethercat/devices”
make[3]: 对“all-am”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/devices”
make[2]: 离开目录“/home/robot/ec_igh/ethercat/devices”
Making all in master
make[2]: 进入目录“/home/robot/ec_igh/ethercat/master”
make[2]: 对“all”无需做任何事。
make[2]: 离开目录“/home/robot/ec_igh/ethercat/master”
Making all in tool
make[2]: 进入目录“/home/robot/ec_igh/ethercat/tool”
  CXX      ethercat-Command.o
  CXX      ethercat-CommandAlias.o
  CXX      ethercat-CommandCrc.o
  CXX      ethercat-CommandCStruct.o
  CXX      ethercat-CommandConfig.o
  CXX      ethercat-CommandData.o
  CXX      ethercat-CommandDebug.o
  CXX      ethercat-CommandDomains.o
  CXX      ethercat-CommandDownload.o
  CXX      ethercat-CommandFoeRead.o
  CXX      ethercat-CommandFoeWrite.o
  CXX      ethercat-CommandGraph.o
  CXX      ethercat-CommandMaster.o
  CXX      ethercat-CommandPdos.o
  CXX      ethercat-CommandRegRead.o
  CXX      ethercat-CommandRegWrite.o
  CXX      ethercat-CommandRescan.o
  CXX      ethercat-CommandSdos.o
  CXX      ethercat-CommandSiiRead.o
  CXX      ethercat-CommandSiiWrite.o
  CXX      ethercat-CommandSlaves.o
  CXX      ethercat-CommandSoeRead.o
  CXX      ethercat-CommandSoeWrite.o
  CXX      ethercat-CommandStates.o
  CXX      ethercat-CommandUpload.o
  CXX      ethercat-CommandVersion.o
  CXX      ethercat-CommandXml.o
  CXX      ethercat-DataTypeHandler.o
  CXX      ethercat-FoeCommand.o
  CXX      ethercat-MasterDevice.o
  CXX      ethercat-NumberListParser.o
  CXX      ethercat-SdoCommand.o
  CXX      ethercat-SoeCommand.o
  CXX      ethercat-main.o
  CXX      ethercat-sii_crc.o
  CXX      ethercat-CommandEoe.o
  CXX      ethercat-CommandIp.o
  CXXLD    ethercat
make[2]: 离开目录“/home/robot/ec_igh/ethercat/tool”
Making all in lib
make[2]: 进入目录“/home/robot/ec_igh/ethercat/lib”
  CC       libethercat_la-common.lo
  CC       libethercat_la-domain.lo
  CC       libethercat_la-master.lo
  CC       libethercat_la-reg_request.lo
  CC       libethercat_la-sdo_request.lo
  CC       libethercat_la-slave_config.lo
  CC       libethercat_la-voe_handler.lo
  CCLD     libethercat.la
/usr/bin/sed -e 's,%libdir%,/opt/etherlab/lib,' -e 's,%includedir%,/opt/etherlab/include,' ethercat-config.cmake.in > ethercat-config.cmake
make[2]: 离开目录“/home/robot/ec_igh/ethercat/lib”
Making all in examples
make[2]: 进入目录“/home/robot/ec_igh/ethercat/examples”
Making all in dc_user
make[3]: 进入目录“/home/robot/ec_igh/ethercat/examples/dc_user”
  CC       ec_dc_user_example-main.o
  CCLD     ec_dc_user_example
make[3]: 离开目录“/home/robot/ec_igh/ethercat/examples/dc_user”
Making all in user
make[3]: 进入目录“/home/robot/ec_igh/ethercat/examples/user”
  CC       ec_user_example-main.o
  CCLD     ec_user_example
make[3]: 离开目录“/home/robot/ec_igh/ethercat/examples/user”
make[3]: 进入目录“/home/robot/ec_igh/ethercat/examples”
make[3]: 对“all-am”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/examples”
make[2]: 离开目录“/home/robot/ec_igh/ethercat/examples”
make[2]: 进入目录“/home/robot/ec_igh/ethercat”
make[2]: 离开目录“/home/robot/ec_igh/ethercat”
make[1]: 离开目录“/home/robot/ec_igh/ethercat”
robot@robot:~/ec_igh/ethercat$ sudo make modules
make -C "/home/robot/linux-5.15.137" M="/home/robot/ec_igh/ethercat" INSTALL_MOD_DIR="/usr/lib/modules/5.15.137-rt71" modules
make[1]: 进入目录“/home/robot/linux-5.15.137”
  CC [M]  /home/robot/ec_igh/ethercat/examples/mini/mini.o
  LD [M]  /home/robot/ec_igh/ethercat/examples/mini/ec_mini.o
  CC [M]  /home/robot/ec_igh/ethercat/master/cdev.o
  CC [M]  /home/robot/ec_igh/ethercat/master/coe_emerg_ring.o
  CC [M]  /home/robot/ec_igh/ethercat/master/datagram.o
  CC [M]  /home/robot/ec_igh/ethercat/master/datagram_pair.o
  CC [M]  /home/robot/ec_igh/ethercat/master/device.o
  CC [M]  /home/robot/ec_igh/ethercat/master/domain.o
  CC [M]  /home/robot/ec_igh/ethercat/master/flag.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fmmu_config.o
  CC [M]  /home/robot/ec_igh/ethercat/master/foe_request.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_change.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_coe.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_foe.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_master.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_pdo.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_pdo_entry.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_sii.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_slave.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_slave_config.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_slave_scan.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_soe.o
  CC [M]  /home/robot/ec_igh/ethercat/master/ioctl.o
  CC [M]  /home/robot/ec_igh/ethercat/master/mailbox.o
  CC [M]  /home/robot/ec_igh/ethercat/master/master.o
/home/robot/ec_igh/ethercat/master/master.c: In function ‘ec_master_domain_count’:
/home/robot/ec_igh/ethercat/master/master.c:2109:18: warning: passing argument 1 of ‘ec_lock_down’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
 2109 |     ec_lock_down(&master->domains_lock);
      |                  ^~~~~~~~~~~~~~~~~~~~~
In file included from /home/robot/ec_igh/ethercat/master/ethernet.h:44,
                 from /home/robot/ec_igh/ethercat/master/master.c:58:
/home/robot/ec_igh/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/robot/ec_igh/ethercat/master/master.c:2113:16: warning: passing argument 1 of ‘ec_lock_up’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
 2113 |     ec_lock_up(&master->domains_lock);
      |                ^~~~~~~~~~~~~~~~~~~~~
In file included from /home/robot/ec_igh/ethercat/master/ethernet.h:44,
                 from /home/robot/ec_igh/ethercat/master/master.c:58:
/home/robot/ec_igh/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); }
      |                               ~~~~~~~~~~~^~~
  CC [M]  /home/robot/ec_igh/ethercat/master/module.o
  CC [M]  /home/robot/ec_igh/ethercat/master/pdo.o
  CC [M]  /home/robot/ec_igh/ethercat/master/pdo_entry.o
  CC [M]  /home/robot/ec_igh/ethercat/master/pdo_list.o
  CC [M]  /home/robot/ec_igh/ethercat/master/reg_request.o
  CC [M]  /home/robot/ec_igh/ethercat/master/sdo.o
  CC [M]  /home/robot/ec_igh/ethercat/master/sdo_entry.o
  CC [M]  /home/robot/ec_igh/ethercat/master/sdo_request.o
  CC [M]  /home/robot/ec_igh/ethercat/master/slave.o
  CC [M]  /home/robot/ec_igh/ethercat/master/slave_config.o
  CC [M]  /home/robot/ec_igh/ethercat/master/soe_errors.o
  CC [M]  /home/robot/ec_igh/ethercat/master/soe_request.o
  CC [M]  /home/robot/ec_igh/ethercat/master/sync.o
  CC [M]  /home/robot/ec_igh/ethercat/master/sync_config.o
  CC [M]  /home/robot/ec_igh/ethercat/master/voe_handler.o
  CC [M]  /home/robot/ec_igh/ethercat/master/dict_request.o
  CC [M]  /home/robot/ec_igh/ethercat/master/eoe_request.o
  CC [M]  /home/robot/ec_igh/ethercat/master/fsm_eoe.o
  CC [M]  /home/robot/ec_igh/ethercat/master/ethernet.o
  LD [M]  /home/robot/ec_igh/ethercat/master/ec_master.o
  CC [M]  /home/robot/ec_igh/ethercat/devices/generic.o
  LD [M]  /home/robot/ec_igh/ethercat/devices/ec_generic.o
  MODPOST /home/robot/ec_igh/ethercat/Module.symvers
  CC [M]  /home/robot/ec_igh/ethercat/devices/ec_generic.mod.o
  LD [M]  /home/robot/ec_igh/ethercat/devices/ec_generic.ko
  CC [M]  /home/robot/ec_igh/ethercat/examples/mini/ec_mini.mod.o
  LD [M]  /home/robot/ec_igh/ethercat/examples/mini/ec_mini.ko
  CC [M]  /home/robot/ec_igh/ethercat/master/ec_master.mod.o
  LD [M]  /home/robot/ec_igh/ethercat/master/ec_master.ko
make[1]: 离开目录“/home/robot/linux-5.15.137”
robot@robot:~/ec_igh/ethercat$ sudo make install
Making install in include
make[1]: 进入目录“/home/robot/ec_igh/ethercat/include”
make[2]: 进入目录“/home/robot/ec_igh/ethercat/include”
make[2]: 对“install-exec-am”无需做任何事。
 /usr/bin/mkdir -p '/opt/etherlab/include'
 /usr/bin/install -c -m 644 ecrt.h ectty.h '/opt/etherlab/include'
make[2]: 离开目录“/home/robot/ec_igh/ethercat/include”
make[1]: 离开目录“/home/robot/ec_igh/ethercat/include”
Making install in script
make[1]: 进入目录“/home/robot/ec_igh/ethercat/script”
make[2]: 进入目录“/home/robot/ec_igh/ethercat/script”
 /usr/bin/mkdir -p '/opt/etherlab/etc'
 /usr/bin/install -c -m 644 ethercat.conf '/opt/etherlab/etc'
 /usr/bin/mkdir -p '/opt/etherlab/sbin'
 /usr/bin/install -c ethercatctl '/opt/etherlab/sbin'
 /usr/bin/mkdir -p '/opt/etherlab/share/bash-completion/completions'
 /usr/bin/install -c -m 644 ethercat.bash_completion '/opt/etherlab/share/bash-completion/completions'
 /usr/bin/mkdir -p '/opt/etherlab/etc/init.d'
 /usr/bin/install -c init.d/ethercat '/opt/etherlab/etc/init.d'
 /usr/bin/mkdir -p '/opt/etherlab/etc/sysconfig'
 /usr/bin/install -c -m 644 ethercat '/opt/etherlab/etc/sysconfig'
 /usr/bin/mkdir -p '/lib/systemd/system'
 /usr/bin/install -c -m 644 ethercat.service '/lib/systemd/system'
make  install-data-hook
make[3]: 进入目录“/home/robot/ec_igh/ethercat/script”
cd /opt/etherlab/share/bash-completion/completions; \
    mv ethercat.bash_completion ethercat
make[3]: 离开目录“/home/robot/ec_igh/ethercat/script”
make[2]: 离开目录“/home/robot/ec_igh/ethercat/script”
make[1]: 离开目录“/home/robot/ec_igh/ethercat/script”
Making install in devices
make[1]: 进入目录“/home/robot/ec_igh/ethercat/devices”
Making install in ccat
make[2]: 进入目录“/home/robot/ec_igh/ethercat/devices/ccat”
make[3]: 进入目录“/home/robot/ec_igh/ethercat/devices/ccat”
make[3]: 对“install-exec-am”无需做任何事。
make[3]: 对“install-data-am”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/devices/ccat”
make[2]: 离开目录“/home/robot/ec_igh/ethercat/devices/ccat”
Making install in e1000
make[2]: 进入目录“/home/robot/ec_igh/ethercat/devices/e1000”
make[3]: 进入目录“/home/robot/ec_igh/ethercat/devices/e1000”
make[3]: 对“install-exec-am”无需做任何事。
make[3]: 对“install-data-am”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/devices/e1000”
make[2]: 离开目录“/home/robot/ec_igh/ethercat/devices/e1000”
Making install in e1000e
make[2]: 进入目录“/home/robot/ec_igh/ethercat/devices/e1000e”
make[3]: 进入目录“/home/robot/ec_igh/ethercat/devices/e1000e”
make[3]: 对“install-exec-am”无需做任何事。
make[3]: 对“install-data-am”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/devices/e1000e”
make[2]: 离开目录“/home/robot/ec_igh/ethercat/devices/e1000e”
Making install in igb
make[2]: 进入目录“/home/robot/ec_igh/ethercat/devices/igb”
make[3]: 进入目录“/home/robot/ec_igh/ethercat/devices/igb”
make[3]: 对“install-exec-am”无需做任何事。
make[3]: 对“install-data-am”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/devices/igb”
make[2]: 离开目录“/home/robot/ec_igh/ethercat/devices/igb”
make[2]: 进入目录“/home/robot/ec_igh/ethercat/devices”
make[3]: 进入目录“/home/robot/ec_igh/ethercat/devices”
make[3]: 对“install-exec-am”无需做任何事。
make[3]: 对“install-data-am”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/devices”
make[2]: 离开目录“/home/robot/ec_igh/ethercat/devices”
make[1]: 离开目录“/home/robot/ec_igh/ethercat/devices”
Making install in master
make[1]: 进入目录“/home/robot/ec_igh/ethercat/master”
make[2]: 进入目录“/home/robot/ec_igh/ethercat/master”
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/home/robot/ec_igh/ethercat/master”
make[1]: 离开目录“/home/robot/ec_igh/ethercat/master”
Making install in tool
make[1]: 进入目录“/home/robot/ec_igh/ethercat/tool”
make[2]: 进入目录“/home/robot/ec_igh/ethercat/tool”
 /usr/bin/mkdir -p '/opt/etherlab/bin'
  /bin/bash ../libtool   --mode=install /usr/bin/install -c ethercat '/opt/etherlab/bin'
libtool: install: /usr/bin/install -c ethercat /opt/etherlab/bin/ethercat
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/home/robot/ec_igh/ethercat/tool”
make[1]: 离开目录“/home/robot/ec_igh/ethercat/tool”
Making install in lib
make[1]: 进入目录“/home/robot/ec_igh/ethercat/lib”
make[2]: 进入目录“/home/robot/ec_igh/ethercat/lib”
 /usr/bin/mkdir -p '/opt/etherlab/lib'
 /bin/bash ../libtool   --mode=install /usr/bin/install -c   libethercat.la '/opt/etherlab/lib'
libtool: install: /usr/bin/install -c .libs/libethercat.so.1.1.0 /opt/etherlab/lib/libethercat.so.1.1.0
libtool: install: (cd /opt/etherlab/lib && { ln -s -f libethercat.so.1.1.0 libethercat.so.1 || { rm -f libethercat.so.1 && ln -s libethercat.so.1.1.0 libethercat.so.1; }; })
libtool: install: (cd /opt/etherlab/lib && { ln -s -f libethercat.so.1.1.0 libethercat.so || { rm -f libethercat.so && ln -s libethercat.so.1.1.0 libethercat.so; }; })
libtool: install: /usr/bin/install -c .libs/libethercat.lai /opt/etherlab/lib/libethercat.la
libtool: install: /usr/bin/install -c .libs/libethercat.a /opt/etherlab/lib/libethercat.a
libtool: install: chmod 644 /opt/etherlab/lib/libethercat.a
libtool: install: ranlib /opt/etherlab/lib/libethercat.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/sbin" ldconfig -n /opt/etherlab/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /opt/etherlab/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the 'LD_RUN_PATH' environment variable
     during linking
   - use the '-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to '/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
 /usr/bin/mkdir -p '/opt/etherlab/lib/cmake/ethercat'
 /usr/bin/install -c -m 644 ethercat-config.cmake '/opt/etherlab/lib/cmake/ethercat'
 /usr/bin/mkdir -p '/opt/etherlab/lib/pkgconfig'
 /usr/bin/install -c -m 644 libethercat.pc '/opt/etherlab/lib/pkgconfig'
make[2]: 离开目录“/home/robot/ec_igh/ethercat/lib”
make[1]: 离开目录“/home/robot/ec_igh/ethercat/lib”
Making install in examples
make[1]: 进入目录“/home/robot/ec_igh/ethercat/examples”
Making install in dc_user
make[2]: 进入目录“/home/robot/ec_igh/ethercat/examples/dc_user”
make[3]: 进入目录“/home/robot/ec_igh/ethercat/examples/dc_user”
make[3]: 对“install-exec-am”无需做任何事。
make[3]: 对“install-data-am”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/examples/dc_user”
make[2]: 离开目录“/home/robot/ec_igh/ethercat/examples/dc_user”
Making install in user
make[2]: 进入目录“/home/robot/ec_igh/ethercat/examples/user”
make[3]: 进入目录“/home/robot/ec_igh/ethercat/examples/user”
make[3]: 对“install-exec-am”无需做任何事。
make[3]: 对“install-data-am”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/examples/user”
make[2]: 离开目录“/home/robot/ec_igh/ethercat/examples/user”
make[2]: 进入目录“/home/robot/ec_igh/ethercat/examples”
make[3]: 进入目录“/home/robot/ec_igh/ethercat/examples”
make[3]: 对“install-exec-am”无需做任何事。
make[3]: 对“install-data-am”无需做任何事。
make[3]: 离开目录“/home/robot/ec_igh/ethercat/examples”
make[2]: 离开目录“/home/robot/ec_igh/ethercat/examples”
make[1]: 离开目录“/home/robot/ec_igh/ethercat/examples”
make[1]: 进入目录“/home/robot/ec_igh/ethercat”
make[2]: 进入目录“/home/robot/ec_igh/ethercat”
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/home/robot/ec_igh/ethercat”
make[1]: 离开目录“/home/robot/ec_igh/ethercat”
robot@robot:~/ec_igh/ethercat$ sudo make modules_install
make -C "/home/robot/linux-5.15.137" M="/home/robot/ec_igh/ethercat" INSTALL_MOD_DIR="/usr/lib/modules/5.15.137-rt71" modules_install
make[1]: 进入目录“/home/robot/linux-5.15.137”
arch/x86/Makefile:142: CONFIG_X86_X32 enabled but no binutils support
  INSTALL /lib/modules/5.15.137-rt71//usr/lib/modules/5.15.137-rt71/devices/ec_generic.ko
  SIGN    /lib/modules/5.15.137-rt71//usr/lib/modules/5.15.137-rt71/devices/ec_generic.ko
  INSTALL /lib/modules/5.15.137-rt71//usr/lib/modules/5.15.137-rt71/examples/mini/ec_mini.ko
  SIGN    /lib/modules/5.15.137-rt71//usr/lib/modules/5.15.137-rt71/examples/mini/ec_mini.ko
  INSTALL /lib/modules/5.15.137-rt71//usr/lib/modules/5.15.137-rt71/master/ec_master.ko
  SIGN    /lib/modules/5.15.137-rt71//usr/lib/modules/5.15.137-rt71/master/ec_master.ko
  DEPMOD  /lib/modules/5.15.137-rt71
make[1]: 离开目录“/home/robot/linux-5.15.137”

环境配置

执行指令:

libtool --finish /opt/etherlab/lib

先 ifconfig 查看网卡的信息,然后进入到 etherlab 的安装位置,master0_device 根据实际情况填。

ifconfig
cd /opt/etherlab 
sudo gedit etc/sysconfig/ethercat
 
MASTER0_DEVICE="00:e8:4c:68:30:dd"
DEVICE_MODULES="generic"

sudo mkdir -p /etc/sysconfig/
sudo cp etc/sysconfig/ethercat /etc/sysconfig/
sudo ln -s /opt/etherlab/etc/init.d/ethercat /etc/init.d/
 
sudo /etc/init.d/ethercat start

可以看到输出

Starting EtherCAT master 1.6.0-rc1  done

就说明 igh 主站可以正常执行。

新开个终端,执行输入指令:ethercat,如果输出了一大堆东西,而不是说指令找不到,说明命令行工具已经添加。如果不是,执行:

gedit ~/.bashrc
PATH=$PATH:/opt/etherlab/bin
source ~/.bashrc
sudo depmod

程序测试

快速测试:从下载的 etherlab 源码里面,找到 examples 文件夹的 user 文件夹,将其拷贝出来。删掉目录中的所有文件,只保留 main.cpp 和 CMakeLists.txt。直接编译:

mkdir build && cd build
cmake ..
make 
sudo su
./userexample

编译没有报错,执行也没有报错。

后续可以先基于这个 main 函数写测试程序:修改 pdo 配置、填写 cyclic_task 函数、通过 sched_setscheduler 调整线程优先级。

  • 7
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值