




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Information about a programming project for creating a loadable kernel module (lkm) for embedded linux using the accelent idp platform. The project involves writing a simple lkm to read and write to the basic system information (uname) on linux 2.4. Partial pseudo code and a makefile to help complete the project. The goal is to learn how to read and write to system parameters dynamically after the system has been booted.
Typology: Study Guides, Projects, Research
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Preliminary Project Data April 14, 2008
/ #include #include #include #include #include #include /
static int proc_write_sysname(struct file *file, const char *buffer, unsigned long count, void data) { /
CC=arm-linux-gcc KERNEL_SRC=/usr/src/linux-2.4. CFLAGS=-Wall -O MODFLAGS=-I$(KERNEL_SRC)/include -D__KERNEL__ -DMODULE procfs_sysinfo.o: procfs_sysinfo.c $(CC) $(CFLAGS) $(MODFLAGS) -c procfs_sysinfo.c
struct proc_dir_entry *create_proc_entry( const char *name, mode_t mode, struct proc_dir_entry *parent);
#define __init _attribute ((section (".text.init"))) #define __exit attribute ((unused, section(".text.exit")))
structure. The read_proc and write_proc will be assigned the addresses of read and write callback functions which are explained in the next sub section.
The read function has the following prototype: int module_read(char *page, char **begin, off_t offset, int count, int *eof, void *data) This function serves the purpose of reading data from a /proc entry from the kernel to the user space. The page argument is the location into which you write the data intended for the user, where count defines the maximum number of characters that can be written. The begin and offset arguments are used for returning more than a page of data (typically 4KB). When all the data have been written, the eof (end-of-file) argument is set. data represents private data. The page buffer provided here is in kernel space. Therefore, it is not necessary to invoke copy_to_user for copying the data to page.
The write function has the following prototype: int module_write(char file *filp, const char *buffer, int count, void *data) This function serves the purpose of writing data from a /proc entry from the kernel to user space. The filp argument is essentially an open file structure (not used in this project). The buffer argument is the string data being passed to kernel space. The buffer address is actually a user-space buffer, so it is not possible to read it directly. The copy_from_user function is used to copy data from user space to kernel. The count argument defines how much data in buffer is being read. The data argument is a pointer to the private data.