Difference between printk and pr_info
The kernel’s printk.h has: #define pr_info(fmt,arg…) \ printk(KERN_INFO fmt,##arg) Just like the name, pr_info() is printk() with the KERN_INFO priority.
The kernel’s printk.h has: #define pr_info(fmt,arg…) \ printk(KERN_INFO fmt,##arg) Just like the name, pr_info() is printk() with the KERN_INFO priority.
Putting ARCH and CROSS_COMPILE in the Makefile doesn’t work. You need to put them on the command line: make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-
Instead of re-configuring the kernel, this error (module verification failed) could be resolved by just adding one line CONFIG_MODULE_SIG=n to the top of the Makefile for the module itself: CONFIG_MODULE_SIG=n # If KERNELRELEASE is defined, we’ve been invoked from the # kernel build system and can use its language. ifneq ($(KERNELRELEASE),) obj-m := hello.o # … Read more
A kernel thread is a task_struct with no userspace components. Besides the lack of userspace, it has different ancestors (kthreadd kernel thread instead of the init process) and is created by a kernel-only API instead of sequences of clone from fork/exec system calls. Two kernel threads have kthreadd as a parent. Apart from that, kernel … Read more
The correct command is just rm 🙂 A device node created by mknod is just a file that contains a device major and minor number. When you access that file the first time, Linux looks for a driver that advertises that major/minor and loads it. Your driver then handles all I/O with that file. When … Read more
You can make a symbolic link of your module to the standard path, so depmod will see it and you’ll be able load it as any other module. sudo ln -s /path/to/module.ko /lib/modules/`uname -r` sudo depmod -a sudo modprobe module If you add the module name to /etc/modules it will be loaded any time you … Read more
Switch to the root directory of your source tree and run the following command: $ make modules SUBDIRS=drivers/the_module_directory And to install the compiled module: $ make modules_install SUBDIRS=drivers/the_module_directory Note: As lunakid mentions, the latter command might not build the module first, so be careful.
Actually, there seems to be a way to list processes that claim a module/driver – however, I haven’t seen it advertised (outside of Linux kernel documentation), so I’ll jot down my notes here: First of all, many thanks for @haggai_e’s answer; the pointer to the functions try_module_get and try_module_put as those responsible for managing the … Read more
You should be aware that you should avoid file I/O from within Linux kernel when possible. The main idea is to go “one level deeper” and call VFS level functions instead of the syscall handler directly: Includes: #include <linux/fs.h> #include <asm/segment.h> #include <asm/uaccess.h> #include <linux/buffer_head.h> Opening a file (similar to open): struct file *file_open(const char … Read more