How do I add script files to a Raspberry Pi filesystem using a custom Yocto recipe? - raspberry-pi

I have a working Yocto image for a RaspberryPi3. I want to add 3 script files /etc/ppp/peers/. I would have thought that adding non-compiled files to the root file-system was a fairly generic thing to do but the only examples I can find are using compiled files and inheriting the autotools recipe.
Is there an example of how to add text files or script files to a Yocto root filesystem this somewhere?
Either a How To write up or an existing recipe that takes a set of text files and places them onto the target's rootfs.
I must be missing something because I cannot get the file files onto the system.
I tried using do_deploy, but that puts files into my ../tmp/deploy/images/raspberrypi3/etc/ppp/ which would be helpful for scripts to aid in image deployment. It is not what I want though as the scripts need to be on the target.
Running a do_install() with or without a blank do_compile() has not resulted in things getting onto the target either. Unless there is something about using ${sysconfdir} or ${IMAGE_ROOTFS} or ${S} or ${D} or ${DEPLOYDIR} or ${WORKDIR} which is particular to the Pi. I'd provide an example of my script but having changed it so many times in the last two days there is not much worth of sharing just one iteration.
Anything that resembles the following with;
${IMAGE_ROOTFS} possibly substituted for ${D} or missing
do_install replaced with do_deploy.
There are probably other permutations that I have tried.
#
# Copy the ppp script files for <vendor> chips to the target filesystem
# These files are based on the details provided in
#
SUMMARY = "PPP Scripts for ..."
SECTION = "net"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
DESCRIPTION = "A set of Linux PPP scripts blar blar"
RDEPENDS_${PN} = "ppp"
SRC_URI += "file://<provider>-ppp"
SRC_URI += "file://<provider>-chat-connect"
SRC_URI += "file://<provider>-chat-disconnect"
S = "${WORKDIR}"
#PACKAGES =+ "${PN} ${PN}-staticdev"
#DEPLOYDIR = "${WORKDIR}/deploy-${PN}"
#D = "${DEPLOYDIR}"
inherit allarch
# Install script on target's root file-system
do_install () {
# Install init script and default settings
install -d ${IMAGE_ROOTFS}${sysconfdir}
install -d ${IMAGE_ROOTFS}${sysconfdir}/ppp/
install -d ${IMAGE_ROOTFS}${sysconfdir}/ppp/peers/
install -m 0755 ${S}/<provider>-ppp ${IMAGE_ROOTFS}${sysconfdir}/ppp/peers/
install -m 0755 ${S}/<provider>-chat-connect ${IMAGE_ROOTFS}${sysconfdir}/ppp/peers/
install -m 0755 ${S}/<provider>-chat-disconnect ${IMAGE_ROOTFS}${sysconfdir}/ppp/peers/
}
# Mark the files which are part of this package
FILES_${PN} += "${sysconfdir}/ppp/"
FILES_${PN} += "${sysconfdir}/ppp/peers/"
FILES_${PN} += "${sysconfdir}/ppp/peers/<provider>-ppp"
FILES_${PN} += "${sysconfdir}/ppp/peers/<provider>-chat-connect"
FILES_${PN} += "${sysconfdir}/ppp/peers/<provider>-chat-disconnect"
I can find a lot of helloworld.c and automate examples. There must be some basic ones for adding scripts somewhere? My googlefu is very weak, I blame a lingering cold.

You should be using install -m 0755 ${WORKDIR}/<provider>-ppp ${D}${sysconfdir}/ppp/peer in your recipe. Have you added the resulting package to your image recipe? You could look at ${WORKDIR}/packages-split/${PN} to confirm that your files have been properly packaged.

Related

Yocto & wpa_supplicant - installing libwpa_client.so

