linux-device-driver

copy_to_user vs memcpy

别等时光非礼了梦想. 提交于 2019-11-30 13:57:50
问题 I have always been told(In books and tutorials) that while copying data from kernel space to user space, we should use copy_to_user() and using memcpy() would cause problems to the system. Recently by mistake i have used memcpy() and it worked perfectly fine with out any problems. Why is that we should use copy_to_user instead of memcpy() My test code(Kernel module) is something like this: static ssize_t test_read(struct file *file, char __user * buf, size_t len, loff_t * offset) { char ani

Mapping physical addresses to virtual address linux

*爱你&永不变心* 提交于 2019-11-30 13:53:57
I am working on a small embedded system. When my linux boots up into user space, I know where are my devices in the physical memory. I want to map them into user space virtual addresses. Currently, I am doing it through a kernel module. I use vmalloc/kmalloc (depending on the size) and then I use ioremap_page_range on that returned virtual addresses to map my physical addresses. I dont think that is the correct way to go about. First of all I am allocating memory and then I am asking kernel to remap that virtual address space to some different physical address space. (Initially mapped physical

Change the TCP timeout for a linux network device [closed]

余生颓废 提交于 2019-11-30 13:45:36
I am programming linux device driver over a very slow interface, whose ping round time can be as long as several minutes. When I try to use TCP to establish connection between two nodes the connection always times out. Is there a method to set the TCP retransmission or handshaking timeout longer in the driver, or are there any commands to set it with? Thanks Have you tried searching for an answer to this question? A quick Google search gave me this , which appears to directly address this issue. The summary is that the setting of the net.ipv4.tcp_syn_retries determines that maximum timeout

How to attach file operations to sysfs attribute in platform driver?

我只是一个虾纸丫 提交于 2019-11-30 13:25:34
问题 I wrote a platform driver for a peripheral we developed and would like to expose some configuration options to the sysfs. I have managed to create the appropriate files using attribute structs (see below) and sysfs_create_file in the probe function, but I can't figure out how to attach the show/store functions to the structs in a platform driver. Most resources I found online used a device_attribute struct or something similar to create their files, is that also appropriate here? Is there

insmod error: inserting './hello.ko': -1 Invalid module format\"

和自甴很熟 提交于 2019-11-30 12:39:50
I have just made my first driver module, the hello world module following LDD3. However unfortunately encountered this error: insmod: error inserting './hello.ko': -1 Invalid module format. I am doing this on Ubuntu 11.04, and my environment: $ uname -r 2.6.38-8-generic I get the kernel source like this: sudo apt-cache search linux-source linux-source - Linux kernel source with Ubuntu patches linux-source-2.6.38 - Linux kernel source for version 2.6.38 with Ubuntu patches $sudo apt-get install linux-source-2.6.38 my /usr/src: $ls /usr/src/ linux-headers-2.6.38-8 linux-source-2.6.38 vboxguest-5

What is the use of __iomem in linux while writing device drivers?

主宰稳场 提交于 2019-11-30 11:28:18
问题 I have seen that __iomem is used to store the return type of ioremap() , but I have used u32 in ARM architecture for it and it works well. So what difference does __iomem make here? And in which circumstances should I use it exactly? 回答1: Lots of type casts are going to just "work well". However, this is not very strict. Nothing stops you from casting a u32 to a u32 * and dereference it, but this is not following the kernel API and is prone to errors. __iomem is a cookie used by Sparse, a

Writing memory of the traced process.

一世执手 提交于 2019-11-30 10:37:47
I am playing around with ptrace in linux. I am trying to write the memory of the traced process using /proc/pid/mem interface. the function I ma using for accomplish this task is : void write_proc(pid_t child, unsigned long int addr) { char mem_file_name[100]; char buf[10]="hope"; int mem_fd; memset( (void*)mem_file_name, 0, 100); memset( (void *)buf, 0, 10); sprintf(mem_file_name, "/proc/%d/mem", child); mem_fd = open(mem_file_name, O_RDONLY); lseek(mem_fd, addr , SEEK_SET); if (write(mem_fd, buf, 5) < 0 ) perror("Writing"); return; } But I always get the error : Writing: Bad file descriptor.

How can I get Linux device with FTDI D2XX driver API

人盡茶涼 提交于 2019-11-30 10:37:19
I am using FTDI D2XX driver API to communicate with a FTDI device. It gives me some information about the device like locid, serialnumber, description but it is not enough. How can I get the device number ( /dev/ttyUSBXX ) or bus or port with this API. thanks As the D2XX Programmer's Guide tells in the Introduction: For Linux, Mac OS X (10.4 and later) and Windows CE (4.2 and later) the D2XX driver and VCP driver are mutually exclusive options as only one driver type may be installed at a given time for a given device ID. The problem is that your Linux may automatically loads the VCP driver (

Why is make printing “make: Nothing to be done for `all'.”?

白昼怎懂夜的黑 提交于 2019-11-30 09:46:47
This is a "Hello.c" module and "Makefile". After executing make from the woking directory I get the following message: make: Nothing to be done for `all'. This is the "Hello.c" file: #include <linux/module.h> // included for all kernel modules #include <linux/kernel.h> // included for KERN_INFO #include <linux/init.h> // included for __init and __exit macros MODULE_LICENSE("GPL"); MODULE_AUTHOR("Lakshmanan"); MODULE_DESCRIPTION("A Simple Hello World module"); static int __init hello_init(void) { printk(KERN_INFO "Hello world!\n"); return 0; // Non-zero return means that the module couldn't be

Where to use volatile? [duplicate]

社会主义新天地 提交于 2019-11-30 09:46:12
This question already has an answer here: Why is volatile needed in C? 17 answers I read about volatile keyword, but I don't know in what situations I should use it. When the memory (variable) is getting updated and process is not aware of that? In what cases should drivers use volatile variables? The most common case in my world is when you are programming microcontrollers that use memory-mapped I/O. The value in a register could change due to external digital inputs, but if you don't declare a variable as volatile , the compiler might optimize the code out completely and you'll be wondering