Reputation: 21
I try to add can0 to systemd to auto start at boot time on my imx8 board. But I couldnt with these configurations :
$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
search can0.service on target roots but not found :
$cd lib/systemd/ && find -name "*can*"
--------------------------------------------
./system/wpa_supplicant.service
./system/[email protected]
./system/[email protected]
./system/[email protected]
Also I try to add systemd_%.bbappend with these file : (Also systemd tree different with under code. can0.service is under the files folder near to service_%.bbappend file)
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 created by above systemd_%.bbappend but not auto start at boot time. Just can0.service seems at /lib/systemd/system folder at target.
What is my mistake? Can somebody help me?
Upvotes: 0
Views: 2487
Reputation: 155
Adding
inherit systemd
and
SYSTEMD_AUTO_ENABLE ??= "enable"
to the recipe did the trick for me. Now the service is auto-enabled after flashing the image.
Upvotes: 0
Reputation: 1523
enable
will hook the specified unit into relevant places so that it will automatically start on boot or other situations depending on what's specified in the unit file.
As of systemctl version 220, enable and disable support a --now switch to start / stop services concurrent with the enabling / disabling.
e.g. systemctl --now enable foobar.service
Use systemctl --version to check your installed version.
Upvotes: 1
Reputation: 1523
The cat0 service status posted above shows that the service is not enabled.
You can enable this service using the command systemctl enable cat0
and then try to reboot the system.
The services which are in enable state comes automatically after system reboot.
Upvotes: 2