igh+preempt_rt main battle building

Keywords: Linux ethercat

catalogue

one, Kernel compilation and installation

1. Download relevant data package

2. Decompression

3. Merge patches

4. Kernel configuration

Modify grub startup profile

Reference link  

1, Kernel compilation and installation

1. Download relevant data package

The current environment is Ubuntu 18.04. The ROS melody environment has been installed. Check the current system kernel version first

uname -a

obtain:

Linux robotarm 5.4.0-89-generic #100~18.04.1-Ubuntu SMP Wed Sep 29 10:59:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Download the patch, and the kernel version is consistent with the patch version.

Patch download address: https://www.kernel.org/pub/linux/kernel/projects/rt/
Kernel address: http://www.kernel.org/pub/linux/kernel/ 

patches-5.4.154-rt65.tar.gz                        20-Oct-2021 15:15    389
linux-5.4.154.tar.gz                               17-Oct-2021 08:48    163M2,

2. Decompression

Unzip the kernel first, and then copy the patch into the kernel directory

tar -xvf linux-5.4.154.tar.gz
tar -xvf patches-5.4.154-rt65.tar.gz 
mv patches linux-5.4.154
cd linux-5.4.154

3. Merge patches

Merge the files extracted from the patches

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

4. Kernel configuration

sudo chrt 10 bash
make mrproper
cp /boot/config-5.4.0-89-generic .config

Install dependent packages

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

Enter menu configuration interface

make menuconfig

  Enter "General setup" and select "full preemptible kernel (real time)" in "Preemption Model"

  Press enter here to save it, then return to the previous layer, then right-click to exit, and then return to the previous layer to find Device Drivers

  Find the staging drivers, (after the comparison, find it slowly), and then press the spacebar to remove it.

   Then save and exit.

You can use the lscpu instruction to view the number of logical cores of the current cpu: 4

lscpu
 framework:           x86_64
CPU Operating mode: 32-bit, 64-bit
 Byte order:         Little Endian
CPU:             4
 on-line CPU List: 0-3
 Threads per core: 2
 Number of cores per seat: 2
 Seat:             1
NUMA Node:      1
 manufacturer ID:         GenuineIntel
CPU Series:       6
 model:           69
 Model name:       Intel(R) Core(TM) i5-4250U CPU @ 1.30GHz
 Stepping:           1
CPU MHz:         2294.841
CPU maximum MHz:    2600.0000
CPU minimum MHz:    800.0000
BogoMIPS:        3791.50
 Virtualization:         VT-x
L1d Cache:       32K
L1i Cache:       32K
L2 Cache:        two hundred and fifty-six K
L3 Cache:        three thousand and seventy-two K
NUMA Node 0 CPU:  0-3

Execute the following command, where 'getconf_NPROCESSORS_ONLN 'indicates the number of cores. The operation of compiling the kernel will be time-consuming, so starting multiple logical cores to compile at the same time as possible can reduce the compilation time.

make -j$(getconf _NPROCESSORS_ONLN)
perhaps  make -j4
 Installing kernel modules
make modules_install 
Install kernel
make install  

Then he reported a mistake

# make modules_install 
sed: Unable to read modules.order: There is no such file or directory
Makefile:1351: recipe for target '_modinst_' failed
make: *** [_modinst_] Error 2

# make modules
  CALL    scripts/checksyscalls.sh
  CALL    scripts/atomic/check-atomics.sh
  DESCEND  objtool
  CHK     include/generated/compile.h
  CHK     kernel/kheaders_data.tar.xz
make[1]: *** There are no rules to make targets“ debian/canonical-certs.pem",By“ certs/x509_certificate_list" Demand. Stop.
Makefile:1734: recipe for target 'certs' failed
make: *** [certs] Error 2

I guess it may be because my current kernel version is different from the downloaded kernel version. I want to go to the official website to download the same version as 5.4.0-89. Good guy, there is no 89 at all.

Try to solve the problem of error reporting first, Baidu one by one, edit the. config file and comment out the following two lines

gedit .config

