How to use custom device tree source correctly in buildroot? - u-boot

I made a copy of the dts from <linux>/board/arch/arm/boot/dts/imx28-evk.dts for using with my custom board. My custom device-tree is named imx28-custom.dts and is pointed in the Out of tree custom DTS menu entry (BR2_LINUX_KERNEL_CUSTOM_DTS_PATH) in the Buildroot config.
However u-boot is configured to use the existing MX28 board config. After building a kernel I have imx28-custom.dtb and zImage in the <buildroot>/output/images folder.
When the system boots, u-boot tells that imx28-evk.dtb is not found. Why was imx28-custom.dtb built but is not found by u-boot? Why u-boot doesn't find its own device-tree (imx28-evk.dtb) for itself and my custom device-tree for the kernel? I assumed that BR2_LINUX_KERNEL_CUSTOM_DTS_PATH relates only to the kernel. How can my custom device-tree be passed to the kernel if u-boot tries to use its own imx28-evk.dtb for this?

u-boot complaining about not finding the device-tree is related to the Linux kernel: when booting, u-boot loads the device-tree and kernel image from the storage to specified addresses in the memory and then passes control to the kernel. The default configuration for the i.MX28-EVK board is to pass the imx28-evk.dtb file.
The BR2_LINUX_KERNEL_CUSTOM_DTS_PATH only serves to include the custom device-tree in the files to build and install but does not configure u-boot to use it.
Which device-tree u-boot passes to the kernel is defined by u-boot's CONFIG_DEFAULT_FDT_FILE option (you can edit this by typing make uboot-menuconfig (see my note at the end) then going under Boot to set the Default fdt file). This option should be set to something like imx28-custom.dtb.
How to configure u-boot from Buildroot is described here and here to make them permanent.
In the case of the i.MX28-EVK, Buildroot uses the Legacy build system (which is to be used up to u-boot 2015.04, but the config uses 2020.04) which does not allow the use of the make uboot-menuconfig command. You should safely be able to change that. You need to set the Build system to Kconfig and set the Board defconfig to mx28evk.

Related

Rebuild linux kernel module for another architecture

Suppose I have x86-64 machine with some version of Linux kernel. And I have directory with kernel sources of another version. The kernel was built for arm arch and loaded to the appropriate device.
Now I need to rebuild just one kernel module in this big directory.
I read this post and tried something like
make path/to/the/module/itself.ko
, but it build module for amd64.
When I try
make M=path/to/the/module/
it gives a bunch of arch-related C-errors.
Could someone explain how can easy use this ARM-ready environment to rebuild some kernel module?
You could try:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- M=path/to/the/module/
Also read:
Cross compiling a kernel module
gcc-arm-linux-gnueabi command not found

Loading my own device driver as builtin in Yocto on my own meta layer

I wrote my own USB driver for hardware and I want to add this driver as builtin. I have seen this post where they create a recipe to set as module and not builtin.
http://wiki.kaeilos.com/index.php/Howto_build_a_kernel_module_out_of_the_kernel_tree
Can you please guys help me in creating a recipe to set the module as builtin.
Thanks for your time.
You can't have external modules built into Linux Kernel. So you need to place your driver into drivers/usb/ (based on the hardware type it needs to be placed in drivers/usb/host/ if it is host controller driver or drivers/usb/dwc* or drivers/usb/gadget/udc if it is gadget driver) of your Linux Kernel tree.
Then you need to add according configuration in Kconfig and Makefile in drivers/usb. Finally you need to enable this as build in driver in defconfig/.config for building.
In short,
Place your driver in drivers/usb
Add Kconfig and Makefile. For example, CONFIG_USB_HW_HCD
Add to defconfig as CONFIG_USB_HW_HCD=y. In Yocto you can specify the defconfig file as file://defconfig in your SRC_URI.
EDIT:
As you are using meta-intel directly, you can create patch and bbappend to it. To do it,
git clone "intel kernel repo"
Add driver as mentioned above. Copy to drivers/usb, add Kconfig, Makefile entry.
Add this driver to git repo using git add + git commit
Create patch using git format-patch
Create a .bbappend file and add this patch. You can place this .bbappend file in any of your custom layer or in meta-intel itself.
Add defconfig fragment also into the .bbappend file for your Linux Kernel.
This way you don't need to have separate repo of same Linux Kernel.
I hope your initial module will have module_init() and module_exit calls.
To make this usb module to be part of builtin kernel, very first thing is to modify you source code to remove module_init or module_exit calls add platform calls probe, init, etc./
Copy your source file to appropriate source directory like "driver/usb/*"
Add a entry in KCONFIG file with some description of that driver and also add rules for its dependencies
Add entry in Makefile for conditional compilation.
Configure your kernel using make menuconfig to enable your config tag and build your kernel

