Yocto install a script along with a kernel module - linux

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?

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"

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.

How to transfer python3-flask project into yocto image?

I am a beginner in yocto. Till now i have learnt about how to build a yocto image and add recipes through layers.openembedded. But i am not able to figure out e.g. i have developed a python3-flask project in my PC and then i want to copy/transfer that project into my yocto os. how can i do that? do i have to make something like executable of that project and then copy that into my os using some recipe?
I have seen this recipe but i am not able to understand what does LIC_FILES_CHSUM means and where to get it? where should i put these file e.g. setup.py? in the same directory as my .bb file?
and on building where my project would be copied in the yocto os?
DESCRIPTION = "Simple Python setuptools hello world application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://setup.py \
file://python-helloworld.py \
file://helloworld/__init__.py \
file://helloworld/main.py"
S = "${WORKDIR}"
inherit setuptools
do_install_append () {
install -d ${D}${bindir}
install -m 0755 python-helloworld.py ${D}${bindir}
}
The LICENSE field should obviously correspond to the license you picked for your SW. LIC_FILES_CHKSUM needs a file that holds the actual license defined in LICENSE and its md5sum passed as an "argument". It is just a way to monitor if the license ever changes. Then its md5sum changes and then the recipe fail to build because the license probably changed and requires the maintainer's attention.
THISDIR being the directory containing the recipe (not exactly but enough for the example), files in SRC_URI will be searched for in FILESPATH (which is first ${THISDIR}/<recipe_name>-<recipe_version> then ${THISDIR}/<recipe-name> then ${THISDIR}/files). So you need to put files (the ones starting with file://) declared in SRC_URI into one of those directories.
Best would actually to have your SW in a git repo somewhere. This better follows the philosophy of having SW source code separate from your build system (what if you decide you want to use a different build system later?).
When you're wondering what some variables or tasks are doing, I highly recommend looking them up on the mega manual: https://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html. This works extremely well as a "dictionary". The documentation is great albeit dense and long but it is rare not to found what you look for as a beginner.
Update
LIC_FILES_CHKSUM can be found in yocto meta/files/common-licenses in the Source Directory. You can also take your own license and check the checksum with md5sum filename and copy that to bb file. If your SW is to be distributed, it is highly recommended to have the license mentioned somewhere in your sources. So better use that part of the code in LIC_FILES_CHKSUM than using the ones in ${COMMON_LICENSE_DIR} so that people will know if and when there is a license change in your project.
The below recipe works fine and you can find your app in /usr/bin directory.
DESCRIPTION = "Simple Python setuptools application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://setup.py \
file://packagetest.py \
file://example/__init__.py \
file://example/file1.py \
file://example/file2.py \
file://example/file3.py"
S = "${WORKDIR}"
inherit pypi setuptools3
do_install_append () {
install -d ${D}${bindir}
install -m 0755 packagetest.py ${D}${bindir}
}

Cross compile package using crossscript in yocto for node-sqlite3?

my yocto setup has nodejs recipe. Which works properly. I'm trying to cross-compile node-sqlite3 package by adding new recipe. node-sqlite3 depends on node-gyp script. script uses command node(machine-image).
Build setup trying to use HOST path instead of machine image path.
node-sqlite3.bb
SUMMARY = "Asynchronous, non-blocking SQLite3 bindings for Node.js"
SECTION = "nodejs/module"
LICENSE = "MIT"
SRC_URI = "https://github.com/mapbox/node-sqlite3/archive/v${PV}.tar.gz"
LIC_FILES_CHKSUM = "file://LICENSE;md5=79558839a9db3e807e4ae6f8cd100c1c"
SRC_URI[md5sum] = "c17036d0db2d147d9af8d7b7057c8c8c"
SRC_URI[sha256sum] = "80d58f84073e524f7d4a39e2ec7b77908862a5629b9a4d882127c807cc093597"
S = "${WORKDIR}/node-sqlite3-${PV}"
DEPENDS = "nodejs node-gyp sqlite3"
inherit nodejs-arch
EXTRA_OECONF = "--with-node=${STAGING_BINDIR_CROSS}/node"
do_configure() {
export LD="${CXX}"
export GYP_DEFINES="sysroot=${STAGING_DIR_HOST}"
node-gyp --arch ${TARGET_ARCH} configure
}
do_compile() {
export LD="${CXX}"
export GYP_DEFINES="sysroot=${STAGING_DIR_HOST}"
node-gyp --arch ${TARGET_ARCH} build
}
do_install() {
install -d ${D}${libdir}/nodejs/sqlite3
install ${S}/build/Release/node_sqlite3.node ${D}${libdir}/nodejs/
install ${S}/lib/sqlite3.js ${D}${libdir}/nodejs/sqlite3/
install ${S}/lib/index.js ${D}${libdir}/nodejs/sqlite3/
install ${S}/lib/trace.js ${D}${libdir}/nodejs/sqlite3/
}
FILES_${PN} += "${libdir}/nodejs ${bindir}node-gyp"
cat node-gyp
#!/usr/bin/env sh
if [ "x$npm_config_node_gyp" = "x" ]; then
node "`dirname "$0"`/../../node_modules/node-gyp/bin/node-gyp.js" "$#"
else
"$npm_config_node_gyp" "$#"
fi
The following binary path should be considered for configuring, compiling.
node-gyp script is used from hosttools not from image directory.
/poky/build/tmp-glibc/hosttools/node-gyp
/poky/build/tmp-glibc/work/target-sdk/machine-image/1.0-r0/rootfs/usr/lib/node_modules/npm/bin/node-gyp-bin/node-gyp
node-gyp script uses node command to compile scipts, build recipe fails to point to image binary path.
build/tmp-glibc/work/target-sdk/machine-image/1.0-r0/rootfs/usr/bin/node
But I'm getting the following error.
| build/tmp-glibc/work/armv7ahf-neon-oe-linux-gnueabi/node-sqlite3/4.0.8-r0/recipe-sysroot
| /usr/bin/env: ‘node’: No such file or directory
How to fix above issues? What steps need to correct or include in node-sqlite3.bb recipe?

Bitbake recipe to have pre and post install action

I am writing an custom recipe for the Bitbake for an Makefile based project. We are able to create the RPMs with all the files place in the package but we are not able to find a way for pre and post install action.
As the application runs as service we want to stop it in pre-install step and then start it in post-install step.
But I am not able to find the same so any thoughts to achieve it.
Below is the sample recipe we written for it.
DESCRIPTION = "Simple helloworld application"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
PR = "r0"
SRC_URI = "file://helloworld.c"
DEPENDS = "boost"
S = "${WORKDIR}"
do_compile() {
${CC} helloworld.c -o helloworld
}
PACKAGES = "helloworld"
do_install() {
install -d ${D}${bindir}
install -m 0755 helloworld ${D}${bindir}
install -d ${D}${sysconfig}/init.d
install -m 0755 ${S}/service ${D}${sysconfig}/init.d
}
I do see INITSCRIPT_PACKAGES and INITSCRIPT_PARAMS but their description doesn't talk about being pre and post action.
So any thoughts for putting %pre and %post (in terms of RPM spec) for this purpose.
You can add post install scripts in your .bb:
pkg_postinst_PACKAGENAME() {
#!/bin/sh -e
# Commands to carry out
}
Reference: Section 5.3.16 http://www.yoctoproject.org/docs/1.7.1/mega-manual/mega-manual.html
According to the documentation the examples only runs during image creation time. There is also another function that will only run on the first boot (and never after it). It uses the meta/recipes-devtools/run-postinsts recipe to accomplish this.
I ran into the same issue. See this post for how I did the post install script. Hopefully you can glean from that answer enough to modify it for your script.

Resources