fix(ethercat): align bundled userspace and kernel modules
Rebuild the bundled IgH EtherCAT 1.7.0 userspace and Linux 6.8.0-138 modules from the same source revision. Record build provenance and update the shared library links to libethercat.so.1.3.0 so slave configuration uses a matching ioctl ABI. Refresh external library discovery when versioned files change and document installation, module compatibility checks, and ABI troubleshooting. Validation: verified matching create-slave-config ioctl values (0xc140a423) in the userspace library and kernel module; checked ethercatctl shell syntax and git diff --check. No motor commands were executed.
This commit is contained in:
parent
37a62fb3e3
commit
0813cad96c
33
README.md
33
README.md
@ -68,6 +68,9 @@ sudo apt install gnuplot-qt
|
||||
dependency/x86/third_party/ethercat/v1.7.0
|
||||
```
|
||||
|
||||
当前依赖的源码提交和配套内核版本记录在该目录的 `BUILDINFO.txt` 中。
|
||||
目录中保留的其他内核版本模块不代表与当前 userspace 兼容。
|
||||
|
||||
先设置本机路径:
|
||||
|
||||
```shell
|
||||
@ -82,7 +85,8 @@ sudo apt-get update
|
||||
sudo apt-get install -y linux-headers-$(uname -r)
|
||||
```
|
||||
|
||||
如果内置目录里已经有当前内核版本的 EtherCAT 内核模块,直接安装到系统:
|
||||
只有在内置 userspace(`libethercat.so`、`ecrt.h`)与 EtherCAT 内核模块来自
|
||||
同一个源码提交,并且模块对应当前内核版本时,才可以直接安装到系统:
|
||||
|
||||
```shell
|
||||
sudo mkdir -p /lib/modules/$(uname -r)/ethercat
|
||||
@ -90,7 +94,11 @@ sudo cp -r $IGH_ETHERCAT_ROOT/lib/modules/$(uname -r)/ethercat/* /lib/modules/$(
|
||||
sudo depmod
|
||||
```
|
||||
|
||||
内置内核模块只适用于相同内核版本。如果 `$IGH_ETHERCAT_ROOT/lib/modules/$(uname -r)` 不存在,说明这台机器的内核版本不匹配,需要在这台机器上重新编译安装 IgH EtherCAT:
|
||||
不能只根据 `uname -r` 和 IgH `1.7.0` 版本号判断兼容性。同一个稳定分支的不同
|
||||
提交也可能使用不同的 ioctl 数据结构,混用后会出现
|
||||
`Failed to create slave config: Inappropriate ioctl for device`。如果无法确认 userspace
|
||||
和内核模块来自同一提交,或者 `$IGH_ETHERCAT_ROOT/lib/modules/$(uname -r)` 不存在,
|
||||
需要在这台机器上使用同一份源码重新编译安装 IgH EtherCAT:
|
||||
|
||||
```shell
|
||||
sudo apt-get update
|
||||
@ -101,6 +109,7 @@ sudo apt-get install -y \
|
||||
cd /tmp
|
||||
git clone --branch stable-1.7 --depth 1 https://gitlab.com/etherlab.org/ethercat.git ethercat-stable-1.7
|
||||
cd ethercat-stable-1.7
|
||||
git rev-parse HEAD # 记录本次 userspace 和内核模块共同使用的提交
|
||||
|
||||
./bootstrap
|
||||
./configure \
|
||||
@ -118,6 +127,26 @@ sudo make modules_install
|
||||
sudo depmod
|
||||
```
|
||||
|
||||
其中,`make install` 会更新 `$IGH_ETHERCAT_ROOT` 下的用户态库、头文件和工具,
|
||||
也会覆盖该目录中的默认配置文件;已有网卡配置应先备份并在安装后恢复。
|
||||
`sudo make modules_install` 会更新 `/lib/modules/$(uname -r)/ethercat` 下的
|
||||
`ec_master.ko`、`ec_generic.ko` 等内核模块。已加载的模块需要通过下方启动脚本
|
||||
停止并重新加载后才会使用新文件;执行前应退出正在占用主站的应用。
|
||||
|
||||
安装完成后,检查用户态库与内核模块中的“创建 slave config” ioctl 编号。
|
||||
使用 `libethercat.so.1` 符号链接,避免把实际库文件名固定为旧的 `1.2.0`:
|
||||
|
||||
```shell
|
||||
objdump -d --disassemble=ecrt_master_slave_config "$IGH_ETHERCAT_ROOT/lib/libethercat.so.1" \
|
||||
| rg -o -m1 '\$0x[cC][0-9a-fA-F]+a423'
|
||||
|
||||
objdump -d "/lib/modules/$(uname -r)/ethercat/master/ec_master.ko" \
|
||||
| rg -o -m1 '\$0x[cC][0-9a-fA-F]+a423'
|
||||
```
|
||||
|
||||
两条命令的输出必须完全一致。编号不同说明 ABI 不兼容,不能启动 EtherCAT 应用;
|
||||
编号一致是必要检查,仍需保证用户态和内核模块来自同一源码提交。
|
||||
|
||||
启动 EtherCAT。`eno1` 换成实际连接 EtherCAT 从站的网卡:
|
||||
|
||||
```shell
|
||||
|
||||
@ -69,7 +69,7 @@ function(setup_external_libs ARCH)
|
||||
set(HAS_LIB TRUE)
|
||||
|
||||
# Collect shared libs for install: *.so and *.so.*
|
||||
file(GLOB _SO_FILES
|
||||
file(GLOB _SO_FILES CONFIGURE_DEPENDS
|
||||
"${FULL_PATH}/lib/*.so"
|
||||
"${FULL_PATH}/lib/*.so.*"
|
||||
)
|
||||
@ -91,7 +91,7 @@ function(setup_external_libs ARCH)
|
||||
set(HAS_LIB TRUE)
|
||||
|
||||
# Only install Linux shared libs from base dir
|
||||
file(GLOB _SO_FILES2
|
||||
file(GLOB _SO_FILES2 CONFIGURE_DEPENDS
|
||||
"${FULL_PATH}/*.so"
|
||||
"${FULL_PATH}/*.so.*"
|
||||
)
|
||||
|
||||
15
dependency/x86/third_party/ethercat/v1.7.0/BUILDINFO.txt
vendored
Normal file
15
dependency/x86/third_party/ethercat/v1.7.0/BUILDINFO.txt
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
IgH EtherCAT 1.7.0
|
||||
Source: https://gitlab.com/etherlab.org/ethercat
|
||||
Commit: 9a2f1f59ebb6568bb5652cb6e852c67ddb77549f
|
||||
Build date: 2026-10-19
|
||||
Architecture: x86_64
|
||||
Userspace shared library: libethercat.so.1.3.0 (SONAME libethercat.so.1)
|
||||
Matching bundled kernel modules: lib/modules/6.8.0-138-generic/ethercat
|
||||
EC_IOCTL_VERSION_MAGIC: 38
|
||||
EC_IOCTL_CREATE_SLAVE_CONFIG: 0xC140A423 (ec_ioctl_config_t: 320 bytes)
|
||||
Configuration: --enable-generic; other features use upstream defaults.
|
||||
Install prefix: dependency/x86/third_party/ethercat/v1.7.0
|
||||
|
||||
The older bundled 6.8.0-124/136 modules are historical artifacts from a
|
||||
previous userspace build. Rebuild both modules and userspace from the same
|
||||
commit before using those kernels; do not pair them with this userspace.
|
||||
Binary file not shown.
@ -36,6 +36,9 @@
|
||||
* - Added ecrt_master_sii_caching() to set the SII caching method and added
|
||||
* the feature flag EC_HAVE_SII_CACHING and the enum type
|
||||
* ec_sii_caching_fields_t.
|
||||
* - Added ecrt_slave_config_pdo_mode() to select whether a slave's PDO
|
||||
* assignment and PDO configuration are read from resp. written to it via
|
||||
* CoE, the enum type ec_pdo_mode_t and the feature flag EC_HAVE_PDO_MODE.
|
||||
*
|
||||
* Changes in version 1.6.0:
|
||||
*
|
||||
@ -252,6 +255,11 @@
|
||||
*/
|
||||
#define EC_HAVE_SII_CACHING
|
||||
|
||||
/** Defined, if the method ecrt_slave_config_pdo_mode() and the enum type
|
||||
* ec_pdo_mode_t are available.
|
||||
*/
|
||||
#define EC_HAVE_PDO_MODE
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/** Symbol visibility control macro.
|
||||
@ -394,7 +402,7 @@ typedef struct {
|
||||
- 8: \a OP
|
||||
|
||||
Note that each state is coded in a different
|
||||
bit! */
|
||||
bit. */
|
||||
} ec_slave_config_state_t;
|
||||
|
||||
/****************************************************************************/
|
||||
@ -532,6 +540,42 @@ typedef enum {
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/** PDO handling mode.
|
||||
*
|
||||
* Used for the \a assign_mode and \a config_mode parameters of
|
||||
* ecrt_slave_config_pdo_mode() to select whether a slave's PDO assignment
|
||||
* (which PDOs are mapped into a sync manager, CoE objects 0x1C10-0x1C13)
|
||||
* resp. its PDO configuration (the entries mapped into an assigned PDO) are
|
||||
* read from resp. written to the slave via CoE.
|
||||
*/
|
||||
typedef enum {
|
||||
EC_PDO_MODE_FIXED, /**< Neither read nor write via CoE. Trust that the
|
||||
slave already matches the layout given via
|
||||
ecrt_slave_config_pdos() and friends. */
|
||||
EC_PDO_MODE_WRITE, /**< Write the configured state via CoE every time
|
||||
the slave is configured, without reading the
|
||||
current state first ("blind write"). */
|
||||
EC_PDO_MODE_READ_WRITE, /**< Read the current state via CoE while
|
||||
scanning the slave, and unconditionally
|
||||
(re-)write it every time the slave is
|
||||
configured. This is the default. */
|
||||
EC_PDO_MODE_WRITE_IF_DIFFERENT, /**< Read the current state via CoE
|
||||
while scanning the slave, and write
|
||||
it back only if it differs from the
|
||||
configured state. */
|
||||
} ec_pdo_mode_t;
|
||||
|
||||
/** Default PDO handling mode: read via CoE while scanning, and
|
||||
* unconditionally (re-)write via CoE every time the slave is configured.
|
||||
* This is the behavior in effect if ecrt_slave_config_pdo_mode() is never
|
||||
* called.
|
||||
*
|
||||
* \see ec_pdo_mode_t
|
||||
*/
|
||||
#define EC_PDO_MODE_DEFAULT EC_PDO_MODE_READ_WRITE
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/** PDO entry configuration information.
|
||||
*
|
||||
* This is the data type of the \a entries field in ec_pdo_info_t.
|
||||
@ -1444,6 +1488,58 @@ EC_PUBLIC_API int ecrt_slave_config_watchdog(
|
||||
so the default is used. */
|
||||
);
|
||||
|
||||
/** Selects how a slave's PDO assignment and PDO configuration are read
|
||||
* from resp. written to it via CoE.
|
||||
*
|
||||
* By default (i. e. if this method is not called), a slave's PDO
|
||||
* assignment and PDO configuration are both read via CoE while the bus is
|
||||
* scanned, and are both unconditionally (re-)written via CoE every time
|
||||
* the slave is configured (e. g. after a state change or reconnect). For
|
||||
* slaves with a fixed or otherwise well-known PDO structure, this can be
|
||||
* relaxed independently for the assignment and the configuration, to save
|
||||
* mailbox round trips during bus scanning and/or slave configuration.
|
||||
*
|
||||
* If \a assign_mode resp. \a config_mode is EC_PDO_MODE_FIXED or
|
||||
* EC_PDO_MODE_WRITE, the corresponding aspect is not read from the slave
|
||||
* while scanning; the master then relies solely on the PDO configuration
|
||||
* made available through ecrt_slave_config_pdos(),
|
||||
* ecrt_slave_config_sync_manager(), ecrt_slave_config_pdo_assign_add()
|
||||
* and ecrt_slave_config_pdo_mapping_add(). The application is responsible
|
||||
* for making sure this matches the slave's actual capabilities in that
|
||||
* case.
|
||||
*
|
||||
* \note Reading the PDO configuration requires first discovering the PDO
|
||||
* assignment (which PDOs exist), since the master must know a PDO's index
|
||||
* before it can query its entries. Therefore, whenever \a config_mode is
|
||||
* EC_PDO_MODE_READ_WRITE or EC_PDO_MODE_WRITE_IF_DIFFERENT, the PDO
|
||||
* assignment is read while scanning the bus as well, regardless of \a
|
||||
* assign_mode. This is harmless, but means that the mailbox traffic saved
|
||||
* by choosing EC_PDO_MODE_FIXED or EC_PDO_MODE_WRITE for \a assign_mode is
|
||||
* not realized in that particular combination.
|
||||
*
|
||||
* \attention Because bus scanning happens before slave configurations are
|
||||
* attached to their slaves, a non-default \a assign_mode or \a
|
||||
* config_mode is only guaranteed to take effect for the scanning of a
|
||||
* slave if this method is called (i. e. the slave configuration is
|
||||
* created via ecrt_master_slave_config()) before that slave is scanned
|
||||
* for the first time. Otherwise, the scan falls back to the default
|
||||
* (reading) behavior for that particular scan; a subsequent bus rescan
|
||||
* (e. g. via the "ethercat rescan" command) will pick up the configured
|
||||
* mode.
|
||||
*
|
||||
* This method has to be called in non-realtime context before
|
||||
* ecrt_master_activate().
|
||||
*
|
||||
* \apiusage{master_idle,blocking}
|
||||
*
|
||||
* \return 0 on success, otherwise negative error code.
|
||||
*/
|
||||
EC_PUBLIC_API int ecrt_slave_config_pdo_mode(
|
||||
ec_slave_config_t *sc, /**< Slave configuration. */
|
||||
ec_pdo_mode_t assign_mode, /**< Mode for the PDO assignment. */
|
||||
ec_pdo_mode_t config_mode /**< Mode for the PDO configuration. */
|
||||
);
|
||||
|
||||
/** Add a PDO to a sync manager's PDO assignment.
|
||||
*
|
||||
* This method has to be called in non-realtime context before
|
||||
@ -1660,8 +1756,63 @@ EC_PUBLIC_API int ecrt_slave_config_reg_pdo_entry_pos(
|
||||
* signals.
|
||||
*
|
||||
* The AssignActivate word is vendor-specific and can be taken from the XML
|
||||
* device description file (Device -> Dc -> AssignActivate). Set this to zero,
|
||||
* if the slave shall be operated without distributed clocks (default).
|
||||
* device description file (ESI, Device -> Dc -> AssignActivate). Set this to
|
||||
* zero, if the slave shall be operated without distributed clocks (default).
|
||||
*
|
||||
* The \a sync0_cycle and \a sync1_cycle parameters correspond to the
|
||||
* \c CycleTimeSync0 and \c CycleTimeSync1 elements of the slave's XML device
|
||||
* description (ESI) file, respectively, but have to be given here as
|
||||
* absolute values in nanoseconds instead of relying on the \c Factor
|
||||
* elements offered by the ESI. If the ESI only specifies a
|
||||
* \c CycleTimeSync0Factor (and no \c CycleTimeSync0), the actual cycle time
|
||||
* has to be derived from the application's own cycle time \a T (i. e. the
|
||||
* period at which the application calls ecrt_master_application_time() /
|
||||
* ecrt_master_send(), in nanoseconds) as follows:
|
||||
*
|
||||
* \code
|
||||
* if CycleTimeSync0 != 0:
|
||||
* sync0_cycle = CycleTimeSync0
|
||||
* else if CycleTimeSync0Factor > 0:
|
||||
* sync0_cycle = T * CycleTimeSync0Factor
|
||||
* else if CycleTimeSync0Factor < 0:
|
||||
* sync0_cycle = T / -CycleTimeSync0Factor
|
||||
* else:
|
||||
* sync0_cycle = 0
|
||||
* \endcode
|
||||
*
|
||||
* A negative \c CycleTimeSync0Factor therefore selects a SYNC0 cycle time
|
||||
* shorter than the application's cycle time (typically used for
|
||||
* oversampling), while a positive factor selects a multiple of it (a factor
|
||||
* greater than 1 is unusual). \a sync1_cycle is derived similarly, but
|
||||
* additionally depends on the already calculated \a sync0_cycle:
|
||||
*
|
||||
* \code
|
||||
* if CycleTimeSync1 != 0:
|
||||
* T1 = CycleTimeSync1
|
||||
* else if CycleTimeSync1Factor > 0:
|
||||
* T1 = sync0_cycle * CycleTimeSync1Factor
|
||||
* else if CycleTimeSync1Factor < 0:
|
||||
* T1 = T * -CycleTimeSync1Factor
|
||||
* else:
|
||||
* T1 = max(T, sync0_cycle)
|
||||
*
|
||||
* sync1_cycle = T1 - sync0_cycle + ShiftTimeSync1
|
||||
* \endcode
|
||||
*
|
||||
* Note how the sign of \c CycleTimeSync1Factor chooses between the
|
||||
* application's cycle time and \a sync0_cycle as the base value. Usually,
|
||||
* \c CycleTimeSync1Factor is set to -1 (thus selecting the application's
|
||||
* cycle time) whenever \c CycleTimeSync0Factor is negative (oversampling),
|
||||
* and to 1 whenever \c CycleTimeSync0Factor is 1. If
|
||||
* \c CycleTimeSync1Factor is left at zero, a value is chosen automatically
|
||||
* as shown above. In any case, make sure that
|
||||
* \a sync0_cycle + \a sync1_cycle is greater than zero.
|
||||
*
|
||||
* \a sync0_shift can be taken directly from the ESI's \c ShiftTimeSync0
|
||||
* element. If you get PLL errors, start with zero shift time, then try one
|
||||
* third and two thirds of the application cycle time. Make sure that the
|
||||
* application time is passed like in the dc_user example (only cyclic, fixed
|
||||
* phase).
|
||||
*
|
||||
* This method has to be called in non-realtime context before
|
||||
* ecrt_master_activate().
|
||||
|
||||
Binary file not shown.
@ -8,7 +8,7 @@
|
||||
dlname='libethercat.so.1'
|
||||
|
||||
# Names of this library.
|
||||
library_names='libethercat.so.1.2.0 libethercat.so.1 libethercat.so'
|
||||
library_names='libethercat.so.1.3.0 libethercat.so.1 libethercat.so'
|
||||
|
||||
# The name of the static archive.
|
||||
old_library='libethercat.a'
|
||||
@ -23,8 +23,8 @@ dependency_libs=''
|
||||
weak_library_names=''
|
||||
|
||||
# Version information for libethercat.
|
||||
current=3
|
||||
age=2
|
||||
current=4
|
||||
age=3
|
||||
revision=0
|
||||
|
||||
# Is this an already installed library?
|
||||
|
||||
@ -1 +1 @@
|
||||
libethercat.so.1.2.0
|
||||
libethercat.so.1.3.0
|
||||
@ -1 +1 @@
|
||||
libethercat.so.1.2.0
|
||||
libethercat.so.1.3.0
|
||||
Binary file not shown.
BIN
dependency/x86/third_party/ethercat/v1.7.0/lib/libethercat.so.1.3.0
vendored
Executable file
BIN
dependency/x86/third_party/ethercat/v1.7.0/lib/libethercat.so.1.3.0
vendored
Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -55,6 +55,15 @@ fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
std_module_name() {
|
||||
case "${1}" in
|
||||
ccat) echo "ec_bhf" ;; # standard driver has a different name
|
||||
*) echo "${1}" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
is_mac_address() {
|
||||
local x='[0-9a-fA-F]'
|
||||
echo "$1" | grep -qE "^($x$x:){5}$x$x\$" -
|
||||
@ -144,10 +153,11 @@ start)
|
||||
continue # ec_* module not found
|
||||
fi
|
||||
|
||||
if [ "${MODULE}" != "generic" ] && [ "${MODULE}" != "ccat" ]; then
|
||||
if [ "${MODULE}" != "generic" ]; then
|
||||
STDMODULE=$(std_module_name "${MODULE}")
|
||||
# unload standard module and check if unloading was successful
|
||||
${RMMOD} "${MODULE}" 2> /dev/null || true
|
||||
if ${LSMOD} | grep "^${MODULE//-/_} " > /dev/null; then
|
||||
${RMMOD} "${STDMODULE}" 2> /dev/null || true
|
||||
if ${LSMOD} | grep "^${STDMODULE//-/_} " > /dev/null; then
|
||||
# could not unload module
|
||||
${RMMOD} ${LOADED_MODULES}
|
||||
exit 1
|
||||
@ -155,8 +165,8 @@ start)
|
||||
fi
|
||||
|
||||
if ! ${MODPROBE} ${MODPROBE_FLAGS} "${ECMODULE}"; then
|
||||
if [ "${MODULE}" != "generic" ] && [ "${MODULE}" != "ccat" ]; then
|
||||
${MODPROBE} ${MODPROBE_FLAGS} "${MODULE}" # try to restore
|
||||
if [ "${MODULE}" != "generic" ]; then
|
||||
${MODPROBE} ${MODPROBE_FLAGS} "${STDMODULE}" # try to restore
|
||||
fi
|
||||
${RMMOD} ${LOADED_MODULES}
|
||||
exit 1
|
||||
@ -186,10 +196,10 @@ stop)
|
||||
|
||||
# load standard modules again
|
||||
for MODULE in ${DEVICE_MODULES}; do
|
||||
if [ "${MODULE}" == "generic" ] || [ "${MODULE}" == "ccat" ]; then
|
||||
if [ "${MODULE}" == "generic" ]; then
|
||||
continue
|
||||
fi
|
||||
${MODPROBE} ${MODPROBE_FLAGS} "${MODULE}"
|
||||
${MODPROBE} ${MODPROBE_FLAGS} "$(std_module_name "${MODULE}")"
|
||||
done
|
||||
|
||||
# bring down all updown interfaces
|
||||
|
||||
Loading…
Reference in New Issue
Block a user