Cannot add C file to Yocto Layer using bitbake - multithreading

I have a C file binary to add as custom layer in the yocto and run in qemu. I have created layer using bitbake-layers create-layer meta-custLayer and added using bitbake-layers add-layer meta-custLayer. The file tree of meta-custLayer is as:
The example_0.1.bb file has the following:
SUMMARY = "bitbake-layers recipe"
DESCRIPTION = "Recipe created by bitbake-layers"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://threading.c"
S = "${WORKDIR}"
TARGET_CC_ARCH += "${LDFLAGS}"
do_compile(){
$(CC) threading.c -o threads -lpthreads
}
do_install(){
install -d ${D}${bindir}
install -m 0755 threads
${D}${bindir}s
}
When the command bitbake example is executed, this is the output:
ERROR: example-0.1-r0 do_compile: Execution of '/home/sajil/edm_yocto/sources/poky/build/tmp/work/core2-64-poky-linux/example/0.1-r0/temp/run.do_compile.1806553' failed with exit code 127:
/home/sajil/edm_yocto/sources/poky/build/tmp/work/core2-64-poky-linux/example/0.1-r0/temp/run.do_compile.1806553: 99: CC: not found
/home/sajil/edm_yocto/sources/poky/build/tmp/work/core2-64-poky-linux/example/0.1-r0/temp/run.do_compile.1806553: 99: threading.c: not found
WARNING: exit code 127 from a shell command.
when bitbake core-image-minimal is executed, terminal shows that threads is unbuildable and runs into error:
ERROR: Nothing RPROVIDES 'threads' (but /home/sajil/edm_yocto/sources/poky/meta/recipes-core/images/core-image-minimal.bb RDEPENDS on or otherwise requires it)
NOTE: Runtime target 'threads' is unbuildable, removing...
Missing or unbuildable dependency chain was: ['threads']
ERROR: Required build target 'core-image-minimal' has no buildable providers.
Missing or unbuildable dependency chain was: ['core-image-minimal', 'threads']
I checked the path of the custom layer directory, being correct. I am clueless about the errors I am confronting.
For now my task is to run the C-file (adding it as a layer) on QEMU. I am unable to build the image for the same.
I would appreciate some help and insights!

There is multiple issues on your recipe:
Your do_compile command does not indicate where to find your .c file
You should use ${CC} instead of $(CC)
lpthread does not end with and s
do_compile() {
${CC} ${S}/threading.c -o ${S}/threads -lpthread
}
Your do_install does not provide the correct path to your binary:
do_install() {
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/threads ${D}${bindir}
}
At the end you should populate the packages:
FILES_${PN} = "${bindir}"
Edit about threads unbuildable:
threads is unbuildable because the recipe does not mention that the package is threads.
Here you have some options:
Rename your recipe to threads_0.1.bb (I recommend you to use a less generic name)
use the PACKAGES variable in your recipe. You will need to modify the FILES_* variable too. (a bit complicated if you are new to Yocto)
Use the current recipe name, and change the IMAGE_INSTALL += "threads" to IMAGE_INSTALL += "example"

Related

Yocto - adding out of tree kernel module

