Simple demonstration of ARM + LINUX driver development steps

Source: Internet
Author: User

I met a younger brother who asked me how to write the driver, but I don't know how to say it to him. There are still a lot to learn. He needs to look at the specific driver framework. I also need to spend some time to understand the kernel mechanism. Since I have done this before, I will sort out the previous documents and demonstrate the steps from start to end. Simply put, it is an operation demonstration. As for debugging, that is the code thing. Paste the previous documents as follows:

 

**************************************** ****************

Since we have to continue to innovate experimental projects in recent times, this is not a great choice. Fortunately, I can build a USB Module. Let's talk about my Development Board. I picked it up today and started it. I lost my temper if I hadn't touched her for a while. No power supply, I thought the power supply was broken. Later, I checked that the button switch was broken. Small case, for better, tonight, the running board.

System Configuration:
On the virtual machine, the operating system is fedora9. Check the kernel.
# Uname-R
2.6.25-14. fc9.i686
Development Board fl2440:
# Uname-R
2.6.12-h1940

First, determine two compilers, GCC and arm-Linux-GCC, on the virtual machine.
# Gcc-V then comes out,
GCC version 4.3.0 20080428 (Red Hat 4.3.0-8) (GCC)
______________________________________________________
| Using toolchain development, I used a cross compiler prepared by others. After decompression, I directly went to the configuration file
| Configuration under the folder
| # Cd/etc
| Tells the compiler path to the kernel, which is called environment variable setting, that is, adding
| Export Path =/usr/local/ARM/3.4.1/bin: $ path
_______________________________________________________
So here we can continue to look at the cross compiler.
# Arm-Linux-gcc
GCC version 3.4.1

Second, the purpose is to write a drive for a streaming lamp, which is actually to write an operation on the LED. Name led. c
The specific analysis of the Board will not be posted. Next, write a simple makefile with the following code:
-------------------------------------
Arch = arm # platform description
Mvtool_prefix =/usr/local/ARM/3.4.1/bin/ARM-Linux-# specify the compiler, local or cross compiler: absolute path
Cross_compile = $ (mvtool_prefix)
Kdir: =/usr/src/linux-2.6.12 # Tell the kernel to compile
Exec = led # file name
OBJ-M: = led. O #-M is compiled into a module. Pay attention to the parameter-y-name.
PWD: = $ (shell PWD)
ALL:
$ (Make)-C $ (kdir) M = $ (PWD) Modules
-------------------------------------
# Mkdir led // create a folder and run the two source files, led. C and makefile, CP.
# Make
# Ls
Led. c led. Mod. c led. O led. Ko led. Mod. o
As you can see, make has done a lot of work. As a result, the task is completed with LED. Ko and other Doon (intermediate files ),

Check it out. Led. Ko is the required module (The. o file used to be the 2.4 kernel. The Virtual Machine and the local machine are set together

So I copied it directly and sent it to fl2440 through UART, and then operated on the board.

# Insmod led. Ko // insmod will call module_init.

Finally, everything is ready to drive. Let's write a test program! Here we post ledshow. c
------------------------------------
# Include "stdio. H"
# Include "unistd. H"
# Include "sys/types. H"
# Include "sys/IOCTL. H"
# Include "stdlib. H"
# Include "termios. H"
# Include "sys/STAT. H"
# Include "fcntl. H"
# Include "sys/time. H"

Int main (void)
{
Int on = 1;
Int led;
Int FD;
FD = open ("/dev/led", 0 );
If (FD <0)
{
Perror ("open device led ");
Exit (1 );
}
Printf ("LEDs test show, press Ctrl + C to exit/N ");
While (1)
{
For (LED = 0; led <4; led ++)
{
IOCTL (FD, on, LED );
Usleep (50000 );
}
On =! On;
}
Close (FD );
Return 0;
}
--------------------------------------
Similarly, if I copy the file to the LED folder, it's easy. I don't need to write makefile or use auto generate makefile. Text

If there are so few items, let's save some time. It takes the least time to complete the most actions. Haha
# Arm-Linux-gcc-O ledshow. C // it is convenient to configure the cross compiler.
# Ls
Led. c led. Mod. c led. O ledshow. c
Led. Ko led. Mod. O ledshow makefile
The program is released, and the ledshow test program is uploaded to the Development Board through the serial port. Then,
# Chmod + x ledshow // modify the File Permission, which can be read, written, and executable.
#./Ledshow

Result, OK! (I only saw the Development Board haha)

By the way, it means that my kernel source code tree is in/usr/src/linux-2.6.12, doing anything like above in any directory,

You have to configure the kernel in the top-level directory of the source code tree. Compile the kernel. Otherwise, it seems that an error may occur. You have not studied the problem.

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.