I'm working with this Yocto/ Bitbake recipe for wpa_supplicant (v2.9) which is a bbappend for this recipe. I had significant difficulties getting the associated library (libwpa_client.so) included in the install process during my Yocto/ Poky build. Eventually I created my own bbappend which contained:
# Force build of library libwpa_client.so
do_configure_append() {
echo 'CONFIG_BUILD_WPA_CLIENT_SO=y' >> wpa_supplicant/.config
}
# Avoid QA errors:
INSANE_SKIP_${PN} += " ldflags"
INHIBIT_PACKAGE_STRIP = "1"
INHIBIT_SYSROOT_STRIP = "1"
SOLIBS = ".so"
FILES_SOLIBSDEV = ""
# Force install of libwpa_client.so
do_install_append(){
install -d ${D}${libdir}
install -m 0644 ${S}/wpa_supplicant/libwpa_client.so ${D}${libdir}
}
Using the config option CONFIG_BUILD_WPA_CLIENT_SO=y failed to install the library so thats why I went with the do_install_append() method. I find it hard to believe this hasn't come up before for others so I think I'm missing something, I can't find similar hacks/ patches.
Can't someone point out if I'm missing something obvious?? There's a patch file for v2.10 which may be associated with this issue, but I think it's more an issue with the Makefile as the library file was successfully built for v2.9, just not populated to the final image.
If this isn't a waste of half a day perhaps this will help others.
Regards,

Create a recipe for a QT5 application

I have been struggling for too long, so I need help :)
I made a big QT5.8 application and usually when I want to compile it with my PC I just have to run the following command: qmake -qt=5.9 -spec linux-arm-gnueabihf-g++ -config configuration_name.
With this command, I can cross compile my source code for the armhf architecture using linux-arm-gnueabihf-g++ toolchain.
But now, as can easily create a yocto image for my target (Raspberry pi), I want to make a recipe in order to compile my qt software and put it into my image.
For now, I achieved to perform these following task in my recipe without errors:
do_fetch -> Yocto fetch the source from git repo (OK)
do_unpack -> OK
After that I want to perform a qmake command in order to generate my makefile, but here is my problem :/
First, I included the qmake5 class in my recipe using
require recipes-qt/qt5/qt5.inc
Then I tried a lot of things..
writing "qmake" into the do_configure task doesn't work. Last thing I tried was: '${OE_QMAKE_QMAKE} ${S}/my_software.pro -config my_config' but still the same error:
Could not find qmake spec 'linux-oe-g++'
I don't know what to do and I can't find any recipe exemple doing the things that I want to do.
If somebody already experienced this issue or have experience compiling qt5 software with a yocto recipe I would like your help :)
my recipe:
LICENSE = "CLOSED"
LIC_FILES_CHKSUM = " "
USERNAME = "****"
PASSWORD = "*****"
S = "${WORKDIR}/git"
require recipes-qt/qt5/qt5.inc
do_fetch(){
git clone http://${USERNAME}:${PASSWORD}#gitlab.....
}
do_configure () {
${OE_QMAKE_QMAKE} ${S}/my_software.pro -config my_config
}
Thanks
Short answer
Add "inherit qmake5" and let Yocto take care of it :)
Long answer
Here's an example of how I added a QT project. It is not using git, it is using local files. However for getting one step further I suggest:
Use my way as a test. Copy the QT project to /yocto/local_sources/Myproject/
and make this known to Yocto by using FILESEXTRAPATHS_prepend_ (as shown below).
If this works on your environment, adapt it to your needs (e.g. build from git instead of local_source, which is better off course.)
This way is tested and works also well for later remote-debugging with qt-creator and the yocto SDK by the way. Stick to Yocto, it's worth it in the end.
Here's my .bb file:
#
# Build QT xyz application
#
SUMMARY = "..."
SECTION = "Mysection"
LICENSE = "CLOSED"
#Add whatever you need here
DEPENDS += "qtbase qtmultimedia qtsvg"
#Add here your .pro and all other relevant files (if you use git later this step will be less tedious ...)
SRC_URI += "file://Myproject.pro"
SRC_URI += "file://*.h"
SRC_URI += "file://*.cpp"
SRC_URI += "file://subdir1/*.h"
SRC_URI += "file://subdir1/*.cpp"
SRC_URI += "file://subdir2/*.h"
SRC_URI += "file://subdir2/*.cpp"
SRC_URI += "file://subdir2/subdir3/*.h"
SRC_URI += "file://subdir2/subdir3/*.cpp"
#If you need autostart:
#SRC_URI += "file://myproject.service"
#Register for root file system aggregation
FILES_${PN} += "${bindir}/Myproject"
#RBE todo: both needed ?
FILESEXTRAPATHS_prepend_${PN} := "/yocto/local_sources/Myproject/Src:"
FILESEXTRAPATHS_prepend := "/yocto/local_sources/Myproject/Src:"
S = "${WORKDIR}"
#If you want to auto-start this add:
#SYSTEMD_SERVICE_${PN} = "Myproject.service"
FILES_${PN} = "${datadir} ${bindir} ${systemd_unitdir}"
FILES_${PN}-dbg = "${datadir}/${PN}/.debug"
FILES_${PN}-dev = "/usr/src"
#Check what's needed in your case ...
RDEPENDS_${PN} += "\
qtmultimedia-qmlplugins \
qtvirtualkeyboard \
qtquickcontrols2-qmlplugins \
gstreamer1.0-libav \
gstreamer1.0-plugins-base-audioconvert \
gstreamer1.0-plugins-base-audioresample \
gstreamer1.0-plugins-base-playback \
gstreamer1.0-plugins-base-typefindfunctions \
gstreamer1.0-plugins-base-videoconvert \
gstreamer1.0-plugins-base-videoscale \
gstreamer1.0-plugins-base-volume \
gstreamer1.0-plugins-base-vorbis \
gstreamer1.0-plugins-good-autodetect \
gstreamer1.0-plugins-good-matroska \
gstreamer1.0-plugins-good-ossaudio \
gstreamer1.0-plugins-good-videofilter \
"
do_install_append () {
# Install application
install -d ${D}${bindir}
install -m 0755 Myproject ${D}${bindir}/
# Uncomment if you want to autostart this application as a service
#install -Dm 0644 ${WORKDIR}/myproject.service ${D}${systemd_system_unitdir}/myproject.service
# Install resource files (example)
#install -d ${D}${datadir}/${PN}/Images
#for f in ${S}/Images/*; do \
# install -Dm 0644 $f ${D}${datadir}/${PN}/Images/
#done
}
#Also inherit "systemd" if you need autostart
inherit qmake5

