Build a Linux 2.6 driver development environment

Source: Internet
Author: User

Although there are already many introductions on the Linux driver development environment on the Internet, as a newbie who has just been involved in the Linux driver, all the things have to be done by yourself, it usually takes a lot of time if the configuration is incorrect or cannot be used. Let's review the building process.

Kernel version: 2.6.38

Operating System: Ubuntu 11.04

Development Environment setup process:

1. Download the necessary development kit (binutils)

Sudo apt-Get install build-essential

2. Download the Linux source code (the specific version must be consistent with the current OS kernel version, uname-a query)

Sudo apt-Get install linux-source-2 .. 6.38 <remove: sudo apt-Get remove linux-source-2.6.38>

After downloading, go to the/usr/src directory and find the Linux source code package. Run tar-xvf to unpackage the package.

3. Go to the decompressed directory and perform the following operations. <if you do not want to input sudo every time, you can run Sudo-s once. As long as the current terminal does not exit, the root permission will be retained.>

Configure sudo make oldconfig

It takes some time for sudo make to compile the kernel and wait patiently.

Sudo make modules compilation Module

Sudo make modules_install installation Module

 

After the above operations are performed, the Ubuntu driver development environment is basically set up. Next we will use the classic Hello world for testing.

Hello. C:

#include <linux/init.h>#include <linux/module.h>static int hello_init(void){    printk(KERN_ALERT "Hello World \n");    return 0;}static void hello_exit(void){    printk(KERN_ALERT "Goodbye \n");}module_init(hello_init);module_exit(hello_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("jiangming.fu@163.com");

Makefile is as follows:

obj-m := hello.oKDIR= /lib/modules/$(shell uname -r)/buildPWD=$(shell pwd)all:$(MAKE) -C $(KDIR) M=$(PWD) #modules.PHONY:cleanclean:rm -f *.mod.c *.mod.o *.ko *.o *.tmp_versions

After make is executed, hell is generated in the current directory. ko (Driver Module). You can use sudo insmod (rmmod) Hello. ko installation (uninstall) module. you can view the output information of the driver module through dmsg.

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.