【发布时间】:2020-05-11 17:42:08
【问题描述】:
我尝试将 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/wpa_supplicant-nl80211@.service
./system/wpa_supplicant@.service
./system/wpa_supplicant-wired@.service
我还尝试使用这些文件添加 systemd_%.bbappend : (另外systemd树也和下面的代码不同。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_%.bbappend 创建,但在启动时不会自动启动。只是 can0.service 似乎在目标的 /lib/systemd/system 文件夹中。
我的错误是什么?有人可以帮帮我吗?
【问题讨论】:
-
journalctl -u can0说什么? -
@OleksandrKravchuk 什么也不说。 (没有条目)
-
服务还在运行吗?
systemctl status cat0 -
@OleksandrKravchuk 没有运行。我的 bbappend 没有将 can0.service 添加到 rootfs。
-
@OleksandrKravchuk:我完成了构建。 systemd_%.append 按照我的预期将 can0.service 添加到 /lib/systemd/system 但是:$systemctl status can0 表示:��● can0.service - can0 接口设置已加载:已加载 (/lib/systemd/system/can0.服务;禁用;供应商预设:启用)活动:非活动(死)1 月 25 日 21:56:55 tqma8xqp-mba8xx systemd[1]: [[0;1;39m[[0;1;31m[[0;1; 39m/lib/systemd/system/can0.service:16:“安装”部分中的未知左值“FILES_${PN} +”[[0m