Linux Kernel Driver DIY (step-by-step learning kernel 2)

Source: Internet
Author: User

The above mentioned modification to the kconfig file,

Added

Config embedsky_hello
Tristate "tq2440/sky2440 Hello driver"
Depends on arch_s3c2440
Help
Embedsky tq2440/sky2440 hello.
These lines of code indicate that the embedsky_hello driver needs to be compiled. What we need to do is

Modify the MAKEFILE file in the same parent directory




Add this line to makefile,


OBJ-$ (config_embedsky_hello) + = embedsky_hello.o







Then select in the kernel compilation option and compile the kernel directly, or use the command # Make subdir = Drivers/Char/modules to compile the driver module.




Let's take a look at the driver module




*************************************
Name: embedsky_hello.c
Copyright: www.embedsky.net
*************************************/
# Include <Linux/module. h>
# Include <Linux/kernel. h>
# Include <Linux/fs. h>
# Include <Linux/init. h>
# Include <Linux/miscdevice. h>
# Include <Linux/delay. h>
# Include <ASM/IRQ. h>
# Include <ASM/ARCH/regs-gpio.h>
# Include <ASM/hardware. h>
Module_license ("GPL ");
When the static int _ init embedsky_hello_init (void) // insmod driver is used, the system automatically calls the function.
{
Printk ("<1>/n hello, embedsky! /N ");
Printk ("<1>/nthis is first driver program./n ");
Return 0;
}





Static void _ exit embedsky_hello_exit (void)
{
Printk ("<1>/n exit! /N ");
Printk ("<1>/ngoodbye embedsky! /N ");
}
Module_init (embedsky_hello_init );
Module_exit (embedsky_hello_exit );








A short piece of code, but it seems that only a few lines of words can be printed in the kernel, without interacting with hardware.

The gpio driver will be available tomorrow.


Related Article

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.