[Beijing Xunwei] i.MX6ULL Terminator Linux MISC driver running test

1 Compile the driver

A Makefile file is needed like the driver test program in the previous chapter, but the value of obj-m is changed to beep_misc.o. The contents of the Makefile file are as follows:

KERNELDIR := /home/topeet/kernel/linux-imx-rel_imx_4.1.15_2.1.0_ga
CURRENT_PATH := $(shell pwd)
obj-m := beep_misc.o

build: kernel_modules
kernel_modules: 
        $(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) modules
clean:
        $(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) clean

First, we enter two commands in the terminal (set two environment variables):

export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-

Then execute the "make" command to compile the module, and the compilation is completed to generate the beep_misc.ko module file.

2 Compile the application test program

Enter the following command to compile the application test program: After the
arm-linux-gnueabihf-gcc -o beep_misc_test beep_misc_test.c
compilation is complete, the beep_misc_test executable file will be generated.

3 Run the test

Start the development board and copy the compiled beep_misc.ko module file and beep_misc_test application to the /lib/modules/4.1.15 directory (check whether there is "/lib/modules/4.1.15" in the root file system of the development board Directory, if you don’t have one, you need to create it yourself. The development board uses the busybox file system provided in the CD data, and the CD data "i.MX6UL Terminator CD data\08_development board system image\03_file system image\ 01_Busybox file system” directory). Enter the following command to load the module:

depmod
modprobe beep_misc

After the driver is loaded successfully, you can see a subdirectory named "miscbeep" in the /sys/class/misc directory, as shown in Figure 3.1:
Insert picture description here

Figure 3.1

All misc devices belong to the same category. The /sys/class/misc directory contains all devices of the misc category, and each device corresponds to a subdirectory.
After the driver and the device are successfully matched, the device driver file /dev/miscbeep will be generated. Enter the following command to view the major and minor device numbers of this file: the
ls /dev/miscbeep -l
result is shown in Figure 3.2:
Insert picture description here

Figure 3.2

It can be seen that the major device number of /dev/miscbeep is 10 and the minor device number is 144, which is consistent with the settings in our driver.
Then use the beep_misc_test application to test the driver file. Enter the following command to open the beep:
./beep_misc_test /dev/miscbeep 1
close the beep. Use the following command:
./beep_misc_test /dev/miscbeep 0
If the buzzer can be turned on and off normally, it means that the drive file is correct.
To uninstall the driver module use the following command:
rmmod beep_misc

Insert picture description here

Guess you like

Origin blog.csdn.net/BeiJingXunWei/article/details/112171056