[Beijing Xunwei] Platform driver running test under i.MX6ULL Terminator device tree

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 led_driver.o. The contents of the Makefile file are as follows:

KERNELDIR := /home/topeet/kernel
CURRENT_PATH := $(shell pwd)
obj-m := led_driver.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 led_driver.ko module file will be generated after compiling.

2 Compile the application test program

The application test program can directly use the led_test application program compiled in 44.3.2 of the previous chapter.

3 Run the test

Start the development board, copy the compiled led_driver.ko module file and led_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: After the
depmod
modprobe led_driver
driver is loaded successfully, check whether the driver exists in the /sys/bus/platform/drivers/ directory. We set the name field of led_driver (platform_driver type) in led_driver.c to "imx6ul- led", so there will be a file named "imx6ul-led" in the /sys/bus/platform/drivers/ directory, and the result is shown in Figure 3.1:
Insert picture description here

Figure 3.1

In the same way, there is also a led device file in the /sys/bus/platform/devices/ directory, which is the gpioled node in the device tree, as shown in Figure 3.2:
Insert picture description here

Figure 3.2

When the device and the driver are successfully matched, there will be information input as shown in Figure 3.3:
Insert picture description here

Figure 3.3

After the device and the driver are successfully matched, use the led_test application to test it. The command is as follows:

./led_test /dev/dtsplatled 1		//打开LED灯
./led_test /dev/dtsplatled 0		//关闭LED灯

Use these two commands to verify whether the devices and drivers under the LED platform are correct.
Uninstall module command:
rmmod led_driver //卸载驱动模块

Insert picture description here

Guess you like

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