CONFIG_MODULE_SIG_KEY="certs/signing_key.pem"
CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"
make -j4
make modules_install -j4
make install
root@robotarm:/home/robotarm/file/ethercat_master_file/linux-5.4.154# make install -j4
sh ./arch/x86/boot/install.sh 5.4.154-rt65 arch/x86/boot/bzImage \
	System.map "/boot"
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 5.4.154-rt65 /boot/vmlinuz-5.4.154-rt65
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 5.4.154-rt65 /boot/vmlinuz-5.4.154-rt65
update-initramfs: Generating /boot/initrd.img-5.4.154-rt65
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 5.4.154-rt65 /boot/vmlinuz-5.4.154-rt65
run-parts: executing /etc/kernel/postinst.d/update-notifier 5.4.154-rt65 /boot/vmlinuz-5.4.154-rt65
run-parts: executing /etc/kernel/postinst.d/xx-update-initrd-links 5.4.154-rt65 /boot/vmlinuz-5.4.154-rt65
I: /vmlinuz.old is now a symlink to boot/vmlinuz-5.4.0-89-generic
I: /initrd.img.old is now a symlink to boot/initrd.img-5.4.0-89-generic
I: /vmlinuz is now a symlink to boot/vmlinuz-5.4.154-rt65
I: /initrd.img is now a symlink to boot/initrd.img-5.4.154-rt65
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 5.4.154-rt65 /boot/vmlinuz-5.4.154-rt65
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.154-rt65
Found initrd image: /boot/initrd.img-5.4.154-rt65
Found linux image: /boot/vmlinuz-5.4.0-89-generic
Found initrd image: /boot/initrd.img-5.4.0-89-generic
Found linux image: /boot/vmlinuz-5.4.0-87-generic
Found initrd image: /boot/initrd.img-5.4.0-87-generic
Found linux image: /boot/vmlinuz-4.15.0-142-generic
Found initrd image: /boot/initrd.img-4.15.0-142-generic
Found linux image: /boot/vmlinuz-4.15.0-45-generic
Found initrd image: /boot/initrd.img-4.15.0-45-generic
Found linux image: /boot/vmlinuz-4.9.38-xenomai-3.1
Found initrd image: /boot/initrd.img-4.9.38-xenomai-3.1
Adding boot menu entry for EFI firmware configuration
done

