Yocto - adding out of tree kernel module - linux

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.

Related

Cannot add C file to Yocto Layer using bitbake

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"

How to apply patch file of dtsi(or dts) in yocto

I'm using yocto(ver.rocko) on ubuntu 18.04 and trying to apply patch file but I can't...
My target machine is qemuarm64 and linux kernel is linux-yocto.
Once do $ bitbake core-image-base, kernel source files are unpacked then target dtsi file is located at poky/build/tmp/work/aarch64-poky-linux/linux-libc-headers/4.12-r0/linux-4.12/arch/arm64/boot/dts/arm/juno-base.dtsi
And my custom meta-data files to patch are below:
poky/meta-custom/recipes-kernel/linux/linux-yocto_4.12.bbappend
poky/meta-custom/recipes-kernel/linux/files/juno-base.dtsi.patch
# poky/meta-custom/recipes-kernel/linux/linux-yocto_4.12.bbappend
FILESEXTRAPATHS_prepend := "${THISDIR}/files"
SRC_URI += "file://juno-base.dtsi.patch"
But after bitbake, patch file is created at poky/build/tmp/work/qemuarm64-poky-linux/linux-yocto/4.12.28+gitAUTOINC+2ae65226f6_e562267bae-r0/juno-base.dtsi.patch and patch-application doesn't work
I don't know what's wrong, what to do...
Plz let me know what should I do?
To create a simple patch for Yocto recipe sources, you can use git command in a simple way:
Your Linux work directory is:
poky/build/tmp/work/qemuarm64-poky-linux/linux-yocto/4.12.28+gitAUTOINC+2ae65226f6_e562267bae-r0
as you can see it is already a "git" directory which means that it is intialized with git already.
Here are clear steps for you to understand the method:
After adding your patch(juno-base.dtsi.patch) to SRC_URI I think your linux-yocto work directory is messed up, so follow me:
Clean the build
bitbake linux-yocto -c cleansstate
Remove the patch from SRC_URI
Apply any default patches
bitbake linux-yocto -c patch
Go to
poky/build/tmp/work/qemuarm64-poky-linux/linux-yocto/4.12.28+gitAUTOINC+2ae65226f6_e562267bae-r0
Make your modifications on
poky/build/tmp/work/qemuarm64-poky-linux/linux-yocto/4.12.28+gitAUTOINC+2ae65226f6_e562267bae-r0/arch/arm64/boot/dts/arm/juno-base.dtsi
and not in
poky/build/tmp/work/aarch64-poky-linux/linux-libc-headers/4.12-r0/linux-4.12/arch/arm64/boot/dts/arm/juno-base.dtsi
Now, open a terminal and change directory to
poky/build/tmp/work/qemuarm64-poky-linux/linux-yocto/4.12.28+gitAUTOINC+2ae65226f6_e562267bae-r0
Run: git status (You should see something like: modified arch/arm64/boot/dts/arm/juno-base.dtsi)
Run: git add arch/arm64/boot/dts/arm/juno-base.dtsi
Run: git commit -m "Patch for juni base dtsi"
Run: git format-patch -1
Now a new patch is created with the name "Patch-for-juni-base-dtsi.patch",
Now you can add it to linux-yocto_%.bbappend:
SRC_URI_append = " file://Patch-for-juni-base-dtsi.patch"
If the dtsi is not exist and you want to add it as a patch, do the same thing, when you run "git status" you will see a new added file, add it with "git add" and continue the commands.
After all of this, you can continue the build process with:
bitbake linux-yocto -C patch
Or, if you add the patch to SRC_URI the linux-yocto build will start from do_fetch.

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 generated nativesdk-cmake SDK is incomplete

