Installing a kernel module in rootfs in yocto build system - yocto

I have a out of tree kernel module(hello.ko) from a vendor which i need to install in rootfs using yocto build. The kernel module is built on the same kernel which yocto build system is using.
I do not have the kernel source for the above module so i cannot build it using recipe.
How can i only install the kernel module in rootfs and to which path it will be installed.
Can anyone share a recipe for this.
I am new to yocto and recently started using it.
Inputs will be helpful.

Loadable kernel module are located in /lib/modules/<kernel_version>/kernel/drivers/
You can create a recipe and add your pre-compiled kernel module in files/lib/modules/<kernel_version>/kernel/drivers/
Then, add the line MODULE_NAME = "hello" to the module_autoload list. This is an example :
#Recipe for hello.ko
SUMMARY = "Hello world"
LICENSE = "closed"
SRC_URI = "file://hello.ko"
S="${WORKDIR}"
do_install()
{
install -d ${D}/lib/modules/${KERNEL_VERSION}/kernel/drivers
install -m 0644 ${WORKDIR}/hello.ko ${D}/lib/modules/${KERNEL_VERSION}/kernel/drivers/
}
FILES_${PN} += "/lib/modules/${KERNEL_VERSION}/kernel/drivers/hello.ko"
MODULE_NAME = "hello"
module_autoload = "${MODULE_NAME}"

Related

dev packages not getting included in Yocto SDK

We are generating Yocto SDK using the following command: bitbake -c populate_sdk <image-name>
Yocto Branch : Dunfell
We don't see header files getting included in the SDK, for example we have libmodbus part of IMAGE_INSTALL, we don't see modbus.h file in SDK which is present in libmodbus-dev package
Could you execute the command below so we can verify your setup:
bitbake -e <image-name> | grep SDKIMAGE_FEATURES
Development packages are automatically included into SDK when they are installed into the image when SDKIMAGE_FEATURES variable defines it
SDKIMAGE_FEATURES = "dev-pkgs staticdev-pkgs"
https://www.yoctoproject.org/docs/3.1/mega-manual/mega-manual.html#var-SDKIMAGE_FEATURES

Install CANopen package in yocto

I have tried installing CANopen in yocto using below command. But the CANOpen is not getting installed.
bitbake canopensocket_git
In local.conf file I had added
CORE_IMAGE_EXTRA_INSTALL += " canopensocket_git "
How I can install canopen package?
Any input is also considered.
First of all, that's a syntax error canopensocket_git.
The recipe name ${PN} is canopensocket and every thing after the_ is the version number ${PV}.
So, you need to only specify the recipe name. Or if you have different versions you can specify one by:
PREFERRED_VERSION_canopensocket = "version_here"
That being said, I found a recipe for canopensocket in here.
But if fails and it is not updated with latest github commit.
I did some modifications on it, here is my recipe:
SUMMARY = "Linux CANOpen tools"
DESCRIPTION = "Linux CANOpen Protocol Stack Tools"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://gpl-2.0.txt;md5=b234ee4d69f5fce4486a80fdaf4a4263"
SRC_URI = "git://github.com/CANopenNode/CANopenSocket.git"
SRCREV = "ec9735165502e08b5d2e84d641833709b6faeb96"
S = "${WORKDIR}/git"
do_compile_prepend() {
cd ${S}
git submodule init
git submodule update
}
do_compile() {
cd ${S}/cocomm
make
cd ${S}/canopencgi
make
}
do_install(){
install -d ${D}${bindir}
install -m 0755 ${S}/cocomm/cocomm ${D}${bindir}
install -m 0755 ${S}/canopencgi/canopen.cgi ${D}${bindir}
}
FILES_${PN} += "${bindir}/*"
I modified do_compile, do_install and added the packaging of FILES.
And I set SRCREV to the latest v4 tag commit instead of AUTOREV.
I do not know what this recipe does, but I compiled it and the build was okay for me on a zeus build.
The build produced two binaries: cocomm and canopen.cgi .
No if you want to install it to your image, add this to you cutom image recipe:
IMAGE_INSTALL_append = " canopensocket"

How to install file in include directory yocto

