我尝试将can0添加到systemd以便在imx8板上的启动时自动启动。但是我无法使用这些配置:
$tree recipes-core/
----------------------------------------
recipes-core/
└── systemd
├── systemd-machine-units
│ ├── 10-eth0.network
│ ├── 10-eth1.network
│ ├── 90-dhcp-default.network
│ ├── can0.service
│ └── can1.service
└── systemd-machine-units_1.0.bbappend
2 directories, 6 files
$ cat systemd-machine-units_1.0.bbappend
-------------------------------------------------------------
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
# all our boards have at least one native network port
SRC_URI = " \
file://10-eth0.network \
file://90-dhcp-default.network \
file://10-eth1.network \
file://can0.service \
file://can1.service \
"
SYSTEMD_SERVICE_${PN} = "can0.service can1.service"
do_install_append() {
install -d ${D}${systemd_unitdir}/network/
install -m 0644 "${WORKDIR}/10-eth0.network" ${D}${systemd_unitdir}/network/
install -m 0644 "${WORKDIR}/90-dhcp-default.network" ${D}${systemd_unitdir}/network/
install -m 0644 "${WORKDIR}/10-eth1.network" ${D}${systemd_unitdir}/network/
install -d ${D}${systemd_system_unitdir}/
install -m 0644 "${WORKDIR}/can0.service" ${D}${systemd_system_unitdir}/
install -m 0644 "${WORKDIR}/can1.service" ${D}${systemd_system_unitdir}/
}
FILES_${PN} = "\
${systemd_system_unitdir} \
${systemd_unitdir}/network/ \
"
$cat can0.service
--------------------------------------------------------------------------------
# For 2.0B legacy mode, arbitration bit rate (bitrate) and
# payload bit rate (dbitrate) have the same value - not higher than 1Mbps.
# CAN frames are limited to max 8 bytes in this case
# if target does not support FD, fg settings are not accepted by ip link set
[Unit]
Description=can0 interface setup
[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/sbin/ip link set can0 up type can bitrate 500000
ExecStop=/sbin/ip link set can0 down
[Install]
WantedBy=basic.target
在目标根上搜索can0.service,但未找到:
$cd lib/systemd/ && find -name "*can*"
--------------------------------------------
./system/wpa_supplicant.service
./system/[email protected]
./system/[email protected]
./system/[email protected]
此外,我尝试在这些文件中添加systemd _%。bbappend:(也有与下面的代码不同的系统树。can0.service在service _%。bbappend文件附近的文件文件夹下)
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += "file://can0.service"
SYSTEMD_SERVICE_${PN} = "can0.service can1.service"
FILES_${PN} += "{sysconfdir}/systemd/system/* "
do_install_append() {
install -d ${D}${systemd_unitdir}/system/
install -m 0644 ${WORKDIR}/*.service ${D}${systemd_unitdir}/system/
}
can0.service由以上systemd _%。bb创建,但在启动时不会自动启动。 can0.service似乎位于目标的/ lib / systemd / system文件夹中。
我的错是什么?有人可以帮我吗?
上面发布的cat0服务状态表明该服务未启用。
您可以使用命令systemctl enable cat0
启用此服务,然后尝试重新引导系统。
处于启用状态的服务在系统重新引导后自动出现。
[enable
会将指定的单元挂接到相关位置,以便它会根据单元文件中指定的内容在启动或其他情况下自动启动。
从systemctl版本220开始,启用和禁用支持--now开关,以在启用/禁用的同时启动/停止服务。
例如systemctl --now enable foobar.service
使用systemctl --version检查您安装的版本。