1. Write a helloworld driver
The driver source code is as follows:
#include
#include
static int hello_init(void)
{
printk(KERN_INFO "BBBlackHelloModule enter!\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_INFO "BBBlackHelloModule exit!\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_AUTHOR("Zhao Yidong
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("A sample bbblack hello module");
MODULE_ALIAS("a sample module");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2. Write the driver makefile
According to the hellomodule of PC, modify the makefile file and edit the makefile of 2416 as follows:
#Makefile for .c
ARCH=arm
CROSS_COMPILE=arm-linux-
ifneq ($(KERNELRELEASE),)
obj-m := HelloModule2416.o
else
#bbblack kernel
KERNELDIR ?= /home/zyd/soft/s3c2416/20140409_HELPER2416/Helper2416/source/s3c-linux.jyx
PWD := $(shell pwd)
modules:
make -C $(KERNELDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
modules_install:
make -C $(KERNELDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules_install
app: app.c
$(CROSS_COMPILE)gcc -o app app.c
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
3. Compile
When executing make modules, an error message ERROR: Kernel configuration is invalid.
It turns out that you need to compile the kernel first
OK, go to the kernel directory /home/zyd/soft/s3c2416/20140409_HELPER2416/Helper2416/source/s3c-linux.jyx and execute the command
make ARCH=arm CROSS_COMPILE=arm-linux- zImage
Note that you must specify the target and compiler. Otherwise, the compiled version will be x86.
After compiling the kernel, you can compile hellomodule.
But when I downloaded the compiled hellomodule.ko driver file to the development board and ran it, an error occurred again. It seemed that the kernel was inconsistent. Oh my god! ! ! ! ! ! ! !
How to solve it?
Starting from the cause, it is suggested that the kernel of the development board and the kernel compiled by the driver are inconsistent.
The kernel of the development board can be viewed using the uname -r command as follows
[root@jyxtec /root]# uname -r
3.2.50+
When the development board starts, the following information is printed
Linux version 3.2.50+ (d02cj@LinuxServer0) (gcc version 4.4.6 (crosstool-NG 1.14
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
Check the driver information as follows
modinfo HelloModule2416.kofilename: HelloModule2416.ko
alias: a sample module
description: A sample bbblack hello module
license: Dual BSD/GPL
author: Zhao Yidong zmurder@outlook.com
depends:
vermagic: 3.2.50 mod_unload ARMv5 p2v8
The kernel of the driver is inconsistent with the kernel of the development board. Because I compiled the kernel before compiling the driver (why do I have to compile the kernel first? I can't compile the driver without compiling the kernel first!!!). The compiled kernel is inconsistent with the kernel on the development board! ! ! ! (Damn the development board vendor, the compiled kernel provided is different from the actual one!!)
Well, now that we know the reason, it’s easy to solve.
Use FTP (assuming FTP is configured) to download your compiled kernel zImage to the development board (refer to Section 3.3.4 of the Junyixing Development Board Manual, Download, Erase, Burn, and Specify Load.)
4. Install and uninstall the driver
At this time, you can use insmod again!!! Hahahahaha!!
But the problem came up again. When using rmmod to uninstall the driver, it prompted (the reason is that busybox is different from the distribution Linux installation, and no corresponding directory is generated)
rmmod: chdir(3.2.50): No such file or directory
Well, here is the solution:
Create a directory: mkdir -p /lib/modules/$(uname -r)
Copy your own driver to this directory
At this point, HelloModule is complete... It was hard!!
Previous article:STM32: STM32 library function configuration
Next article:2416 Development Record 3: Simple LED Driver and Application
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Impedance Matching and the Smith Chart: The Basics
- ATH10 temperature and humidity measurement is inaccurate
- Happy Little New Year! How many days off do you have for the New Year?
- [Pingtou Ge RVB2601 creative application development] 1. Understand Pingtou Ge chips and development platform
- Advantages of using pressure sensors in constant pressure water supply systems!
- How to Make DSP Digital Oscillator Generate Phase-Shifted Sine Wave
- One-to-two high power relay
- CC2640 Button Battery Powered Design Tips
- A new energy company in Beijing is recruiting algorithm and HIL engineers
- May 19 live broadcast review: MPS, Nexperia and Tektronix gathered to discuss the key points of new energy power design