1. The simplest Linux driver __linux

Source: Internet
Author: User

Learning Linux has been a while, has been disorganized. I don't know what I learned or what I did. Now take a step-by-step look at the Linux-driven learning process. From the simplest to see the beginning.

First, we write a simplest module. Edit HELLO_MODULE.C

#include <linux/module.h>
#include <linux/sched.h>
#include <linux/kernel.h>

Module_license ("GPL");
int text_init (void)
{
PRINTK ("<0>" "Hello World");
return 0;
}

void Text_cleanup (void)
{
PRINTK ("<0>goodbye World");
}

Module_init (Text_init);
Module_exit (Text_cleanup);

Write makefile

Ifneq ($ (kernelrelease),)
Obj-m: = HELLO_MODULE.O
Else
#KERNELDIR: =/home/sinew/Desktop/linux-2.6.30.4-ces2440
Kerneldir: =/usr/src/linux-headers-3.8.0-19-generic/
pwd:=$ (Shell PWD)
All
Make-c $ (Kerneldir) m=$ (PWD) modules
Clean
RM-RF *.ko *.o *.mod.c *.mod.o *.symvers
endif

Where Kerneldir needs to be set to your kernel source path.

Then use the Insmod command to deposit modules: Insmod Hello_nodule.ko

Using Lsmod, you can see your newly inserted module.

Using Rmmod to remove modules: Rmmod hello_module

The simplest driver is complete.

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.