My First Linux Module

Source: Internet
Author: User
Tags parent directory

My First Linux Module

Today, I successfully build my first Linux Hello module.

First of all add a directory named Hello in the Kernel/driver, and add a file hello.c, write codes like bellow:

#include <linux/init.h>#include<linux/module.h>Static int__init Hello_init (void) {PRINTK (Kern_err"Hello, world!\n."); return 0;}Static void__exit Hello_exit (void) {PRINTK (Kern_err"Goodbye, world!\n");} Module_init (Hello_init); Module_exit (Hello_exit); Module_author ("Bob, Zhang"); Module_license ("Dual BSD/GPL"); Module_description ("A Simple Hello World demo"); Module_alias ("A Simple Module");

Then create a Kconfig file:

config HELLO     " HELLO World driver! "     default M    help        HELLO World

and create a Makefile file:

Obj-m + = hello.o

Next ADD the Kconfig and Makefile into the Kconfig file and Makefile file in parent directory.

Finally Run the commands bellow:

 Make Arch=arm cross_compile=$tool _prefix my_kernel_defconfig make Arch=arm cross_compile=$tool _ Prefix modulesmkdir ./moduls_temp make arch=arm cross_compile= $tool _prefix Modules_ Install Install_mod_path=./modules_temp

At last, the demo run is like this:

My First Linux Module

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.