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.
Related
I've found various kernel configs in kernel/configs/q.
When I alter them, and run mm in kernel/msm-4.14 the kernel is not rebuilt.
Where do I edit the kernel config, such that a kernel rebuild is forced when mm is run?
The kernel is built separately from the Android platform first. Then the Android platform build system is pointed at where the kernel image is located, using the TARGET_PREBUILT_KERNEL environment variable.
Here is an outline of how I usually configure and build. I have done it this way for both Android 9 and 10, for various vendors. The scheme I use is mentioned in the docs here. Non-Google kernels usually don't come with version control (repo), I don't know what you're dealing with so I'll cover both.
Configuring the kernel
For repo-checkout kernels, you do the config in build/build.config. Basically, after defconfig was taken as basis, you use the ${KERNEL_DIR}/scripts/config tool to alter the config. This usually looks as follows:
POST_DEFCONFIG_CMDS="check_defconfig && update_config"
function update_config() {
${KERNEL_DIR}/scripts/config --file ${OUT_DIR}/.config \
-d CONFIG_SOMETHING_I_DISABLE \
-e CONFIG_SOMETHING_I_ENABLE \
--set-val CONFIG_FOO = 123
}
If you don't have a repo-checkout kernel, locations and details may differ but the basic idea is usually the same: Find/Create the script that kicks of the build, and add invocations of the config tool after making defconfig.
Run the config tool by its own to see full options and more info on its usage, but the above is usually all you need. Beware: If you make syntactically-correct invalid changes (e.g. enable symbols of which the dependencies are not met), the build system will NOT complain and ignore these changes silently. If you face this situation, e.g. use menuconfig to find out what's wrong, as it shows dependencies.
Building AOSP / Making boot.img
After you've built your kernel, you will have Image.lz4 in out/.../dist (or Image.gz in out/.../private/msm-google/arch/arm64/boot). You go to your Android source, and in addition to the usual things (source build/envsetup.sh, lunch) you point the build system at the image you built, e.g. export TARGET_PREBUILT_KERNEL=/path/to/Image.lz4. Then just start the build normally, e.g. make bootimage or m droid.
Note that for Android 10 at least in some cases, you'll have to copy over the kernel modules from out/.../dist too, since the new kernel can't load the old ones. With this part, I am having problems myself at the moment. I think they have to be copied to device/VENDOR/DEVICE (e.g. google/coral-kernel), you may also copy your kernel image there btw, since the original prebuilt one also is there by default. The problem is that at least in my case, the new kernel modules were not copied to device after all.
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.
Im playing around with buildroot together with linaro 2016.11 for arm.
Im actually building the latest Linux Kernel for the i.MX6 Processors.
So far so good.
I have setup the buildroot config with
$ make makeconfig
I have configured an external toolchain (the linaro one). I also configured the uboot to be built. In the uboot section, i had to choose the appropriate board name for the defconfig.
Now the problem:
I have done a full make which was successfull without any errors.
After that, i have changed the uboot board name to something which does not exist in the source. Just to make sure everything is working correct.
i have restartet the build process with
$ make uboot-rebuild
to my confusion, the build was sucessfull. After a deeper look to the shell commands, i saw, that the new config was just ignored. I have tried everything without success. It only rebuilds correctly after i do a
$make clean
$make
but this will build the whole thing again and it takes a lot of time.
I hope someone could help me with that and give me some hint.
Thanks.
make <pkg>-rebuild rebuilds the package without applying a new configuration, so what happens is correct.
After changing the U-Boot configuration you have to run make uboot-reconfigure. This command first applies the configuration, then it does the same actions as uboot-rebuild.
See also the Buildroot manual, section Understanding how to rebuild packages.
There are some kernel variables(for example tcp_frto) which can be accessible from the user space by using the commands like sysctl net.ipv4.tcp_frto or cat /proc/sys/net/ipv4/tcp_frto.
It can be read and easily changed from bash command line. But I want to change them from the kernel module that I am writing.
How can I read and write into these variables from the module?
(Linux source code uses sysctl_tcp_frto to access this variable which was declared in the tcp.h file. Maybe possible to EXPORT the varible name and then can be found by modules, but I don't want to change the source and compile it again). I am trying to make a Loadable Kernel Module (LKM) without compiling the source every time.
Unless a Linux kernel variable is made global (using EXPORT_SYMBOL or one of its variants) it cannot be read outside its scope.
As there is an alternate means to access tcp_frto using the procfs, you can use VFS functions to do the same from within a Linux kernel module as shown in these sample code snippets.
How this works and why it is generally NOT a good idea (unless except for debugging) is described in detail in this article.
Can anyone please help me with getting the proper header files needed for the copy_from_user method?
I found a few of the include headers I need, but my compiler keeps saying that they are not found. I am running CentOS on my machine. I have tried yum installing various kernel-headers and devel packages but still no luck.
Is there a special segment I need to add in my gcc command? Everything I find on the Internet only tells me how to use the method but not actually how I can get access to it in the first place.
I assume you're developing a kernel module, because outside of it trying to use copy_from_user wouldn't make sense. Either way, in the kernel use:
#include <linux/uaccess.h>
Edit: if building a kernel module is what you want, you may want to look at this Hello World Linux Kernel Module. Specifically the makefile portion may be of interest to you (search for obj-m).