Yocto: Create a New Directory in etcdir

I am new to Yocto,
I want to create a directory in /etc and copy my server certificates into that directory. I tried doing below, But it it not creating any directory in /etc, however i am not getting any compilation error:
DESCRIPTION = "OC sample service"
SUMMARY = "Install and start a systemd service and copy server certificates"
LICENSE = "MIT"
SRC_URI = "file://service.tar.gz"
inherit systemd
S = "${WORKDIR}/service"
SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE_${PN} = "sample.service"
SYSTEMD_AUTO_ENABLE = "enable"
INSANE_SKIP_${PN} += "installed-vs-shipped"
do_configure() {
:
}
do_compile() {
:
}
do_install() {
install -d ${D}${systemd_unitdir}/system
install -m 0755 ${S}/sample.service ${D}${systemd_unitdir}/system
mkdir -p ${D}${etcdir}/oc_certs
install -m 0755 ${S}/certs/* ${D}${etcdir}/oc_certs
}
FILES_${PN} = "${systemd_unitdir}/system
"
Now the problem is, sample.service is successfully being placed to the location but /etc/oc_certs is not being created.
In addition to LetoThe2nd's answer: the ${etcdir} variable is usually empty. If you want a variable for /etc, it is ${sysconfdir}. So your files are probably installed to root directory.
Check output of bitbake -e <your_recipe> and try to find etcdir to verify.
Also drop INSANE_SKIP_${PN} += "installed-vs-shipped" which hides the error your are trying to find (you will see what is installed where but not shipped).
BTW LetoThe2nd's answer is also needed, because you are overwriting (instead of appending FILES_${PN}, otherwise it wouldn't be needed. The ${sysconfdir} is already part of FILES_${PN}.
"Not working" is a rather bad error description, but the most probable issue is that it does not get included in the image. This is because bitbakes packaging mechanisms do not know about that directory, so add it with:
FILES_${PN} += "${etcdir}/oc_certs"
If you need further assistance, please extend your question with a precise error description, respectively the corresponding log.
You are missing a / after ${D}. To create a directory say mydir in your /etc folder, just add the following code in the do_install() of your recipe.
do_install() {
install -d ${D}/etc/mydir
}

Yocto: Install different config files based on MACHINE type or target image

I've got a couple of HW platforms (same cpu, etc.) that require different asound.conf files.
The way that I'm controlling the target platform is via the MACHINE variable and target image (i.e., MACHINE=machine_1 nice bitbake machine-1-bringup-image)
Normally, if just replacing the conf file I'd just create an alsa-state.bbappend and create a do_install_append function to replace it.
However since the different HW platforms require differ conf files I'm unsure how to handle it.
I've tried putting some logic into the append file do_install_append function but it's not working out. It's not always picking up the correct file (like it thinks that nothing has changed so that it uses the previous cached conf?)
Here's an example of one of the append files that I've tried:
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " \ file://asound_MACHINE1.conf \
file://asound_MACHINE2.conf \ "
do_install_append() {
echo " alsa-state.bbappend MACHINE: ${MACHINE}"
if [ "${MACHINE}" = "machine_1" ]; then
echo " machine_1"
echo " installing ${WORKDIR}/asound_MACHINE1.conf to ${D}${sysconfdir}/asound.conf"
install -m 644 ${WORKDIR}/asound_MACHINE1.conf {D}${sysconfdir}/asound.conf
else
echo " installing ${WORKDIR}/asound_MACHINE2.conf to ${D}${sysconfdir}/asound.conf"
install -m 644 ${WORKDIR}/asound_MACHINE2.conf ${D}${sysconfdir}/asound.conf
fi
}
I can see the correct echoes in the logs per the logic.
At any rate I don't think that the path I'm going down is the best way to deal with this.
Is there a 'standard' way to have different files installed based on either the target image or MACHINE variable?
do_install_append () {
// install common things here
}
do_install_append_machine-1 () {
// install machine-1 specific things here
}
do_install_append_machine-2 () {
// install machine-2 specific things here
}
The value of MACHINE is automatically added to OVERRIDES, which can be used at the end of a function append to have a MACHINE-specific addition to a function.
Maybe useful: https://www.yoctoproject.org/docs/2.4/mega-manual/mega-manual.html#var-OVERRIDES
You can have configuration files in machine specific directories in your particular case (just a specific configuration file for each machine). OpenEmbedded will fetch the most specific one. The directory structure in your recipe directory will look like:
files/<machine1>/asound.conf
files/<machine2>/asound.conf
And your alsa-state.bbappend will contain just one line (you don't need to change do_install because alsa-state.bb already installs asound.conf):
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
BTW: We are using that setup to have specific asound.state file per machine in our project.
Moreover, OpenEmbedded will detect that SRC_URI contains machine specific file and change the PACKAGE_ARCH accordingly, see: https://www.yoctoproject.org/docs/2.5/mega-manual/mega-manual.html#var-SRC_URI_OVERRIDES_PACKAGE_ARCH
Few more words on machine, distro or arch specific files: OE is trying to fetch the most specific file in file:// fetcher. It searches also in the directories named by distro (e.g files/<distro>/asound.conf) and architecture (e.g. armv7a, arm). It might be useful if you want to have file specific for some set of devices. More information: https://www.yoctoproject.org/docs/2.5/mega-manual/mega-manual.html#var-FILESOVERRIDES and also https://www.yoctoproject.org/docs/2.5/mega-manual/mega-manual.html#best-practices-to-follow-when-creating-layers (section "Place Machine-Specific Files in Machine-Specific Locations")
The above answer by clsulliv worked better than advertised. For future reference below is the append file I used:
FILESEXTRAPATHS_prepend:= "${THISDIR}/${PN}:"
SRC_URI += " \
file://machine1_asound.conf \
file://machine2_asound.conf \
"
do_install_append_machine1() {
echo " machine1"
echo " installing ${WORKDIR}/machine1_asound.conf to ${D}${sysconfdir}/asound.conf"
install -m 644 ${WORKDIR}/machine1_asound.conf ${D}${sysconfdir}/asound.conf
}
do_install_append_machine2() {
echo " machine2"
echo " installing ${WORKDIR}/machine2_asound.conf to ${D}${sysconfdir}/asound.conf"
install -m 644 ${WORKDIR}/machine2_asound.conf ${D}${sysconfdir}/asound.conf
}
Thanks for the help!

bitbake recipe - doing a simple copy of the image

I am attempting to write a recipe that would simple copy two files (MyfileA , MyfileB) to a specific directory when the overall image is built. This is what my directory structure looks like:
MyDir/MyRecipe.bb
MyDir/files/MyfileA
MyDir/files/MyfileB
I would like the two files to be copied to a folder in home (which would not exist initially hence the directories should be created)The folder lets say is called "Testfolder"
This is what my bitbake file looks like
DESCRIPTION = "Testing Bitbake file"
PR = "r0"
SRC_URI = "file://MyfileA \
file://MyfileB "
do_install() {
install -d MyfileA ~/TestFolder/
}
Kindly let me know if I am doing something wrong here?
When i run bitbake on this I get the following
The BBPATH variable is not set and bitbake did not find a conf/bblayers.conf file in the expected location.
Maybe you accidentally invoked bitbake from the wrong directory?
DEBUG: Removed the following variables from the environment: LANG, LS_COLORS, LESSCLOSE, XDG_RUNTIME_DIR, SHLVL, SSH_TTY, OLDPWD, LESSOPEN, SSH_CLIENT, MAIL, SSH_CONNECTION, XDG_SESSION_ID, _, BUILDDIR
Any help in this regard would be appreciated.
First of all, to create your own meta-layer, you should run command yocto-layer create MyRecipe in your Yocto Environment. This is to make sure that you have all the necessary element in your meta layer. Make sure to put the new meta-layer into conf/bblayers.conf
Creating HelloWorld Recipe Video can be found here
Second, to copy a file from one to another directories.
DESCRIPTION = "Testing Bitbake file"
SECTION = "TESTING"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
PR = "r0"
SRC_URI = "file://MyfileA \
file://MyfileB "
#specify where to get the files
S = "${WORKDIR}"
inherit allarch
#create the folder in target machine
#${D} is the directory of the target machine
#move the file from working directory to the target machine
do_install() {
install -d ${D}/TestFolder
install -m ${WORKDIR}/MyfileA ${D}/TestFolder
}
To get more in details, this is my understanding of how the files move around in Yocto.
You have a directory that stored metadata in /sourced/meta-mylayer/recipes-myRecipe/. In that directory, there would be a folder with the same name as the recipe. I.E. myRecipe/ myRecipe_001.bb.
You would store the files that are related to myRecipe.bb (usually it is a patch) in myRecipe/ so that SRC_URI will get into that myRecipe/ directory to grab files. I.E. myFileA, myFileB
Then, you specify the S. This is the location in the Build Directory where unpacked recipe source code resides. By that mean, myFileA and myFileB are moved/copied to there when myRecipe builds.
Usually, S is equal to ${WORKDIR}, this is equivalent to ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR}
The actual directory depends on several things:
TMPDIR: The top-level build output directory
MULTIMACH_TARGET_SYS: The target system identifier
PN: The recipe name
EXTENDPE: The epoch - (if PE is not specified, which is usually the case for most recipes, then EXTENDPE is blank)
PV: The recipe version
PR: The recipe revision
After that, we inherit allarch. This class is used for architecture independent recipes/data files (usually scripts).
Then, the last thing we have to do is copy the files.
${D} is the location in the Build Directory where components are installed by do_install task. This location defaults to ${WORKDIR}/image
${WORKDIR}/image can also be described as the / directory in the target system.
Go to ${D} directory and create a folder call TestFolder
Then, copy myFileA from ${WORKDIR} to the ${D}/TestFolder
P.S. Please add comment to fix. There might be mistaken information here, cause I learned all this by myself.