Write Kernel first Hello World

Source: Internet
Author: User

Situ

Objective: To be familiar with the basic process of driver programming and debugging. 1. Prepare

Operating system: ubuntu12.04 LTS2. Source Code[CPP] View plain copy #include <linux/init.h> #include <linux/module.h> static int hello_init (void)       {pr_info ("Hello, world.\n");   return 0;   } static void Hello_exit (void) {pr_info ("Goodbye, cruel world\n");   } module_init (Hello_init);      Module_exit (Hello_exit); Module_license ("Dual BSD/GPL");3.Makefile[Plain] View plain copy obj-m: = hello.o Kerneldir: =/usr/src/linux-headers-$ (Shell uname-r) PWD: = $ (Shell PWD ) Modules: $ (make)-C $ (Kerneldir) m=$ (PWD) modules Modules_install: $ (make)-C $ (Kerneldir) m=$ (PWD) M Odules_install4. CompileMake: [Plain] View plain copy ckt@ubuntu:~/work/ldd/hello$ make make-c/usr/src/linux-headers-3.13.0-32-genericm=/hom E/ckt/work/ldd/hello Modules Make[1]: Entering directory '/usr/src/linux-headers-3.13.0-32-generic ' CC [M]/home/ckt     /WORK/LDD/HELLO/HELLO.O Buildingmodules, Stage 2. Modpost 1modules LD [M]/home/ckt/work/ldd/hello/hello.ko make[1]: Leaving directory '/usr/src/linux-headers-3.13.0- 32-generic '5. Test

[plain]  View Plain  copy lsmod                    #查看当前加载的模块    sudo insmod hello.ko           #加载hello. Ko module    sudo rmmod hello               #移除hello. Ko module    cat/var/log/syslog       #查看日志   

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.