Linux Driver Development (1) Environment construction small test sledgehammer

Source: Internet
Author: User

First, Environment construction

The simplest way is to:

1. Installing VMware under Windows

2, WMware install Ubuntu (i installed ubuntu-10.04-desktop-i386 (Ubuntu distribution name, 10.04 is April 10, Desktop is the release version, I386 is the model and type of CPU))

3, at this time your environment has been set up, to how simple is more simple, is not yet do what? How can it be? This is because Ubuntu has helped us get it done.

4, just install Ubuntu How to configure screen resolution? System-preferences-monitors

5, verify: Open terminal (shortcut key: ctrl+atl+t) input uname-a or uname-r view kernel version; source directory:/USR/SRC

Second, small trial sledgehammer

1, under your user to create a new directory: study (can be arbitrary, this article takes study as an example)

2. Build two files

First one: hello.c

The code is as follows:

#include <linux/module.h>
#include <linux/init.h>


module_license ("Dual bsd/ GPL ");


static int hello_init (void)
{
PRINTK (kern_alert "Hello world.\n");
return 0;
}


static int hello_exit (void)
{
PRINTK (kern_alert "goodbye.\ n ");
return 0;
}


Module_init (hello_ INIT);
module_exit (hello_exit);

Second file: Makefile (note m uppercase and no suffix prefix, the following all and clean under the line of instructions before the blank type of a tab to build)

The contents are as follows:

Obj-m: = hello.o
Kernel_dir: =/lib/modules/$ (Shell uname-r)/build
PWD: = $ (shell pwd)
All
Make-c $ (Kernel_dir) subdirs=$ (PWD) modules
Clean
RM *.o *.ko
. Phony:clean

3, Execution (note: When prompted operation not permitted please add sudo before the instruction)

First go to directory study

Then execute: Make

Next load module to kernel: Insmod./hello.ko

See if there is a Hello module: lsmod

Last unload module: rmmod Hello

Linux Driver Development (1) Environment construction small test sledgehammer

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.