1. Compile/install driver
In Linux systems, drivers are usually written using the kernel module's program structure. Therefore, compiling/installing a driver is essentially compiling/installing a kernel module.
Create a MEMDEV.C driver (a character device that simulates with memory)
Makefile file
Then compile: Make, copy the Memdev.ko file to the board, install Insmod Memdev.ko, and see if it was successful: Lsmod.
2. Character device files
The application uses the character device driver to control the character device by using the characters device file.
Ways to create a character device file: There are generally two types:
1), using the Mknod command
mknod/dev/character device file name C main device number secondary device number
2), use the function to create in the driver
Find the driver corresponding to the main device number (this is the driver instead of the character device file!!) ), using cat/proc/devices, you can see two columns: the number corresponding to the device number, the corresponding name, and the secondary device number generally take a nonnegative number
The following character device files are created: Mknod/dev/memdev0 C 253 0 (note that 253 is the main device number for the driver that was just installed, so the character device file created here also corresponds to the same master device number!! )。
View the character device file ls/dev/memdev0 below.
The device driver is now installed into the kernel as a kernel module and the character device files are created as well.
Create the application below to test
1) write the content to the register (the register is virtual with an array)
VI WRITE_MEM.C
ARM-LINUX-GCC Write_mem.c-o Write_mem, put it on the board to run: if there is a-/bin/sh:-/write_mem:not found, it means that our application depends on the library is not found, this situation occurs, Back to the host, using the command arm-linux-readelf-d write_mem to check,-D is to query the application depends on the dynamic link library, in our Development Board does not have the library ls/lib/.
Workaround:
1, the dynamic link library to find, copy it to the Development Board under the Lib;
2, we use static compilation method: Arm-linux-gcc-static Write_mem.c-o Write_mem, and then copy to the Development Board run.
By executing the program, 2013 numbers have been written into the corresponding character device.
Read the number below.
VI READ_MEM.C
Compile arm-linux-gcc-static read_mem.c-o read_mem. Operation of
Using character drivers