I want to add custom yocto systemd service.
I referred to Enable systemd services using yocto
but my bb code is not working. It's not installed in filesystem.
(eth0.service code is okay)
How to fix it?
eth0_0.1.bb
SUMMARY = "Install and start a systemd service"
SECTION = "eth0"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI += "file://eth0.service"
S = "${WORKDIR}"
inherit systemd
SYSTEMD_SERVICE_${PN} = "eth0.service"
do_install() {
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/eth0.service ${D}${systemd_system_unitdir}/
}
FILES_${PN} += "/lib/systemd/system"
REQUIRED_DISTRO_FEATURES= "systemd"
eth0.service
[Unit]
Description=Network interfaces
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-eth0.device
After=sys.subsystem-net-devices-eth0.device
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "ifup eth0"
ExecStop=/bin/sh -c "ifdown eth0"
[Install]
WantedBy=multi-user.target
if you have inherit systemd and SYSTEMD_SERVICE_${PN} = "eth0.service" which you seem to have should have done it. So I think what you need to add is SYSTEMD_AUTO_ENABLE = "enable" a
nd make sure that .service file has [Install] section which you seem to have as well. Secondly also make sure package is added to image via IMAGE_INSTALL_append = " eth0" in local.conf
For network you can also create a systemd_%.bbappend with
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += "file://eth0.network"
FILES_${PN} += "${systemd_unitdir}/network/*"
do_install_append() {
install -d ${D}${systemd_unitdir}/network/
install -m 0644 ${WORKDIR}/*.network ${D}${systemd_unitdir}/network/
}
with files/eth0.network:
[Match]
Name=eth0
[Network]
DHCP=ipv4
Related
I have a bb file that will install a file into rootfs:
DESCRIPTION = "Add file to rootfs"
LICENSE = "test"
CONF_FILE = "${TOPDIR}/../meta/meta-test/recipes-test/test_file"
do_install() {
install -d ${D}/home/root
install -m 755 ${CONF_FILE} ${D}/home/root
}
FILES_${PN} += "/home/root"
It works fine and I can see my file in /home/root
Then I modify the file and build again.
But I find that the file isn't changed.
How can I have Yocto to check this file and build-in every time when it's changed?
Thanks to Nayfe.
It's been solved after adding SRC_URI
DESCRIPTION = "Add file to rootfs"
LICENSE = "test"
CONF_FILE = "${TOPDIR}/../meta/meta-test/recipes-test/test_file"
SRC_URI = ${CONF_FILE}
do_install() {
install -d ${D}/home/root
install -m 755 ${CONF_FILE} ${D}/home/root
}
FILES_${PN} += "/home/root"
Yocto Version is warrior.
I did a yocto project with a GO/golang user app (https-server) that works just fine on a raspi3.
Now I'm trying to autostart it at the yocto image and doesnt't got it working.
I know there are plenty outher questions regarding this, but I didnt found something that helped.
e.g. I tried to follow all steps in this post
Enable systemd services using yocto
but it doesn't autostart at the raspi.
These files at the raspi for the service I found:
/lib/systemd/system/https-server.service
/etc/systemd/system/multi-user.target.wants/https-server.service
The application itself is running great if I start it manually,
it is at the raspi at /usr/bin/https-server
my build/conf/local.conf:
IMAGE_INSTALL_append = " kernel-image kernel-devicetree sudo apt dnsmasq nano dhcpcd git glibc-utils localedef curl go https-server"
meta-https-server/
├── conf
│ └── layer.conf
└── recipes-https-server
└── https-server
├── files
│ ├── https-server.go
│ ├── https-server.service
│ ├── mytest
│ ├── server.crt
│ ├── server.key
│ └── testvideo.mp4
├── go-sw.inc
└── https-server.bb
https-server.bb
require go-sw.inc
inherit go systemd
#inherit go update-rc.d systemd
SRC_URI += "file://https-server.service"
SRC_URI += "file://https-server.go"
SYSTEMD_PACKAGES = "${PN}"
INITSCRIPT_PACKAGES = "${PN}"
SYSTEMD_SERVICE_${PN} = "https-server.service"
# Path
MY_KEY = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/server.key"
MY_CERT = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/server.crt"
TESTVIDEO = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/testvideo.mp4"
MY_TEST = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/mytest"
# COMPILER
do_compile() {
go build /data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/https-server.go
}
# INSTALL
do_install() {
# install -d to create directories, "${D}/${bindir}" is /usr/bin
# systemd
install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/https-server.service ${D}${systemd_unitdir}/system
# HTTPS certificate and key
install -d "${D}/${bindir}"
install -m 0755 "${MY_KEY}" "${D}/${bindir}"
install -m 0755 "${MY_CERT}" "${D}/${bindir}"
install -m 0777 "${TESTVIDEO}" "${D}/${bindir}"
install -m 0777 "${MY_TEST}" "${D}/${bindir}"
# HTTPS Server Software
install -m 0755 "${S}/build/https-server" "${D}/${bindir}"
}
FILES_${PN} += "${bindir}"
FILES_${PN} += "${libexecdir}"
FILES_${PN} += "${systemd_system_unitdir}"
REQUIRED_DISTRO_FEATURES= "systemd"
the service https-server.service
[Unit]
Description=HTTPS Server sw startup script
[Service]
ExecStart=/usr/bin/https-server
[Install]
WantedBy=multi-user.target
I found out what was causing the problem:
At my local configuration at build/conf/local.conf
I had only this:
DISTRO_FEATURES_append = " systemd "
after I added the following:
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = ""
It was working fine. The process https-server started at startup.
I checked the running processes after startup with ps, as
systemctl was not working on my core-image-minimal image:
root#raspberrypi3:~# ps
[...]
152 root 861m S /usr/bin/https-server
[...]
root#raspberrypi3:~#
So this made the difference. Don't know if the missing space at my
DISTRO_FEATURES_append = " systemd" was also wrong... ??
#DISTRO_FEATURES_append = " systemd"
DISTRO_FEATURES_append = " systemd "
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = ""
The oe-pkgdata-util that #Nayfe suggested is a very helpful tool here:
user#machine:[...]/poky-warrior/build$
oe-pkgdata-util list-pkg-files -p https-server
https-server:
/lib/systemd/system/https-server.service
/usr/bin/https-server
/usr/bin/mytest
/usr/bin/server.crt
/usr/bin/server.key
/usr/bin/testvideo.mp4
https-server-dbg:
/usr/bin/.debug/https-server
https-server-dev:
https-server-ptest:
I also worked over the recipe https-server.bb from above
to avoid absolute paths as #Nayfe suggested. This was not causing
the problem but it was bad style.
Don't use /data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/ prefix, and add every files in SRC_URI instead.
require go-sw.inc
inherit go systemd
# "${D}/${bindir}" is /usr/bin
# ${WORKDIR} is path at local directory,
# this can be used instead of absolute paths
SRC_URI += "file://https-server.service"
SRC_URI += "file://https-server.go"
SRC_URI += "file://server.key"
SRC_URI += "file://server.crt"
SRC_URI += "file://testvideo.mp4"
SRC_URI += "file://mytest"
SYSTEMD_PACKAGES = "${PN}"
INITSCRIPT_PACKAGES = "${PN}"
SYSTEMD_SERVICE_${PN} = "https-server.service"
# COMPILER
do_compile() {
go build ${WORKDIR}/https-server.go
}
# INSTALL
do_install() {
# install -d to create directories, "${D}/${bindir}" is /usr/bin
# systemd
install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/https-server.service ${D}${systemd_unitdir}/system
# HTTPS certificate, key and testdata for https-server
install -d "${D}/${bindir}"
install -m 0755 ${WORKDIR}/server.key "${D}/${bindir}"
install -m 0755 ${WORKDIR}/server.crt "${D}/${bindir}"
install -m 0777 ${WORKDIR}/testvideo.mp4 "${D}/${bindir}"
install -m 0777 ${WORKDIR}/mytest "${D}/${bindir}"
# HTTPS Server Software
install -m 0755 "${WORKDIR}/build/https-server" "${D}/${bindir}"
}
# FILES_${PN} is Yocto’s way of specifying
# which files are expected to be installed along with which package
# (${PN} is a variable holding the main package’s name).
FILES_${PN} += "${bindir}"
FILES_${PN} += "${libexecdir}"
FILES_${PN} += "${systemd_system_unitdir}"
REQUIRED_DISTRO_FEATURES= "systemd"
Thanks to #kostix and #nayfe for their suggestions.
After updating dotnet-runtime in our Yocto based Linux distribution to version 2.1.12, I saw that the resulting image had increased significantly in size. On closer inspection i found that the image contained both the new 2.1.12 version and the older 2.1.11 version of the dotnet-runtime library. How can I ensure that older version are not included in the image? Do I have to change more that just the SRC_URI and checksum?
Here is the content of dotnet-runtime.bb
DESCRIPTION = ".NET Core Runtime, SDK & CLI tools"
HOMEPAGE = "https://www.microsoft.com/net/core"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE.txt;md5=42b611e7375c06a28601953626ab16cb"
COMPATIBLE_HOST ?= "x86_64.*-linux"
RDEPENDS_${PN} = "glibc zlib libunwind icu libcurl openssl krb5 libgssglue"
INSANE_SKIP_${PN} += "already-stripped staticdev file-rdeps libdir"
INHIBIT_PACKAGE_STRIP = "1"
INHIBIT_SYSROOT_STRIP = "1"
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
SRC_URI = "https://download.visualstudio.microsoft.com/download/pr/c1b620fe-7d8e-4685-b6ae-82b444dbc7a7/3d5610f0607da49ee014c61c6cd4e9af/aspne
tcore-runtime-2.1.12-linux-x64.tar.gz"
SRC_URI[sha256sum] = "cdb8816a437de168b25500b14ea32169abe610675ced08ca31f77f9542c2149a"
S = "${WORKDIR}"
do_install() {
install -d ${D}${bindir}
install -d ${D}${datadir}/dotnet
install -d ${D}${datadir}/dotnet/host/
install -d ${D}${datadir}/dotnet/shared/
install -m 0755 ${S}/dotnet ${D}${datadir}/dotnet
install -m 0644 ${S}/LICENSE.txt ${D}${datadir}/dotnet
install -m 0644 ${S}/ThirdPartyNotices.txt ${D}${datadir}/dotnet
cp -r --no-preserve=ownership ${S}/host/ ${D}${datadir}/dotnet/
cp -r --no-preserve=ownership ${S}/shared/ ${D}${datadir}/dotnet/
# Symlinks
cd ${D}${bindir}
ln -s ../../${datadir}/dotnet/dotnet dotnet || true
}
FILES_${PN} = "\
${bindir}/dotnet \
${datadir}/dotnet/ \
"
You might need to clean the cache of the recipe.
Just run:
$ bitbake -c clean {recipe name}
Then build your image again.
Hope it helps.
Adding the version number to the bitbake file, dotnet-runtime_2.1.12.bb instead of dotnet-runtime.bb, solved the issue.
Info about recipe naming http://www.embeddedlinux.org.cn/OEManual/recipes_versioning.html
I'm currently using yocto to build the system imx6sxsabresd (IMX6 Solo X). I have successfully built the image however I want to add a script to init.d to turn on a led. I'm appending to the linux-imx recipes within the meta-fsl-bsp-release layer.
This is my linux-imx.bbappend file:
FILESEXTRAPATHS_prepend := "${THISDIR}/linux-imx:"
SRC_URI += "file://0001-added-pad-for-heartbeat-led.patch \
file://heartbeat.sh \
file://heartbeat "
PACKAGECONFIG_append = " heartbeat"
inherit update-rc.d
INITSCRIPT_PACKAGES = "${PN}"
INITSCRIPT_PARAMS = "start"
INITSCRIPT_NAME = "heartbeat.sh"
do_install_append()
{
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/heartbeat.sh ${D}${sysconfdir}/init.d/heartbeat.sh
install -d ${D}/home/root
install -m 0755 ${WORKDIR}/heartbeat ${D}/home/root/heartbeat
}
FILES_${PN} += "${sysconfdir}/init.d/heartbeat.sh /home/root/heartbeat"
PACKAGES = "${PN}"
I'm able to create the sdcard image succesfully with the patch I've included in this bbappend file, however, the files heartbeat.sh and heartbeat are not copying to the final rootfs added to the output sdcard file. This is very odd because I'm able to see these files in their paths copied to ../tmp/work/imx6sxsabresd-poky-linux-gnueabi/linux-imx/4.14.98-r0/image/
As the comments suggests appending to the kernel recipe is the wrong way to go about this. You should instead add your own recipe and reference that recipe from the image definition (append to IMAGE_INSTALL).
Your recipe could look something like:
SUMMARY = "LED heartbeat init script"
inherit update-rc.d
SRC_URI += "\
file://heartbeat.sh \
"
do_install() {
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/heartbeat.sh ${D}${sysconfdir}/init.d/
}
FILES_${PN} = "${sysconfdir}/init.d/heartbeat.sh"
INITSCRIPT_NAME = "heartbeat.sh"
INITSCRIPT_PARAMS = "start 90 5 . stop 20 0 1 6 ."
My aim is to create Bitbake recipe, that will install config file in /etc directory, and script, that will apply this config into /ect/init.d directory (and invoke update-rc-d).
I already saw another similar question (Bitbake not installing my file in the rootfs image). I did almost exactly what this guy did, but unfortunately it didn't work.
The problem is that Bitbake does not complain on anything, but just not adds these files to rootfs.
Here is my current recipe. I also put my script and config files to two directories: files, and alsa-config, which resides inside recipe directory.
SUMMARY = "Alsa Config"
DESCRIPTION = "Adds alsa configuration file, and startup script that applies it."
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI += " \
file://my-alsa-config \
file://asound.state \
"
PACKAGE_ARCH = "${MACHINE_ARCH}"
S = "${WORKDIR}"
INITSCRIPT_NAME = "my-alsa-config"
INITSCRIPT_PARAMS = "defaults 99 01"
inherit autotools update-rc.d
do_install() {
install -m 0644 ${WORKDIR}/asound.state ${D}${sysconfdir}
}
FILES_${PN} += "${sysconfdir}/asound.state"
In my local.conf I added line:
CORE_IMAGE_EXTRA_INSTALL += "alsa-config "
Please, can anybody help?
Fortunately, I was able to solve the problem. Here is the solution:
SUMMARY = "Alsa Config"
DESCRIPTION = "Adds alsa configuration file, and startup script that applies it."
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI += " \
file://my-alsa-config \
file://asound.state \
"
PACKAGE_ARCH = "${MACHINE_ARCH}"
S = "${WORKDIR}"
INITSCRIPT_NAME = "my-alsa-config"
INITSCRIPT_PARAMS = "defaults 99 01"
inherit autotools update-rc.d
do_install() {
install -d ${D}${sysconfdir}/init.d/
install -m 0755 ${WORKDIR}/my-alsa-config ${D}${sysconfdir}/init.d/
install -m 0644 ${WORKDIR}/asound.state ${D}${sysconfdir}/
}
FILES_${PN} += "${sysconfdir}/asound.state \
${sysconfdir}/my-alsa-config"
A little bit of comments:
PACKAGE_ARCH has to be set properly. In my case, when I didn't have it, execute permissions for script file were not set for some reason.
do_install() has to create every directory, that is needed. Even if I know, that in my rootfs there will be /etc directory, I have to create it. And I'm not sure if it is necessary, but it's better to have slash at the end of install directory, just in case.
Init scripts that are to be installed to launch at startup has to be installed too;)
Scripts must have proper permissions set.