linux-device-driver

Study device driver source files?

北城余情 提交于 2021-02-06 09:34:04
问题 I want to study the source files of some of the device drivers that are installed and loaded on either a raspberry pi(raspian), beaglebone(debian) or a my laptop(ubuntu). My aim is to learn how to properly implement my own modules by studying the source files of some drivers that actually works. I am particularly interested in drivers that communicates with actual hardware (USB, I2C, SPI, UART etc). Can someone tell me how to find these sources? are they available in some particular folder i

Is kmalloc allocation not virtually contiguous?

可紊 提交于 2021-02-04 06:12:54
问题 I found that kmalloc returns physically and virtually contiguous memory. I wrote some code to observe the behavior, but only the physical memory seems to be contiguous and not the virtual. Am I making any mistake? #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/moduleparam.h> MODULE_LICENSE("GPL"); static char *ptr; int alloc_size = 1024; module_param(alloc_size, int, 0); static int test_hello_init(void) { ptr = kmalloc(alloc_size,GFP_ATOMIC); if(

Is kmalloc allocation not virtually contiguous?

拜拜、爱过 提交于 2021-02-04 06:08:26
问题 I found that kmalloc returns physically and virtually contiguous memory. I wrote some code to observe the behavior, but only the physical memory seems to be contiguous and not the virtual. Am I making any mistake? #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/moduleparam.h> MODULE_LICENSE("GPL"); static char *ptr; int alloc_size = 1024; module_param(alloc_size, int, 0); static int test_hello_init(void) { ptr = kmalloc(alloc_size,GFP_ATOMIC); if(

Making Kernel Module and registering it as pci device driver and network device driver and accessing the module's buffer using ioctl. Possible?

本小妞迷上赌 提交于 2021-01-29 17:16:50
问题 I like to make a kernel module. And inside it I like to register it as pci and network device driver. And using ioctle from user space to access the module's buffer(in pci and network driver) and getting buffer. The buffer contains packets received in interrupt handler when packet arrives in my kernel module/device driver and the buffer is global in the module. Means it will not be inside interrupt handler for receiving packets. and in ioctl function implementation inside device driver just

Linux Kernel generate compile-commands.json for module

廉价感情. 提交于 2021-01-29 05:23:00
问题 The problem : Most of macro definition and even header files are not looked up by an IDE because include path is not specified in the IDE configuration. It inhibits autocompletion and navigation. Here is my Makefile : #-Wno-declaration-after-statement ccflags-y := -std=gnu11 -Wno-declaration-after-statement -Werror obj-m += pfsw.o pfsw-objs := src/init.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean I ran

Creating a simple write only proc entry in kernel

混江龙づ霸主 提交于 2021-01-28 01:06:21
问题 #include <linux/module.h> #include <linux/kernel.h> #include <linux/proc_fs.h> #include<linux/sched.h> #include <asm/uaccess.h> #include <linux/slab.h> char *msg; ssize_t write_proc(struct file *filp,const char *buf,size_t count,loff_t *offp) { copy_from_user(msg,buf,count); printk(KERN_INFO "%s",msg); return count; } struct file_operations proc_fops = { write: write_proc }; int proc_init (void) { proc_create("write",0,NULL,&proc_fops); return 0; } void proc_cleanup(void) { remove_proc_entry(

__builtin_return_address returns null for index >0?

牧云@^-^@ 提交于 2021-01-20 07:27:42
问题 I want to get the return address of the caller function. I'm using __builtin_return_address() funtion, but if I give index value greater than 0 it is returning NULL . Please help me with this or tell me any other function to get the same. 回答1: See this answer to a related question. __builtin_return_address is GCC and processor specific (also available in some versions of Clang on some processors with some -lack of- optimizations), and documented as On some machines it may be impossible to

how to disable CONFIG_STRICT_DEVMEM through make menuconfig or make nconfig

Deadly 提交于 2020-12-26 09:14:53
问题 I need to disable a CONFIG_STRICT_DEVMEM option in my Linux kernel and recompile it. Why? I was told to do so. I know I can disable it by simply commenting it out in the .config file, but I need to see how it is done through make menuconfig or make nconfig . Why? This is for a demo and I need to be able to show it. Does anyone know how to do it? Any help is appreciated. 回答1: If you don't know your way around menuconfig, hit / to search (à la vim and friends), and type in enough of the config

How can I list MMC partitions in a Linux driver?

巧了我就是萌 提交于 2020-12-15 06:37:40
问题 I'm trying to read the U-Boot environment that is stored on eMMC, but I can't figure out how I can list the disks. The driver I'm creating is separated of the mmc device driver (/dev/mmcblk0p1). I already found out that the partitions of mmcblk0 are struct mmc_part entries in struct mmc_card. Basically I'm searching for the mmc variant of __mtd_next_device. EDIT 1: I found out that I can get a block_device struct through bdget, but gendisk points to NULL . struct block_device *my_bdevice;

How can I list MMC partitions in a Linux driver?

ε祈祈猫儿з 提交于 2020-12-15 06:37:05
问题 I'm trying to read the U-Boot environment that is stored on eMMC, but I can't figure out how I can list the disks. The driver I'm creating is separated of the mmc device driver (/dev/mmcblk0p1). I already found out that the partitions of mmcblk0 are struct mmc_part entries in struct mmc_card. Basically I'm searching for the mmc variant of __mtd_next_device. EDIT 1: I found out that I can get a block_device struct through bdget, but gendisk points to NULL . struct block_device *my_bdevice;