Linux device driver _hello Word module compiling various problem collections

Source: Internet
Author: User

After reading the classic book "Linux Device Driver", the first program is to write a Hello word module. Originally thought very simple, really get up, found a lot of problems ah. Two days ago, because there is no record, today to see the time and forget, so no matter how late, you have to record.


1, first explain my system environment: Ubuntu 14.04, the kernel is 3.13.0-29-generic

2, installed in My Computer git version controller, I clone a Linux kernel library on my computer, so I can arbitrarily switch to any branch up. It was originally used in 2.6.3, and later compiled with various problems. Google a bit, now will you the God's solution Link: http://blog.csdn.net/sabalol/article/details/2076610


Hello Word code:

1 #include <linux/init.h>  2 #include <linux/module.h>  3   4 module_license ("Dual BSD/GPL");  5   6 static int hello_init (void)  7 {  8         printk (kern_alert "Hello World enter\n");  9         return 0;  {         printk (kern_alert "Hello World exit\n") and static void Hello_exit (void); 15} 16  Module_init (Hello_init), Module_exit (Hello_exit), Module_author ("Zhangjun"), Module_description (" A Simple Hello World Module "); Module_alias ("A simple MODULE");
Makefile Code:

1 obj-m: = hello.o  2 KERNEL: =/lib/modules/3.13.0-29-generic/build  3 pwd: =$ (Shell PWD)  4 modules:  5
   $ (make)-C $ (KERNEL) m=$ (PWD) Modules  6           7. Phoney:clean  8 Clean:  9         rm-f *.o *.ko
Note : Change the "/lib/modules/3.13.0-29-generic/build" behind kernel to the path that matches your system

3, at the beginning I did not use the system to bring the path "/lib/modules/3.13.0-29-generic/build", but its own source code, it can compile, but load the module will be reported insmod:error inserting ' Hello.ko ': Invalid module format this error. Check is that the source code version of the compilation and the system version is different. Later I changed to the same, or not. Finally saw this article, can be said to save the building I os.51cto.com/art/201108/287684.htm, here thank this man. Then the compiled source code path is changed to the system's own path, the Gaocheng.

4, in the Ubuntu terminal load when found no output, which makes me very depressed, in fact, this is because the desktop environment terminal is analog terminal, only under the character terminal to display output. If under the analog terminal, it is the information output to "/var/log/kern.log" (Ps:ubuntu system is this directory, other systems may be/var/log/message ");

5, we want to load the time to see the output will need to switch to the character interface down. How do I switch? Under Ubuntu, CRTL+ALT+F2 or F3,f4,f5,f6 are OK. (PS: Remember to switch back to desktop environment is ALT+F7)

6. Common commands: Check your kernel version uname-a
Reference: blog.csdn.net/wwyyxx26/article/details/6325843


Then give you the program ape point Good Things: Https://github.com/txthinking/google-hosts believe that like programming you all like GOOGLE,,FUCKGWF.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.