I'm trying install files extracted from tar file, but non of my files are installing under usr/include directory on target board, but I see my files under temp/work/aarch64/recipedir/image/usr/include/mydir/ and include/myfile.h. While building I haven't got any errors.
do_install() {
install -d ${D}${includedir}
mkdir -p ${D}${includedir}/mydir
install -m 0644 ${S}/include/myfile.h ${D}${includedir}
install -m 0644 ${S}/include/mydir/*.h ${D}${includedir}/mydir/
}
FILES_${PN} += "${includedir}/mydir
Everything in ${includedir} is put into ${PN}-dev by default.
c.f.: https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/conf/bitbake.conf#n316
You have to remember that a file can only be in one package. To determine in which package a file is going to make it, it's pretty simple. Starting from leftmost package in PACKAGES, the first package to have the file matching any path in FILES_<pkg> will have the file.
By default, ${PN}-dev appears before ${PN} in PACKAGES.
c.f.: http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/conf/bitbake.conf#n294
You can check which package has your file without "reverse-engineering" the whole thing by running oe-pkgdata-util find-path '/usr/include/mydir'.
If you really want this header file in your system (why?), you can either add ${PN}-dev to your image or hack things (remove the -dev package from PACKAGES or move ${PN} before ${PN}-dev, if you only have one file in ${includedir}, etc.).

rpm tool can't be used in yocto enviroment

In local.conf, I can see:
PACKAGE_CLASSES ?= "package_rpm"
However, after boot the yocto OS, the rpm command not found.
PACKAGE_CLASSES specifies the package manager the OpenEmbedded build system uses when packaging data. This will not add rpm package to your image.
To have rpm package to your image, add EXTRA_IMAGE_FEATURES += "package-management" to your conf/local.conf

How to install ruamel.yaml on a buildroot environment

ruamel.yaml seems to require PIP to install, which is not the default buildroot solution to build and install a Python package.
Is is possible to -at least- install a pure Python version of ruamel.yaml into a buildroot image - and how to circumvent the pip limitation?
Is is possible to cross-build ruamel.yaml?
Forcing RUAMEL_NO_PIP_INSTALL_CHECK env. var. does not help:
test compiling test_ruamel_yaml
running install
Checking .pth file support in ...
Failed to import the site module
ModuleNotFoundError: No module named '_sysconfigdata_m_linux_arm-linux-gnueabihf'
error: command '.../output/host/bin/python' failed with exit status 1
package/pkg-generic.mk:310: recipe for target '.../output/build/python-ruamel-yaml-0.15.45/.stamp_target_installed' failed
ruamel.yaml indeed requires pip to install from PyPI (using the .tar.gz or a .whl appropriate for your platform), this is documented.
The reason for this is that the fixes necessary to enable nested package installs where only implemented for pip (and not for easy_install or python setup.py installs).
That however does not preclude you from using ruamel.yaml, especially if you don't need the C extension (which is checked for at load time).
You can either check out a tagged version from bitbucket or untar a .tar.gz from PyPI and move the result to your site-packages directory:
$ virtualenv /tmp/ruamel_yaml_no_pip
Using base prefix '/opt/python/3.7'
New python executable in /tmp/ruamel_yaml_no_pip/bin/python
Installing setuptools, pip, wheel...done.
$ cd /tmp/ruamel_yaml_no_pip/
$ source bin/activate
(ruamel_yaml_no_pip) $ mkdir lib/python3.7/site-packages/ruamel/
(ruamel_yaml_no_pip) $ touch lib/python3.7/site-packages/ruamel/__init__.py
(ruamel_yaml_no_pip) $ wget -q https://files.pythonhosted.org/packages/63/a5/dba37230d6cf51f4cc19a486faf0f06871d9e87d25df0171b3225d20fc68/ruamel.yaml-0.15.45.tar.gz
(ruamel_yaml_no_pip) $ python -m ruamel.yaml
/tmp/ruamel_yaml_no_pip/bin/python: Error while finding module specification for 'ruamel.yaml' (ModuleNotFoundError: No module named 'ruamel')
(ruamel_yaml_no_pip) $ tar xf ruamel.yaml-0.15.45.tar.gz
(ruamel_yaml_no_pip) $ mv ruamel.yaml-0.15.45 lib/python3.7/site-packages/ruamel/yaml
(ruamel_yaml_no_pip) $ python -c 'from ruamel.yaml import YAML; print(YAML().load("{hello: world}")["hello"])'
world
(ruamel_yaml_no_pip)
(ruamel_yaml_no_pip) $ python -c 'from ruamel.yaml import __with_libyaml__ as X; print(X)'
False
(The URL is copied from the 0.15.45 project download page)
For development I normally just make a soft link from a virtualenv's site-packages to my ruamel directory.
I don't know how and if that translates to a buildroot environment (if so please publish your result).
I overlooked the buildroot documentation.
There is a critical parameter to define: SETUP_TYPE = setuptools rather than SETUP_TYPE = distutils.
With the following snippet:
PYTHON_RUAMEL_YAML_VERSION = 0.15.45
PYTHON_RUAMEL_YAML_SOURCE = ruamel.yaml-$(PYTHON_RUAMEL_YAML_VERSION).tar.gz
PYTHON_RUAMEL_YAML_SITE = https://pypi.python.org/packages/63/a5/dba37230d6cf51f4cc19a486faf0f06871d9e87d25df0171b3225d20fc68
PYTHON_RUAMEL_YAML_SETUP_TYPE = setuptools
PYTHON_RUAMEL_YAML_LICENSE = MIT
PYTHON_RUAMEL_YAML_LICENSE_FILES = LICENSE
PYTHON_RUAMEL_YAML_ENV += RUAMEL_NO_PIP_INSTALL_CHECK=1
$(eval $(python-package))
ruamel.yaml installs perfectly on the target image.