xenomai + igh配置

内容分享1周前发布
0 0 0

环境:
ubuntu24 内核6.14
dovetail版本 6.14
xenomai版本 3.3.2
igh版本 1.6.0

参考链接:
https://blog.csdn.net/ji2581072/article/details/139145356
https://www.cnblogs.com/wsg1100/p/12730720.html
https://developer.aliyun.com/article/1504341

下载安装文件

查看系统内核版本:


robot@robot:~$ uname -a
Linux robot 6.14.0-36-generic #36~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Oct 15 15:45:17 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

安装必要的工具


sudo apt install cmake make git flex bison libncurses5-dev gcc exuberant-ctags bc libssl-dev meson ninja-build libelf-dev libbpf-dev pkg-config gawk fuse

xenomai 官网:
https://xenomai.org/

下载dovetail:
下载地址:https://gitlab.com/Xenomai/linux-dovetail/
下载文件:linux-dovetail-v6.14-dovetail-rebase.tar.gz

下载xenomai:
下载地址:https://gitlab.com/Xenomai/xenomai3/xenomai/
下载文件:xenomai-v3.3.2.tar.gz

将所有压缩包解压,下文假设都放在 Downloads文件夹里

制作patch:


cd ~/Downloads/xenomai-v3.3.2/scripts/

./prepare-kernel.sh --linux=/home/robot/Downloads/linux-dovetail-v6.14-dovetail-rebase --arch=x86_64 --outpatch=/home/robot/Downloads/patch-cobalt-3.3.2.patch

cd ~/Downloads/linux-dovetail-v6.14-dovetail-rebase

patch -p1 < ../patch-cobalt-3.3.2.patch

cp /boot/config-`uname -r` .config

make menuconfig

选项:


