Yocto: patch kernel module Makefile - makefile

I have a Linux kernel for NXP i.MX6. There are some capture kernel modules in /driver/media/platform/mxc/capture.
One of the files called mxc_v4l2_capture.c. I had to change this file for using it with my own new kernel driver.
I created a repository with my driver and the sources for mxc_v4l2_capture. Then I made a new Yocto recipe in my layer recipies-kernel -> kernel-modules->my-kernel-module.bb
Yocto can build these two kernel modules (my-kernel-module.ko and mxc_v4l2_capture.ko).
Okay, now there is a problem because the kernel recipe already builds the mxc_v4l2_capture module. Therefore I want to manipulate the Makefile for the original kernel modules and exclude the make of mxc_v4l2_capture.
I have created the patch but I don't know how to use the patch with Yocto. Where to place it and how can I call it?
Normally I put a patch into a .bbappend file and finish but I don't know the name of the recipe that build the kernel modules.
It would be great if there is a way without manipulating this Makefile.
Is there a way to solve this with my kernel module recipe?

mxc_v4l2_capture.c is in-tree kernel driver. If you want to change the in-tree driver code and compile, it's highly recommended to patch the kernel and compile the kernel with usual recipe.
Having additional bitbake recipe for the in-tree kernel module is not necessary. To patch the kernel and compile, you can use .bbappend or .bb itself. For example,
if you have recipes-kernel/linux/linux-stable_4.19.75.bb in your Yocto BSP layer, you can add the patch to SRC_URI as below.
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:"
SRC_URI += "file://mxc_v4l2_capture.patch"
Now, you create recipes-kernel/linux/linux-stable-4.19.75/ and copy the mxc_v4l2_capture.patch file inside.
Or if you don't have permission or not possible to modify the Kernel recipe in BSP layer, you can create .bbappend in your custom layer. For the above example, you can create linux-stable_4.19.75.bbappend (specific version) or linux-stable_%.bbappend (any version). Then place the same content as mentioned above.
Yocto supports various patch formats, refer here for more details.

Look at this answer I wrote some days ago. The steps are basically the same. Using
devtool modify virtual/kernel
will create a working copy in build/workspace where you can do the work you want. Commiting those changes to the local branch and running
devtool finish linux-mainline <path-to-your-layer>
will create a .bbappend file with the patches already created and put to the correct location for you.
If you want to learn how to do it manually follow the advice #Parthiban gave.

Related

Yocto, remove autotools from (userspace) package build process

Userspace package built for and along with root file system image of some embedded Linux-based system here (using Yocto project) apparently uses autotools - one can see Makefile.am's and configure.ac in package's sources. pkg-config or its successor seems to be used too (.pc.in is present), however out-of scope here.
Package in focus here does it this way (by involving autotools) as in the beginning of its development it was apparently the line of lowest resistance to copy and adopt build scripts from similar but already-existing package.
Actually autotools seem to be dispensable when building with Yocto, as Yocto build system meta data do specify target precisely enough for every target. For good reason standard build flow in Yocto is download, unpack, patch, configure, build,... with scan-and-detect-target-environment not included in this chain.
Now I wonder if it was good to streamline package's build process by removing autotools stage. I'm going to conduct it by proceeding in sequence of few steps starting with replacing .am file with real makefile. Question is if it will be sufficient enough to find env. variables defined and used in .am and .ac then transfer them to makefile? Remaining target-device specification should actually come from Yocto build system meta data. Possibly it will work this straightforward if to build package in scope of root file system image build. But how to ensure build environment provides complete target device specification when building only this package bitbake package-name?
Replacing autotools with a bare makefile isn't a trivial operation, as https://nibblestew.blogspot.co.uk/2017/12/a-simple-makefile-is-unicorn.html demonstrates nicely.
If you don't want to use autotools in your packages then alternatives such as Meson are generally faster.

How to add netconsole to kernel with OpenWRT

