Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of examples written by linux drivers

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "sample analysis of linux drivers", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and study the "sample analysis of linux drivers".

Before I left, the job involved little knowledge of driving. All I have to do is split the customer's request for the device into an interface and call the settings of the driver to configure it. Of course, as for how the driver is implemented, it depends on the situation. For example, some drivers are written directly by chip manufacturers, assuming that chip manufacturers provide sdk functions for the corresponding platform, then the work of the driver is to encapsulate these sdk functions, and the other is to write the driver interface for a specific platform. For example, now you need to write serial port, i2C, i2s, FLASH, network card, LCD, touch screen, USB driver. At this time, you have nothing but a bunch of chip manuals in your hand. Whether you can debug successfully or not is up to you. Of course, in general, there will be a lot of demo code of the same type on a particular platform, and you can modify it according to it. Except for interrupts, addresses, reading and writing, and so on, most of the logic is not very different. As to whether the speed of modification is fast or not, it depends on you.

What we are going to talk about today is linux driver writing. Now linux drivers are popular for several reasons: 1) the linux platform is free, and many chip manufacturers want linux platforms to support their products; 2) recently, android platforms are very popular, which has invisibly helped linux, and more and more people are engaged in linux drivers. 3) there is also the income, according to the current basic market, the income of driver-driven engineers is higher than that of ordinary development engineers, which can be answered from the recruitment website, so many friends are happy to switch to this industry. So, at this time, many friends may have questions, do chip driver design really need to understand linux?

In fact, driver and linux are two different things. Take a lcd, for example, we can write drivers on windows ce, or we can use linux framebuffer to write drivers. Of course, if we are friends who do communication, we can also use vxworks to do drivers. There is no limit to the driver, but it also has to be linked to the specific operating system platform in order to make sense. Of course, some friends said, do we have to have an operating system? In fact, you can do without an operating system, or do a simple while (1) foreground and background system, but the efficiency of this development is not high, and the scalability is not good. Since linux has set up the framework for us, why can't we just use it for processing?

Friends who are familiar with the linux platform all know that. On linux, all devices can be treated as files. Basically, all our operations on the equipment can be simplified to open, close, read, write, and io control. As for what these operations have done, we need to implement them ourselves. Now, the linux driver development process has been very mature, in addition to a lot of demo code, books, there are a lot of videos to learn online. Among them, I personally prefer the books of Song Baohua and Wei Dongshan. The former tends to be more theoretical, while the latter pays more attention to the content of practice.

Having said so much, you may ask how to do a good job in linux-driven development. For myself, this is how I usually deal with it.

(01) find two computers, one with windows system and the other with linux system. There is no restriction on the type.

(02) to view the version type of the linux system, type uname-r

(03) according to the linux kernel version obtained, find the appropriate kernel version on www.kernel.org and download it directly with wget.

(04) decompress the kernel version with tar, copy the config file under boot to local, enter make menuconfig, and save it directly.

(05) enter make-j2 & make modules_install & make install to restart the system.

(06) after the linux system is installed, pay attention to selecting the newly compiled kernel version when grub starts, so that the kernel driver can be developed on linux.

(07) install secureCRT tools on windows platform and connect with linux

(08) enter the following code, hello.c and Makefile, respectively, where the hello.c content is as follows

# include # include # include MODULE_LICENSE ("GPL"); MODULE_AUTHOR ("feixiaoxing"); MODULE_DESCRIPTION ("This is just a hello module!\ n"); static int _ init hello_init (void) {printk (KERN_EMERG "hello, init\ n"); return 0;} static void _ exit hello_exit (void) {printk (KERN_EMERG "hello, exit\ n");} module_init (hello_init); module_exit (hello_exit)

The content of Makefile is as follows

Ifneq ($(KERNELRELEASE),) obj-m: = hello.o else PWD: = $(shell pwd) KVER: = $(shell uname-r) KDIR: = / lib/modules/$ (KVER) / build all: $(MAKE)-C $(KDIR) build all $(PWD) modules clean: rm-rf. * .cmd * .o * .mod.c * .ko .tmp _ versions endif

(09) when compiling, you can make directly. Of course, the premise is that the two files must be in one directory.

(10) generate a hello.ko file after compilation, which you can think of as an ordinary execution file

(11) if you need to install, you can simply insmod hello.ko. Type dmesg | tail to see the printed content, and enter lsmod | grep hello to see whether the module has been installed.

(12) if you delete a module, you can enter rmmod hello directly. Of course, both add and delete operations need to be performed in root mode.

So these are the simple development steps of the linux driver.

The above is all the contents of the article "sample Analysis written by linux drivers". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report