我尝试将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:(还有系统树,与下面的代码不同。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位于target的/lib/systemd/system文件夹中。
我的错误是什么?有人能帮帮我吗?
发布于 2020-01-26 13:43:10
上面发布的cat0服务状态显示该服务未启用。
您可以使用命令systemctl enable cat0启用此服务,然后尝试重新启动系统。
处于启用状态的服务会在系统重新启动后自动出现。
发布于 2020-01-26 16:04:59
enable会将指定的单元挂接到相关位置,以便根据单元文件中指定的内容在引导或其他情况下自动启动。
从systemctl版本220开始,启用和禁用支持a --now切换到与启用/禁用同时启动/停止服务。
例如systemctl --now enable foobar.service
使用systemctl --version检查您安装的版本。
发布于 2020-01-30 21:37:31
添加
inherit systemd和
SYSTEMD_AUTO_ENABLE ??= "enable"食谱帮了我大忙。现在,该服务在刷新镜像后会自动启用。
https://stackoverflow.com/questions/59912651
复制相似问题