(I seem to have downloaded the kernel several times. Anyway, this time it's version 154)

View the compiled kernel size: 18G

du -sh

18G	.

5. Modify grub startup configuration file

After installing the kernel, update grub manually.

update-grub

gedit edits the / etc/default/grub file and makes three changes:

Comment out "GRUB_TIMEOUT_STYLE=hidden" (add "#" before it).

Change the value of "GRUB_TIMEOUT" to "15".

Change the value of "GRUB_CMDLINE_LINUX_DEFAULT" to "text".

Update the configuration file again

update-grub

  6. Test

After reboot, enter GRUB interface, select 154, and then

uname -a
Linux robotarm 5.4.154-rt65 #1 SMP PREEMPT_RT Thu Nov 4 10:21:44 CST 2021 x86_64 x86_64 x86_64 GNU/Linux

It seems to be successful. Test it. Run five threads with thread priority of 80 and infinite loop.

T: 0      Thread with sequence number 0
P: 0      Thread priority is 0
C: 9397   Counter. The counter is incremented by 1 for each time interval of the thread
I: 1000   The time interval is 1000 microseconds (us)
Min:      Minimum delay (us)
Act:      Last delay (us)
Avg:     Average delay (us)
Max:     Maximum delay (us)  

sudo apt-get install rt-tests
sudo cyclictest -t 5 -p 80 -n 
# /dev/cpu_dma_latency set to 0us
policy: fifo: loadavg: 3.63 1.72 0.90 1/711 2801          

T: 0 ( 2797) P:80 I:1000 C:   6258 Min:      3 Act:    3 Avg:    4 Max:      31
T: 1 ( 2798) P:80 I:1500 C:   4172 Min:      3 Act:    4 Avg:    5 Max:      30
T: 2 ( 2799) P:80 I:2000 C:   3129 Min:      3 Act:    4 Avg:    5 Max:      21
T: 3 ( 2800) P:80 I:2500 C:   2503 Min:      3 Act:    3 Avg:    4 Max:      32
T: 4 ( 2801) P:80 I:3000 C:   2086 Min:      3 Act:    4 Avg:    5 Max:      27

It seems that the error is not big. There should be no problem running ethercat communication

2, Install igh master station

download

http://etherlab.org/download/ethercat/ethercat-1.5.2.tar.bz2

tar -vxf ethercat-1.5.2.tar.bz2
cd ethercat-1.5.2/
./configure --with-linux-dir=/usr/src/linux-headers-5.4.0-89-generic/ --enable-8139too=no --enable-wildcards=yes

make -j4
make modules -j4

Then he reported a mistake
CC [M]  /home/robotarm/ethercat-1.5.2/devices/generic.o
/home/robotarm/ethercat-1.5.2/devices/generic.c: In function 'ec_gen_device_init':
/home/robotarm/ethercat-1.5.2/devices/generic.c:152:77: error: macro "alloc_netdev" requires 4 arguments, but only 3 given
     dev->netdev = alloc_netdev(sizeof(ec_gen_device_t *), &null, ether_setup);
                                                                             ^
/home/robotarm/ethercat-1.5.2/devices/generic.c:152:19: error: 'alloc_netdev' undeclared (first use in this function); did you mean 'alloc_netdev_mqs'?
     dev->netdev = alloc_netdev(sizeof(ec_gen_device_t *), &null, ether_setup);
                   ^~~~~~~~~~~~
                   alloc_netdev_mqs
/home/robotarm/ethercat-1.5.2/devices/generic.c:152:19: note: each undeclared identifier is reported only once for each function it appears in
/home/robotarm/ethercat-1.5.2/devices/generic.c:146:10: warning: unused variable 'null' [-Wunused-variable]
     char null = 0x00;
          ^~~~
In file included from ./include/linux/skbuff.h:20:0,
                 from ./include/linux/if_arp.h:22,
                 from /home/robotarm/ethercat-1.5.2/devices/generic.c:40:
/home/robotarm/ethercat-1.5.2/devices/generic.c: In function 'ec_gen_device_create_socket':
./include/linux/socket.h:181:19: warning: passing argument 1 of 'sock_create_kern' makes pointer from integer without a cast [-Wint-conversion]
 #define AF_PACKET 17 /* Packet family  */
                   ^
./include/linux/socket.h:235:19: note: in expansion of macro 'AF_PACKET'
 #define PF_PACKET AF_PACKET
                   ^~~~~~~~~
/home/robotarm/ethercat-1.5.2/devices/generic.c:210:28: note: in expansion of macro 'PF_PACKET'
     ret = sock_create_kern(PF_PACKET, SOCK_RAW, htons(ETH_P_ETHERCAT),
                            ^~~~~~~~~
In file included from ./include/linux/skbuff.h:26:0,
                 from ./include/linux/if_arp.h:22,
                 from /home/robotarm/ethercat-1.5.2/devices/generic.c:40:
./include/linux/net.h:235:5: note: expected 'struct net *' but argument is of type 'int'
 int sock_create_kern(struct net *net, int family, int type, int proto, struct socket **res);
     ^~~~~~~~~~~~~~~~
/home/robotarm/ethercat-1.5.2/devices/generic.c:211:13: warning: passing argument 4 of 'sock_create_kern' makes integer from pointer without a cast [-Wint-conversion]
             &dev->socket);
             ^
In file included from ./include/linux/skbuff.h:26:0,
                 from ./include/linux/if_arp.h:22,
                 from /home/robotarm/ethercat-1.5.2/devices/generic.c:40:
./include/linux/net.h:235:5: note: expected 'int' but argument is of type 'struct socket **'
 int sock_create_kern(struct net *net, int family, int type, int proto, struct socket **res);
     ^~~~~~~~~~~~~~~~
/home/robotarm/ethercat-1.5.2/devices/generic.c:210:11: error: too few arguments to function 'sock_create_kern'
     ret = sock_create_kern(PF_PACKET, SOCK_RAW, htons(ETH_P_ETHERCAT),
           ^~~~~~~~~~~~~~~~
In file included from ./include/linux/skbuff.h:26:0,
                 from ./include/linux/if_arp.h:22,
                 from /home/robotarm/ethercat-1.5.2/devices/generic.c:40:
./include/linux/net.h:235:5: note: declared here
 int sock_create_kern(struct net *net, int family, int type, int proto, struct socket **res);
     ^~~~~~~~~~~~~~~~
scripts/Makefile.build:262: recipe for target '/home/robotarm/ethercat-1.5.2/devices/generic.o' failed
make[3]: *** [/home/robotarm/ethercat-1.5.2/devices/generic.o] Error 1
scripts/Makefile.build:497: recipe for target '/home/robotarm/ethercat-1.5.2/devices' failed
make[2]: *** [/home/robotarm/ethercat-1.5.2/devices] Error 2
Makefile:1734: recipe for target '/home/robotarm/ethercat-1.5.2' failed
make[1]: *** [/home/robotarm/ethercat-1.5.2] Error 2
make[1]: Leave directory“/home/robotarm/file/ethercat_master_file/linux-5.4.154"
Makefile:834: recipe for target 'modules' failed
make: *** [modules] Error 2



Maybe, maybe it's the wrong kernel version. Try it again, and then slide by hand. I accidentally unloaded some things. It shouldn't be a big problem.

The following packages are installed automatically and are no longer required:
  amd64-microcode intel-microcode iucode-tool linux-hwe-5.4-headers-5.4.0-84 linux-hwe-5.4-headers-5.4.0-87 linux-hwe-5.4-headers-5.4.0-89
  linux-image-generic-hwe-18.04 thermald
 use'sudo apt autoremove'To uninstall it(they). 
The following software packages will be uninstalled:
  linux-generic-hwe-18.04 linux-headers-5.4.0-87-generic linux-headers-5.4.0-89-generic linux-headers-generic-hwe-18.04
  linux-signed-generic-hwe-18.04
 0 packages have been upgraded and 0 packages have been newly installed. To uninstall 5 packages, 5 packages have not been upgraded.
28 will be empty after decompression.6 MB Space.
(Reading database ... There are currently 273602 files and directories installed in the system.)
Uninstalling linux-signed-generic-hwe-18.04 (5.3.0.62.115) ...
Uninstalling linux-generic-hwe-18.04 (5.4.0.89.100~18.04.79) ...
Uninstalling linux-headers-5.4.0-87-generic (5.4.0-87.98~18.04.1) ...
Uninstalling linux-headers-generic-hwe-18.04 (5.4.0.89.100~18.04.79) ...
Uninstalling linux-headers-5.4.0-89-generic (5.4.0-89.100~18.04.1) ...

Download it again

sudo apt install linux-headers-5.4.0-89

Take a closer look at the error message. It seems that there are less values passed by the parameters in it. Maybe there is something missing in kernel version 5.4

sudo gedit devices/generic.c +154

// dev->netdev = alloc_netdev(sizeof(ec_gen_device_t *), &null, ether_setup);
   dev->netdev = alloc_netdev(sizeof(ec_gen_device_t *), &null,NET_NAME_UNKNOWN, ether_setup);


sudo gedit master/ethernet.c +150
// if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) {
   if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name,NET_NAME_UNKNOWN, ether_setup))) {
Another problem is this

int sock_create_kern(struct net *net, int family, int type, int proto, struct socket **res);

linux2.x The version is:
int sock_create_kern(int family, int type, int protocol, struct socket **res)
{
    return __sock_create(family, type, protocol, res, 1);
}
linux3.x The version of is
int sock_create_kern(int family, int type, int protocol, struct socket **res)
{
    return __sock_create(&init_net, family, type, protocol, res, 1);
}
linux4.x The version of is
int sock_create_kern(struct net *net, int family, int type, int protocol, struct socket **res)
{
    return __sock_create(net, family, type, protocol, res, 1);
}

And in generic.c The calling method in is
ret = sock_create_kern(PF_PACKET, SOCK_RAW, htons(ETH_P_ETHERCAT),&dev->socket);
int 
So it will cause problems
 In 4.x The version of can be called this way
sock_create_kern(&init_net, family, type, protocol, res);
So line 211 should read
// ret = sock_create_kern(PF_PACKET, SOCK_RAW, htons(ETH_P_ETHERCAT),
    ret = sock_create_kern(&init_net,PF_PACKET, SOCK_RAW, htons(ETH_P_ETHERCAT),

Then compile it again

sudo make modules

home/robotarm/ethercat-1.5.2/examples/mini/mini.c: In function 'init_mini_module':
/home/robotarm/ethercat-1.5.2/examples/mini/mini.c:495:5: error: implicit declaration of function 'init_timer'; did you mean 'init_timers'? [-Werror=implicit-function-declaration]
     init_timer(&timer);
     ^~~~~~~~~~
     init_timers
/home/robotarm/ethercat-1.5.2/examples/mini/mini.c:496:20: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
     timer.function = cyclic_task;

I don't want to care about anything in... example. Just comment it out.

 CC [M]  /home/robotarm/ethercat-1.5.2/master/cdev.o
/home/robotarm/ethercat-1.5.2/master/cdev.c:89:14: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
     .fault = eccdev_vma_fault
              ^~~~~~~~~~~~~~~~
/home/robotarm/ethercat-1.5.2/master/cdev.c:89:14: note: (near initialization for 'eccdev_vm_ops.fault')
In file included from /home/robotarm/ethercat-1.5.2/master/cdev.c:42:0:
/home/robotarm/ethercat-1.5.2/master/cdev.c: In function 'eccdev_vma_fault':
/home/robotarm/ethercat-1.5.2/master/cdev.c:279:46: error: 'struct vm_fault' has no member named 'virtual_address'
             " offset = %lu, page = %p\n", vmf->virtual_address, offset, page);
                                              ^
/home/robotarm/ethercat-1.5.2/master/master.h:115:38: note: in definition of macro 'EC_MASTER_DBG'
                     master->index, ##args); \

First, change line 62 to and comment out other errors

#define PAGE_FAULT_VERSION KERNEL_VERSION(5, 4, 154)

Continue to report errors

/home/robotarm/ethercat-1.5.2/master/master.c: In function 'ec_master_eoe_start':
/home/robotarm/ethercat-1.5.2/master/master.c:1637:12: error: variable 'param' has initializer but incomplete type
     struct sched_param param = { .sched_priority = 0 };
            ^~~~~~~~~~~
/home/robotarm/ethercat-1.5.2/master/master.c:1637:35: error: 'struct sched_param' has no member named 'sched_priority'
     struct sched_param param = { .sched_priority = 0 };
                                   ^~~~~~~~~~~~~~
/home/robotarm/ethercat-1.5.2/master/master.c:1637:52: warning: excess elements in struct initializer
     struct sched_param param = { .sched_priority = 0 };
                                                    ^
/home/robotarm/ethercat-1.5.2/master/master.c:1637:52: note: (near initialization for 'param')
/home/robotarm/ethercat-1.5.2/master/master.c:1637:24: error: storage size of 'param' isn't known
     struct sched_param param = { .sched_priority = 0 };
                        ^~~~~
/home/robotarm/ethercat-1.5.2/master/master.c:1637:24: warning: unused variable 'param' [-Wunused-variable]

#Include < Linux / sched. H >, if this is added to the header file, there is still an error... Then add it manually

    struct sched_param
    {
        int sched_priority;
    };

... in fact, it doesn't work. In the end, it was found that it was a problem with the linux system directory,, / / /,

Rewrite the next one

Reference link  

 Linux kernel real-time patch preempt_rt - know

Compilation, installation and testing of real-time Linux kernel (preempt_rt) _v6543210 column - CSDN blog _preempt_rtLinux kernel compilation error: make[1]: * * * there are no rules to create the target "debian/canonical-certs.pem", which is required by "certs/x509_certificate_list". Stop the blog of _m0_51203305 - CSDN blog

Compiling kernel 5.4.0 using Ubuntu 18.04 on the server - Zhihu
Compilation, installation and testing of real-time Linux kernel (preempt_rt) _v6543210 column - CSDN blog _preempt_rt

Posted by jimrains on Thu, 04 Nov 2021 17:44:28 -0700