General setup  --->
    Preemption Model (Preemptible Kernel --->
        (X) Preemptible Kernel (Low-Latency Desktop)

Processor type and features  --->
    Processor family (Generic-x86-64)  --->
        (X) Core 2/newer Xeon

    [*] Multi-core scheduler support
    [ ]   CPU core priorities scheduler support

Power management and ACPI options  --->
    CPU Frequency scaling  --->
        [ ] CPU Frequency scaling

    [*] ACPI (Advanced Configuration and Power Interface) Support  --->
        < >   Processor

    CPU Idle  --->
        [ ] CPU idle PM support

Memory Management options  --->
    [ ] Transparent Hugepage Support
    [ ] Allow for memory compaction
    [ ] Page migration
  [ ] Contiguous Memory Allocator


[*] Xenomai/cobalt (NEW)  --->
    Drivers  --->
        RTnet  --->
            <M> RTnet, TCP/IP socket interface
            
        Real-time IPC drivers  --->
          <M> RTIPC protocol family
            [*]   XDDP cross-domain datagram protocol (NEW)
            [*]   IDDP intra-domain datagram protocol (NEW)
            (32)    Number of IDDP communication ports (NEW)
            [*]   Buffer protocol (NEW)
            (32)    Number of BUFP communication ports (NEW)

注:这里配置可以在general setup 里面设置 local version,这样在启动时选择系统时更好分辨

禁用系统密钥和调试,避免编译报错


scripts/config --disable SYSTEM_TRUSTED_KEYS
scripts/config --set-str CONFIG_SYSTEM_TRUSTED_KEYS ""
scripts/config --disable SYSTEM_REVOCATION_KEYS
scripts/config --set-str CONFIG_SYSTEM_REVOCATION_KEYS ""
scripts/config --disable CONFIG_DEBUG_INFO_BTF

scripts/config --disable GDB_SCRIPTS
scripts/config --disable DEBUG_INFO
scripts/config --disable DEBUG_INFO_SPLIT
scripts/config --disable DEBUG_INFO_REDUCED
scripts/config --disable DEBUG_INFO_COMPRESSED
scripts/config --set-val DEBUG_INFO_NONE y
scripts/config --set-val DEBUG_INFO_DWARF5 n
scripts/config --disable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT

编译内核:


make -j4 bindeb-pkg

内核编译速度与电脑配置有关系,可能耗时4小时以上


# 返回上一级目录(deb 包生成在此目录)
cd ..
# 安装所有生成的 deb 包
$ sudo dpkg -i *.deb

为避免使用 Xenomai 功能时频繁输入 sudo


# 创建 xenomai 用户组
sudo addgroup xenomai
# 将 root 用户添加到 xenomai 组
sudo usermod -aG xenomai root
# 将当前用户添加到 xenomai 组
sudo usermod -aG xenomai $(whoami)
cat /etc/group | grep xenomai
# 示例输出(GID 为 1001):xenomai:x:1001:root,robot

配置 GRUB 引导选项


sudo gedit /etc/default/grub

当前只隔离第三个核


GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
#GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=10
# 核心引导参数(需将 xenomai.allowed_group 的值改为实际 GID)
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash noapic xenomai.allowed_group=1001"
GRUB_CMDLINE_LINUX=""

一步到位可尝试:


GRUB_CMDLINE_LINUX="splash audit=0 isolcpus=3 xenomai.supported_cpus=0x08 nohz_full=3 rcu_nocbs=3 irqaffinity=0,1,2 rcu_nocb_poll=1024 rcupdate.rcu_cpu_stall_suppress=1 acpi_irq_nobalance numa_balancing=disable cpufreq.off=1 nosmap nosmt  nohalt  noirqbalance hugepages=1024  i915.enable_rc6=0 i915.enable_dc=0 i915.disable_power_well=0  i915.enable_execlists=0  nmi_watchdog=0 nosoftlockup processor.max_cstate=0 intel.max_cstate=0 processor_idle.max_cstate=0 intel_idle.max_cstate=0 clocksource=tsc tsc=reliable nmi_watchdog=0 nosoftlockup intel_pstate=disable idle=poll mce=ignore_ce hpet=disable clocksource=tsc tsc=reliable nohz=off"

注:quiet 指启动的时候不输出显示启动的进程

更新 GRUB 配置并重启系统:


sudo update-grub
sudo reboot

配置 XDDP 权限(通过 udev 规则)
XDDP 是普通内核与实时内核之间的一种 IPC(进程间通信)方式,需通过 udev 规则设置其权限:


sudo gedit /etc/udev/rules.d/99-xenomai.rules

添加以下内容并保存:


KERNEL=="rtp[0-32]*", MODE="0666"(允许所有用户访问 rtp 设备节点)
SUBSYSTEM=="rtdm", MODE="0666"(允许所有用户访问 RTDM 子系统设备)

编辑 /etc/modules 文件,添加模块名称以实现开机自动加载:


sudo gedit /etc/modules

添加(XDDP 依赖的 RTIPC 模块):


xeno_rtipc

重启电脑

验证


uname -a
lsmod | grep xeno
# 示例输出:
xeno_rtipc               28672  0

安装xenomai库


# 进入 Xenomai 源码目录
cd ~/Downloads/xenomai-v3.3.2
# 初始化编译环境
./scripts/bootstrap
# 配置编译参数(启用 SMP、禁用 TLS 等)
./configure --with-pic --with-core=cobalt --enable-smp --disable-tls --enable-dlopen-libs --disable-clock-monotonic-raw
# 编译(-j4 可根据 CPU 核心数调整)
make -j4
# 安装到系统目录(默认路径 /usr/xenomai)
sudo make install

添加 Xenomai 二进制文件路径到 PATH


# 将路径添加到 .bashrc,实现终端启动时自动加载
echo "export PATH=/usr/xenomai/bin:$PATH" >> ~/.bashrc
# 立即生效当前终端的环境变量
source ~/.bashrc

配置 Xenomai 库路径:


# 创建 Xenomai 库路径配置文件
sudo gedit /etc/ld.so.conf.d/xenomai.conf
# 添加Xenomai 库所在路径:
/usr/xenomai/lib

更新系统库缓存:


sudo ldconfig

延迟测试:


sudo apt install htop stress
# 分三个终端运行:
htop
stress --cpu 4
xeno latency

结果说明:在 100 微秒的控制周期下,用户态(通过 dovetail 访问 Xenomai 内核)的延迟约为 x 微秒。若使用内核态或内核 IRQ 模式运行,可获得更优的实时性能。

安装igh

下载地址:https://gitlab.com/etherlab.org/ethercat/


./bootstrap
sudo ./configure --with-linux-dir=/home/robot/Downloads/linux-dovetail-v6.14-dovetail-rebase --enable-generic --enable-8139too=no --enable-cycles --enable-hrtimer --with-xenomai-dir=/usr/xenomai
sudo make -j4
sudo make modules -j4
sudo make install  #安装
sudo make modules_install  #安装模块

注:
在configure 的时候没有指定安装目录,(有教程会建议装在 /opt/ethercat/ 目录下),在 make install 的时候终端会显示


Libraries have been installed in:
   /usr/local/lib

配置文件调整


sudo mkdir /etc/sysconfig  #创建文件夹
sudo cp /usr/local/etc/sysconfig/ethercat /etc/sysconfig/
sudo cp /usr/local/etc/init.d/ethercat /etc/init.d/
sudo chmod a+x /etc/init.d/ethercat
sudo update-rc.d ethercat defaults

sudo gedit /etc/udev/rules.d/99-EtherCAT.rules

# 注意这个是在 igh 编译的目录里
sudo cp devices/ec_generic.ko /lib/modules/$(uname -r)
sudo cp master/ec_master.ko /lib/modules/$(uname -r)
sudo depmod

查看网卡信息


robot@robot:~$ ifconfig
enp2s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b0:42:9f:04:4c:30  txqueuelen 1000  (以太网)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xa1400000-a141ffff  

enp3s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b0:42:9f:04:4c:31  txqueuelen 1000  (以太网)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xa1300000-a131ffff 

设置网卡


# 配置网卡
sudo gedit /etc/sysconfig/ethercat
sudo gedit /usr/local/etc/sysconfig/ethercat  #这两个文件配置一样
#  在大约27行和60行处填入自己的网卡信息
MASTER0_DEVICE="b0:42:9f:04:4c:30"  
DEVICE_MODULES="generic"    
 
# 启动主站
sudo /etc/init.d/ethercat start
# 查看帮助 或者 pdo信息
sudo ethercat --h
ethercat pdos
© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
none
暂无评论...