tailieunhanh - Step by step to build driver and application in Linux

Step by step to build driver and application in Linux includes Building kernel module (Add Char driver to module, The following code is a complete "hello world" module), Adding module to kernel, Building application, Removing kernel module. | STEP BY STEP TO BUILD DRIVER AND APPLICATION IN LINUX 1. Building kernel module Ex: The following code is a complete "hello world" module: 1. Building kernel module (cont.) #include #include MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello, world\n"); return 0; } static void hello_exit(void) { printk(KERN_ALERT "Goodbye, cruel world\n"); } module_init(hello_init); module_exit(hello_exit); This module defines two functions, one to be invoked when the module is loaded into the kernel (hello_init) and one for when the module is removed (hello_exit). The module_init and module_exit lines use special kernel macros to indicate the role of these two functions 1. Building kernel module (cont.) After success to build that code, you can test the module with the insmod and rmmod utilities, as shown below. Note that only the superuser can load and unload a module. root# insmod ./ Hello, world root # rmmod hello Goodbye cruel world root# 1. Building kernel module (cont.) Add Char driver to module We develop a character driver because - This class is suitable for most simple hardware devices. - Char drivers are also easier to understand than block drivers or network drivers. The classic way to register a char device driver is .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.