I would like to add a wifi out-of-tree kernel module to my Yocto project. I found a layer on Open Embedded Layer Index with the driver that I need (https://layers.openembedded.org/layerindex/branch/master/layer/meta-rtlwifi/). I cannot build an image because I get the following error from bitbake:
install: cannot stat
'build/tmp/work/<machine_dir>/rtl8821cu/5.8.1.2-git-r0/git/8821cu.ko': No
such file or directory WARNING: exit code 1 from a shell command.
This file should be created by Makefile, but I have no errors generating by make.
The recipe for the driver is as follows:
SUMMARY = "RTL8821CU kernel driver (wifi)"
DESCRIPTION = "RTL8821CU kernel driver"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://LICENSE;md5=b234ee4d69f5fce4486a80fdaf4a4263"
SRCREV = "2dace83e5f4cada52bbe3930b864c3eb82390b1f"
SRC_URI = "git://github.com/spriteguard/rtl8821CU;protocol=https "
S = "${WORKDIR}/git"
PV = "5.8.1.2-git"
DEPENDS = "virtual/kernel"
inherit module
#This is the only line added by me to this recipe because sh wasn't able to find `bc`
EXTRA_OEMAKE += "-I${S}/usr/bin' "
EXTRA_OEMAKE += "ARCH=${ARCH}"
EXTRA_OEMAKE += "KSRC=${STAGING_KERNEL_BUILDDIR}"
MODULES_INSTALL_TARGET="install"
do_install () {
install -d ${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel/drivers/net/wireless
install -m 0644 ${B}/8821cu.ko ${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel/drivers/net/wireless/rtl8821cu.ko
}
FILES_${PN} += "${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel/drivers/net/wireless/rtl8821cu.ko"
RPROVIDES_${PN} += "kernel-module-${PN}-${KERNEL_VERSION}"
I have tried to add the following task:
do_compile () {
oe_runmake
}
But it changed nothing. I needed to add one line to this recipe: EXTRA_OEMAKE += "-I${S}/usr/bin' " because sh wasn't able to find bc. Maybe bitbake doesn't see one more file/library?
When I cloned the repo on my PC and just run make, the file *.ko was created. What can cause problems in Yocto with creating this module? I use the official layer and recipe so I suppose it should works.
You have to replace SRCREV. Because as far as I can see, the SRCREV of the above recipe is using the old version. You can check "git log" and choose the latest commit.
I used master branch and bitbake successfully.

Disable do_package_qa during bitbake

Is there any way to disable do_package_qa step during bitbake
Actually I have a precompiled binary which I want to copy to my rootfs. I have tried install as well as cp in the do_install section of my recipe.
In both the cases, I am getting QA issue which complains about libQt5Qml.so and libQt5Quick.so not being found in RDEPENDS.
I have tried INSANE_SKIP_${PN} , RDEPENDS_${PN} and DEPENDS to suppress the errors but I am not able to do so.
Is there any way with which I can compile my recipe ?
Recipe
DESCRIPTION = "..."
LICENSE = "CLOSED"
RDEPENDS_${PN} = "qtbase"
SRC_URI = "file://hello.c \
file://basic \
"
S = "${WORKDIR}"
do_compile() {
${CC} hello.c -o hello
}
do_install() {
install -d ${D}/opt/mybin/
install -m 0755 hello ${D}/opt/mybin/
install -m 0755 basic ${D}/opt/mybin/
}
FILES_${PN} = "/opt/mybin/"
INSANE_SKIP_${PN} = "ldflags"
Error
ERROR: my-binary-1.0-r0 do_package_qa: QA Issue: /opt/mybin/basic contained in package my-binary requires libQt5Qml.so.5(Qt_5), but no providers found in RDEPENDS_my-binary? [file-rdeps]
ERROR: my-binary-1.0-r0 do_package_qa: QA Issue: /opt/mybin/basic contained in package my-binary requires libQt5Quick.so.5(Qt_5), but no providers found in RDEPENDS_my-binary? [file-rdeps]
INSANE_SKIP_${PN} = "file-rdeps" might help to fix the error.
Reported issue is something similar to below link
Errors including shared prebuilt libraries in petalinux
Maybe adding
RDEPENDS_${PN} += " libQt5Qml.so.5(Qt_5) libQt5Quick.so.5(Qt_5)"
to your recipe it will solve the QA issue. Lets try.

Yocto install a script along with a kernel module

I want to install a script into target rootfs that will help set up a driver. I tried doing something like this (as I wanted it to be installed along the kernel module):
SUMMARY = "Kernel module with script"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "\
file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
inherit module
SRC_URI = "file://Makefile"
SRC_URI += "file://char-drv-ll.c"
SRC_URI += "file://start-char-drv-ll.sh"
S = "${WORKDIR}"
# The inherit of module.bbclass will automatically name module packages with
# "kernel-module-" prefix as required by the oe-core build environment.
RPROVIDES_${PN} += "kernel-module-char-drv-ll"
do_install_append() {
install -d ${D}${bindir}
install -m 0755 ${S}/start-char-drv-ll.sh ${D}${bindir}
}
RDEPENDS_${PN} += "bash"
FILES_${PN} += "${bindir}/start-char-drv-ll.sh"
However, after running the image in QEMU, I see that module is installed, but the script is nowhere to be found.
Where am I wrong in my reasoning?

Yocto build for a static library fails with error "No Match Found"

I am trying to include a Yocto recipe in the image which I wrote for static library.
Created recipes-test/static folder in my own layer .
Created 'static_0.1.bb' file in this folder
Created 'files' folder inside the 'recipes-test/static' folder
Copied the below files.
hello.c
char * hello (void)
{
return "Hello";
}
world.c
char *world(void)
{
return "World";
}
helloworld.h
#ifndef HELLOWORLD_H
#define HELLOWORLD_H
char * hello (void);
char * world (void);
#endif
Created recipe with the following content:
DESCRIPTION = "Simple helloworld example static library"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = " file://hello.c \
file://world.c \
file://helloworld.h "
S = "${WORKDIR}"
do_compile() {
${CC} -c hello.c world.c
${AR} -cvq libhelloworld.a hello.o world.o
}
do_install() {
install -d ${D}${includedir}
install -d ${D}${libdir}
install -m 0755 helloworld.h ${D}${includedir}
install -m 0755 libhelloworld.a ${D}${libdir}
}
When i say bitbake static , static library is created in the tmp/work folder
When i included it in conf/local.conf file with the following line:
IMAGE_INSTALL_append = " static"
The build fails at the root file creating stage with the following error:
not found other for:
not found modules for:
not found deltainfo for:
not found updateinfo for:
oe-repo: using metadata from Tue 02 Jul 2019 03:54:50 AM UTC.
No module defaults found
No match for argument: static
Error: Unable to find a match
Can you please help me to resolve the error
Update: After changing IMAGE_INSTALL_append = " static-staticdev", i get the following error:
No module defaults found
--> Starting dependency resolution
--> Finished dependency resolution
Error:
Problem: package static-staticdev-0.1-r0.cortexa7t2hf_neon_vfpv4 requires static-dev = 0.1-r0, but none of the providers can be installed
- conflicting requests
- nothing provides static = 0.1-r0 needed by static-dev-0.1-r0.cortexa7t2hf_neon_vfpv4
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
Yocto will automatically split up the files installed in ${D} into different packages. In your case the helloworld.h will go into ${PN}-dev (${PN} equals static in your case, but I write ${PN} to avoid confusion) and libhelloworld.a will go into ${PN}-staticdev, but since there's no other files there will not be a package called ${PN} since it would be empty.
If you really want the static library to end up in the image, use IMAGE_INSTALL_append = "static-staticdev"
There's also a problem that there is no file that will be included in the plain ${PN} package, which with the default settings means that no such package will be created. This is a problem since the ${PN}-dev package has a runtime dependency on ${PN}. This can be solved by allowing the creation of ${PN} even if it's empty, enable this by adding ALLOW_EMPTY_${PN} = "1"

Bitbake - non debug package contains .debug directory

I need to create a .ipk package from Bitbake script. My bb file:
...
PR = "r0"
PACKAGES = "${PN}"
SRC_URI = " \
file://mypackage \
file://mypackage-startup \
"
do_install() {
install -m 0775 -d ${D}/userdata/costume
install -m 0744 ${WORKDIR}/mypackage ${D}/userdata/costume/mypackage
install -m 0644 ${WORKDIR}/mypackage-startup ${D}/userdata/costume/mypackage-startup
}
FILES_${PN} += "/userdata/costume"
FILES_${PN}-dbg += "/userdata/costume/.debug"
...
But I receive the next error:
ERROR: QA Issue with mypackage: non debug package contains .debug
directory: mypackage path
/work/.../mypackage-1.0-r0/packages-split/mypackage/userdata/costume/.debug/mypackage
FATAL: QA run found fatal errors. Please consider fixing them. ERROR:
Error in executing python function in:
/home/nickname/build/mypackage.bb ERROR:
Exception: Message:1 ERROR: Printing the
environment of the function ERROR: Function do_package_qa failed
ERROR: TaskFailed event exception, aborting ERROR: Build of
/home/nickname/build/mypackage.bb do_package failed
Line with FILES_${PN}-dbg was added after net surfing. But this fix not helped in my situation.
You set PACKAGES = "${PN}" which means the debug package is never created (the default value of PACKAGES does contain ${PN}-dbg).
Either remove the PACKAGES line (if you didn't have a good reason for it) or use
PACKAGES = "${PN}-dbg ${PN}"

Resources