For the past couple of days I have been trying to generate a viable CMake SDK with Yocto Project. I'm trying to generate SDK based on an image file which is given below:
#To build SDK, use bitbake meta-toolchain
DESCRIPTION = "Embeddev-LXDE image."
LICENSE="CLOSED"
IMAGE_INSTALL = "packagegroup-core-boot \
packagegroup-core-x11 \
packagegroup-lxde-base \
kernel-modules \
"
IMAGE_INSTALL_append = " nano git cmake qtbase qtchooser dbus packagegroup-core-ssh-openssh xterm"
#Framebuffer driver for tft
IMAGE_INSTALL_append = " xf86-video-fbdev"
IMAGE_INSTALL_append = " apt dpkg sudo tzdata glibc-utils localedef networkmanager pointercal xinit xkeyboard-config base-passwd liberation-fonts pkgconfig"
IMAGE_INSTALL_append = " wiringpi"
#Maybe consider connman instead of networkmanager
#vc-graphics is problematic with userland..
inherit populate_sdk
## SDK stuff, to build sdk use bitbake rpi-embeddev-lxde-image -c populate_sdk
# Add all static packages: SDKIMAGE_FEATURES += "staticdev-pkgs"
SDKIMAGE_FEATURES += "staticdev-pkgs"
SDKIMAGE_FEATURES += "dev-pkgs"
TOOLCHAIN_TARGET_TASK_append = " wiringpi-dev"
TOOLCHAIN_HOST_TASK_append = " nativesdk-cmake"
##
inherit distro_features_check
REQUIRED_DISTRO_FEATURES = "x11"
IMAGE_LINGUAS ?= " "
LICENSE = "MIT"
export IMAGE_BASENAME = "rpi-embeddev-lxde-image"
inherit core-image
ENABLE_SPI_BUS = "1"
ENABLE_I2C = "1"
# qtwebengine qtwebkit ...
do_image_prepend() {
}
I create my SDK with bitbake rpi-embeddev-lxde-image -c populate_sdk.
I would like to describe the exact problem. The problem is that nativesdk-cmake is not correctly installed in the SDK. Cmake 3.10.2 recipe gives:
do_install_append_class-nativesdk() {
mkdir -p ${D}${datadir}/cmake
install -m 644 ${WORKDIR}/OEToolchainConfig.cmake ${D}${datadir}/cmake/
mkdir -p ${D}${SDKPATHNATIVE}/environment-setup.d
install -m 644 ${WORKDIR}/environment.d-cmake.sh ${D}${SDKPATHNATIVE}/environment-setup.d/cmake.sh
}
FILES_${PN}_append_class-nativesdk = " ${SDKPATHNATIVE}"
FILES_${PN} += "${datadir}/cmake-${CMAKE_MAJOR_VERSION}"
FILES_${PN}-doc += "${docdir}/cmake-${CMAKE_MAJOR_VERSION}"
BBCLASSEXTEND = "nativesdk"
Tracing the root of the problem, I have seen that the cmake/ directory that should be created is created in:
/home/<user>/poky/build/tmp/work/x86_64-nativesdk-pokysdk-linux/nativesdk-cmake/3.10.2-r0/image/opt/poky/2.4+snapshot/sysroots/x86_64-pokysdk-linux/usr/share/cmake/
However, this cmake directory is not valid in /opt/poky/2.4+snapshot/sysroots/x86_64-pokysdk-linux/usr/share/, -where it is actually needed- when I install the SDK to /opt, unfortunately.
Do I need to know anything else or do anything else regarding how to properly generate SDK?
I am really stuck here any help is much appreciated indeed.
Thanks in advance.
EDIT: I moved TOOLCHAIN_TASK statements to layer.conf and used bitbake meta-toolchain which also didn't work.
EDIT2: I used cmake version 3.6 with PREFERRED_PROVIDER_cmake = "3.6.1", which also did not work.
There seems to be a bug in the imminent Yocto Project 2.5, Sumo, release. Here, sysroots/x86_64-chargestorm-linux/usr/share/cmake/OEToolchainConfig.cmake seems to be omitted.
The temporary solution for this is to add
TOOLCHAIN_HOST_TASK += "nativesdk-cmake-dev"
And yes, using a release is always helpful, especially if your new to some project. Just remember to always use the same release branches for all your included layers. And personally, I'd not start a new project based on Morty, which was released 1.5 years ago when writing this, as it's likely to go out of official Yocto Project support rather soon.
As an aside, it seems that it is still a bug (Or would this be mis-feature at this point...?) in Sumo. Just got bit by this...workaround looks to be the same as described.
(Note: This is a release at this point in time... X-D)
Problem solved by using a release (I used "morty", and not the "master branch") for every layer and poky itself. This is apparently very important.

Library installation with yocto recipe

have a bit of a problem creating a recipe for yocto. More specifically i have to install a library from git that normally installs like this:
./bootstrap
./configure --sysconfdir=/etc
make
sudo make install
My question is how can I add this to the recipe functions do_configure, do_compile, do_install. Haven't found much information or examples online.
Update 1:
This is the library that i want to integrate into yocto
https://github.com/NXPNFCLinux/linux_libnfc-nci
It's just a regular autotools based library. The main issues, that someone ought to fix, are to make the build create versioned libraries and to add a LICENSE or COPYING file.
However, a quick recipe could look like:
SUMMARY = "Linux NFC stack for NCI based NXP NFC Controllers"
HOMEPAGE = ""
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://src/include/linux_nfc_api.h;endline=17;md5=42fdb99b3ff2c12f594b22a774cb7308"
SECTION = "libs"
SRC_URI = "git://github.com/NXPNFCLinux/linux_libnfc-nci.git"
SRCREV = "118ea118cecda55c1b6a87d151a77b04515687df"
PV = "2.0+git${SRCPV}"
S = "${WORKDIR}/git"
inherit autotools
FILES_${PN} += "${libdir}/libnfc_nci_linux-1.so"
# Make sure it isn’t in the dev package’s files list
FILES_SOLIBSDEV = "${libdir}/libnfc_nci_linux.so"
A versioned library would allow us to remove the last three lines.

Resources