Using Pulse Width Modulation (PWM) interface in kernel module

I'm new in kernel development driver and I'm trying to develop a Linux kernel module, using the this module information:
http://lxr.free-electrons.com/source/drivers/pwm/pwm-tiehrpwm.c
But I didn't understand how to use it. How could adapt this module or better, how to create a new module using functions contained in this file like ehrpwm_pwm_config, ehrpwm_pwm_enable?
PS:I don't want to use sysfs, I would configure the pwm signal programmatically. I'm using a Beaglebone Black board running a Debian distribution , and cape-universaln.
Thanks
You need to enable CONFIG_PWM_TIEHRPWM in your .config file of your linux-kernel. By default, CONFIG_PWM_TIEHRPWM is not set and you need to enable it as CONFIG_PWM_TIEHRPWM=y, if you want to build it as a part of kernel image, or as CONFIG_PWM_TIEHRPWM=m, if you want to build it as a LKM.
Then, build your kernel as make -j12 and insmod your module as:
#insmod /lib/modules/$uname -r/drivers/pwm/pwm_tiehrpwm.ko if you have built it as a LKM. Check Linux kernel documentation on how to configure pwm!

Compiling an individual kernel module (Debian/Ubuntu)

I need to modify the ELF loader's kernel implementation of an Ubuntu 14.04 distribution. Having downloaded the sources using:
sudo apt-get source linux-image-$(uname -r)
I ran the configuration script:
make config
in the root source tree. After a seemingly endless sequence of input requests, the script created the .config file needed to build the kernel(or a set of modules). The kernel version I am using is linux-3.13.0 and has the following source tree layout:
$ ls
arch COPYING crypto Documentation dropped.txt FileSystemMakefile fs init Kbuild kernel MAINTAINERS mm README samples security sound ubuntu virt
block CREDITS debian.master drivers elf.dat firmware include ipc Kconfig lib Makefile net REPORTING-BUGS scripts shortcuts tools usr
The ELF loader is located in /path/to/source/fs/binfmt_elf.c. Following this question,in order to compile an individual module it is sufficient to run
make /path/to/module/directory.
In this case that would be:
make ./path/to/source/fs
The compilation is quite lengthy; it takes about twenty minutes(on a virtual machine) and the output is written(by default) in the same directory in which the module is located. I've found the object files by running:
find . -name "*.o"
in /path/to/source/fs. Filtering by name the ELF loader can be located by running:
find . -name "*elf*.o"
In the current sources it is written(by default) in:
/path/to/source/fs/binfmt_elf.o
Having gone through this tutorial, I've noticed that kernel modules have the naming convention [module_name].ko in order to distinguish them from user space object files.
My question is how can I insert the new(modified) ELF loader into the kernel given that the current ELF loader is present(as unloading it may prevent binaries from being executed)?
What you have described is not really compiling a "kernel module" as it is commonly referred to. You have built an object that is statically linked into the kernel and there is no way that you can load just that object into a running kernel.
"kernel module" usually refers to "loadable kernel module" (LKM). Building and loading the fs as an LKM is what you need/want. Take a look at the below HOWTO. Follow that to build the desired fs as an LKM. Then you can just replace that one LKM (.ko) file and reboot (normally you can dynamically remove and insert LKMs but not sure how that will affect something fundamental like the ELF fs - you can try rmmod/modprobe without a reboot first if you ike).
http://www.tldp.org/HOWTO/Module-HOWTO/x73.html

Testing kernel Crypto API on linux

I have a Freescale i.MX board on which I run the Linux 3.0.35 kernel.
I want to test if the Kernel Crypto API of my Linux system works. I just found out the test program is called tcrypt. I see that under /lib/modules/ there is a tcrypt.ko in the drivers directory. This being the case, is there anyway I can test run this library? How do I call it? Do I need to reconfigure my kernel to "enable" something to call it?
Please keep in mind that I am new to kernel API's.
I had to compile the kernel modules. This built the "tcrypt.ko" module too. Then I used "insmod" command to load the module. Once loaded, the module was started with :
modprobe tcrypt sec=1 mode=200
(where mode is the algorithm to test)

Resources