I'm using OpenWRT and I'm trying to work with netconsole instead of serial cable to debug kernel messages. By default, netconsole is not defined in OpenWRT, and I can't add it through menuconfig. There is no documentation for it anywhere. Any help to add netconsole to the kernel would be much appreciated! Thanks
Run: make kernel_menuconfig and select the option.
But that alone won't help you. Netconsole requires kernel boot parameters to be set, most important, the destination address where the console messages are sent. You need to modify your bootloader to pass that parameter to the kernel.
I found one way to do this.
First you need to look at your .config file, which is found in the linux folder with the version you working with.
for example, I'm working with qca/src/linux-3.14.
This .config is being build in the compilation.
you can see the field
# CONFIG_NETCONSOLE is not set
The configurations in this file will define what will be built and what not.
So in order to build this module, go to your target folder, in linux/generic/ there is another configs files, mine is config-3.14. yours will be as your linux version you using.
change CONFIG_NETCONSOLE is not set to CONFIG_NETCONSOLE=m
and add CONFIG_NETCONSOLE_DYNAMIC=y'.
Now in compilation, the first .config file will be with the correct configuration and netconsole.ko module will be created.
This is valid for adding to kernel any module that affected by .config file.
Of course, you need to add this module manually, or add the module as part of kernel CONFIG_NETCONSOLE=y but I've had some problems with this.

How do I recompile a single Linux kernel module?

I need to build mmc_block.ko but with MMC_BLOCK_MINORS=16. I do not wish to build the entire kernel. I am using Ubuntu 15.10. How do I do this?
Dpending on how the Makefile has been written, a module can be compiled out of the kernel tree or in the kernel tree.
Concerning your specific example, I assume the module is the one shipped with the kernel and therefore the Makefile has been written for in-tree compilation. In this case, you can just type make modules to rebuild the module, provided that the kernel has been already compiled (which is a mandatory condition also for out-of-the-tree compilation).

Access patches from recipe in a different layer

I'm attempting to setup the avr toolchain while still utilizing the upstream binutils and gcc recipes. For example, the base recipe for binutils is in yocto/poky/meta/recipes-devtools/binutils/. I have my custom avr-flavored recipe in yocto/meta-avr/recipes-devtools/avr-binutils/.
Inside the custom avr recipe are a few environment variable changes (TARGET_PREFIX, TARGET_SYS, etc), and then a "require recipes-devtools/binutils/binutils-cross_2.23.2.bb". This lets me depend on the upstream binutils recipe without having to replicate everything manually.
Now, the problem I'm having is that the upstream recipe has a bunch of patches that get applied. I can't figure out how to have my custom recipe point to a filepath outside its layer so I can use the patches that already exist. I've tried using FILESEXTRAPATHS_prepend with no luck.
I think you're looking for a .bbappend file, which will inherit the existing recipe and allow you to override some parts of it.

How to add kernel module to LTIB target image

I have create a new Kernel Module following The Linux Kernel Module Programming Guide.I want to add my module to the [config -> Package selection -> package List]
and distribute my module with target image
â–ºDevelopment Environment
boundary device sabrelite board
LTIB (i.MX6 kernel 4.1.0)
I put my kernel module's source on [/home/USER/ltib/rpm/BUILD/myModule] path. (just like hello_mod example module which explained in "The Linux Kernel Module Programming Guide")
but when i build target image it does not compile.
hello_mod example module can be selected in configuration mode(./ltib -m config).
How can I add my module to this config -> Package selection -> package List
If you want to build from make menuconfig, that you probably should change the makefiles.
Check this documentation from the linux kernel. Taken from it:
Normal developers are people who work on features such as device drivers, file systems, and network protocols. These people need to
maintain the kbuild Makefiles for the subsystem they are working on.
In order to do this effectively, they need some overall knowledge
about the kernel Makefiles, plus detailed knowledge about the public
interface for kbuild.

Resources