Using Pulse Width Modulation (PWM) interface in kernel module - c

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!

Related

How to use custom device tree source correctly in buildroot?

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.

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

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)

How to add new QEMU machine types without modifying the mainline source code?

Can a new machine type be added for qemu-system-arm -M <MachineType> without having to recompile qemu or write code? Are there docs to do this? I would like to be able to emulate raspberry pi and pandaboard using qemu.
I know that meego's fork of qemu supports pandaboard, but I am trying to stick with the main stream qemu that I can manage from the apt-get package manager. the main stream qemu now supports beagleboard rev C and beagleboard xm that were previously supported only in the meego fork.
without having to recompile qemu or write code?
No. There must be some code doing the device specific emulation, like for example the way the Raspberry Pi or the Pandaboard implement video output. This is not a matter of just a few config files.
I've been able to emulate the Pi with -M versatilepb: https://raspberrypi.stackexchange.com/questions/165/emulation-on-a-linux-pc/53991#53991 and -M raspi2 has was later added in QEMU 2.6.
Maybe this feature is feasible to implement, see my experience with adding a new platform device: How to add a new device in QEMU source code?
There, I only needed to add a single line to attach a new device to versatilepb:
sysbus_create_simple("lkmc_platform_device", 0x101e9000, pic[18]);
so maybe we could have a config file containing lines of type:
type name regid irq
sysbus lkmc_platform_device 0x101e9000 18
Related: out-of-tree devices: How to create out-of-tree QEMU devices?

Resources