[Linux] -- Linux driver learning notes (1) -- two methods of driver Compilation

Source: Internet
Author: User

The driver can be compiled together with the kernel or separately as a module. However, to facilitate driver debugging, the driver is usually compiled in a modular manner.

1. Compile the driver in modular Mode

The Linux kernel is 2.6.12 and the fl2440 driver is used as an example. Source File: Driver s3c2440_leds.c, test program led. C. Now, you only need to write a makefile segment to compile the LED driver. Content:

obj-m :=s3c2440_leds.oKERNELDIR ?= /root/linux-2440/linux-2.6.12PWD := $(shell pwd)default:$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

Then run the make command. The generated s3c2440_leds.ko is the driver module File we need. Then, generate the LED. C, and upload the led of the s3c2440_leds.ko program and the test program to the board. After changing the permission, run the following command:

#insmod s3c2440_leds.ko#./led

2. Compile with the kernel

Take the fl2440 and LED Drivers as examples. The Development Board of the Linux source package in the/root/linux-2440/linux-2.6.12 directory, the s3c2440_leds.c copy to the source package dirvers/Char directory, and modify the makefile under the drivers/Char directory, add the following content 1 in the corresponding location, and add content 2 in the corresponding location of the kconfig file:

1.obj-$(CONFIG_S3C2440_LEDS) += s3c2440_leds.o2.config S3C2440_LEDS       tristate "S3C2440 LEDS Drivers"       depends on ARCH_S3C2440        help               SBC2440 User keys

Then, when you execute make menuconfig in the source package directory for Option Selection, The S3C2440 LEDs option appears under character drivers under the device driver option. After selecting the corresponding module, after the compilation is successful, download it to the Development Board and run the LED test program directly.

 

 

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.