2416 Development Record 2: The simplest helloworld driver

Publisher:乡村乐园Latest update time:2019-01-17 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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!!


Reference address:2416 Development Record 2: The simplest helloworld driver

Previous article:STM32: STM32 library function configuration
Next article:2416 Development Record 3: Simple LED Driver and Application

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号