Linux arm driver development Summary

Source: Internet
Author: User
Tags dmesg
Driver Design:
Differences between Linux drivers and bootloader drivers:
The interface with the application layer should be considered;
Consider multiple users;
Consider other protocols;

The role of the device driver: Read data and write data;
Initialize devices, read and write devices, allocate device data to applications, and allocate application data to devices;

The relationship between drivers and devices in the operating system is one-to-one;
The relationship between applications and drivers is one-to-many;

Main features of the kernel: process management, memory management, file system, device control, and network;

Linux drivers: character devices, Block devices, and network devices;

In most cases: the editor ID identifies the corresponding driver (modern Linux allows multiple drivers to share the editor ID), and the next device ID identifies which device;

CP of the device file: $ sudo CP-A/dev/mouse/tmp/(fopen opens the device file)
$ Sudo CP/dev/mouse/tmp/(open to open the device)

View the driver information of a Linux device:
/Proc/devices: view the supported character devices and block device drivers;
/Proc/PCI view the system's PCI device;
/Proc/ioports view the device's IO port;
/Proc/interrupts: Check the interrupt number in use and the number of interruptions;
/Proc/NET/dev: View network hardware devices, including the down Nic;
/Proc/kallsyms view the module symbol;
/Proc/jitimer to view the timer;
Dmesg can view the startup information of the system, and view the printing information of some drivers supported by the system;
Lspci
Lsusb-V

Uname-
Ifconfig-a view all NICs

All modules are drivers, but most modules are drivers;

Those functions can be used in the module. For the kernel API, you can view the http://kernelbook.sf.net

Re-compile the module:
Decompress the Linux source code package in/usr/src/Linux;
Copy the configuration file: CP/boot/config-2.6.20-16.generic/usr/src/Linux/. config;
Re-compile the kernel: sudo make
Compile the module in the project directory of the module: Make

Module parameter transfer:
Module_param (name, type, Perm );
Static int count;
Module_param (count, Int, 0 );

# Insmod driver. Ko COUNT = 10
# Lsmod
# Rmmod driver

Module Cross-compilation (ARM development board ):
Re-compile kernel 2.6.17.14 and pass zimage to the Development Board;
Copy the module project directory to rootfs/usr/module;
Change the source code path of the makefile in the module to the path of the 2.6.17.14 kernel;
Recompile sudo make;

Application Layer ---> telnet, FTP, email
Transport Layer ---> TCP, UDP
Network Layer ---> ip, ICMP, IGMP
Link Layer ---> device drivers and interface cards

USB device driver:
Important websites:
Knowledge about Linux drivers: http://www.xml.com/ldd/chapter/bookdownload Linux Device Drivers, 2nd Edition
USB related information: http://www.bode.cs.tum.edu/Par/arch/usb/usbdoc

Http://www.usbman.com/developer.htm

Http://www.usb.org

USB1.1 specification: http://www.usb.org/developer/docs/usbspec.zip
OHCI Protocol: ftp://ftp.compaq.com/pub/supportinformation/papers/hcir1_0a.pdf
Uhci Protocol: http://developer.inter.com/technology/usb/UHCI11D.pdf

Lsusb-V: View USB device information;
Vendor: Product = 1241: 1111 this is the ID number of the USB device, which must be obtained from USB. org;
Numconfigurations = 1 indicates that one configuration descriptor exists;
Bendpointaddress = 81 (in) means 1000 0001, the highest bit 1 is read, and the last 1 is the endpoint number;
Bmattributes = 03 (Interrupt) indicates that the transmission is interrupted; therefore, binterval = 08 (8 ms) indicates that the interval is 8 ms;

Working Process:
The USB Host Controller accesses all devices through DMA;
Read/write to a device is achieved through the device endpoint;
The USB Host polls these endpoints through the Protocol linked list. to work properly, you need to fill in the endpoint format and put it in the Protocol linked list;
Control, real-time, interrupted, and massive transmission require different methods to fill the Protocol linked list;
When the hardware reads and writes are completed, the CPU is notified through interruption and the CPU is used to handle the remaining work;
Character device Block C device B network device (no device file)
The device file has a file node, but no real content;
The ID of the driver connected to the device. The device number is used to determine the device to be referenced (generally, not absolute );
Kernel type of the device number dev_t Major (dev_t Dev); minor (dev_t Dev );
Mkdev (INT major, int minor ); Sudo CP-A/dev/input/mice/tmp/# fopen copy file
Sudo CP/dev/input/mice/tmp/# Open the device
CAT/proc/devices PCI ioports interrupts
Lspci // lsusb-V // cpuinfo partitions // dmesg can view the module output information
Kallsyms module loading location ???
Ln-s SDA/C/CC symbolic connection
Sudo aptitude install linux-source-2.6.20
The header file parameters of the module are written using the delay parameters. The user space and the data in the kernel space are used for mutual transmission;
Copy_to_user/copy_from_user put_user/get_user

The first linuxkernel module experiment:
Uname-A // view the current version
Check whether there is a corresponding Linux source under/user/src/. If not, download and install the linux-source-2.6.20
Sudo CP/boot/config-2.6.20-15.generic/usr/src/linux-2.6.20/. config
Sudo make
In the module compiling directory, make
Use insmod rmmod lsmod again
Dmesg View module access information;

Com2 settings:
Ucon1l (v) B (X )??? Send urxh1-> L (v) B (X) to receive;
There are two methods to read and write physical addresses:
1. # define ucon1 (* (volatile unsigned *) ioremap (0x500c4004, 4 )))
2. Include
# Define iobase s3c24xx_va_uart1
# Define ucon1 (iobase + 0x04)
_ Raw_writel (5, ucon1 );
State = _ raw_readb (utrstat1 );

/N newline/R carriage return ~ /. Define the function (void) void of the trash recycle bin;
Need to include some
Experiment process:
Decompress the linux2.6.17.14 code ~ /. Directory, re-make menuconfig to set arm and add module support;
After re-compilation, download the kernel zimage to the 2410 board,
In the driver editing directory, change the SRC path of makefile ~ /. Linux2.6.17.14;
Make to get the driver. Ko file and copy it to rootfs/usr/driver /.
The Development Board is started in NFS mode. Run insmod driver. Ko, lsmod, and rmmod driver in minicom to observe the results;

Scull Device Driver:
When writing a device driver, you encounter the following problems:
1. Sending and receiving are the same-> Buf [] points to a fixed string, and separate arrays must be sent and received;
2. send and receive.-> send and receive different arrays in the driver. Write requests can be dynamically applied. Receiving and receiving arrays is successful ???
3. Use an array pointer for sending and receiving, for example, * Buf ++. The result has been moved. Use Buf [TMP ++;
4. After count --, count is used in copy_to_user (BUF, kbuf, cout), and count is already 0;
5. The recieve information is interrupted by char release in the terminal display. Two processing methods are feasible: Sleep (1) Before close; no information is printed in release;
6. After TMP ++, return TMP is exactly the number of reads, rather than TMP + 1;

Sudo-S/su Username

Character Device Driver, gpio DRIVER:
Concepts:
Dev_t is a 32-bit device number (12 + 20); scull_dev structure, cdev Structure
Old registration method: register_chrdev (Major, & name, & FOPS)
Unregister_chrdev (Major, & name)
New registration method: regist_chrdev_region (dev_t, Count, & name );
Alloc_chrdev_region (& Dev, firstminor, Count, & name );
Major = major (Dev );
Cdev_init (& cdev, & FOPS); cdev. Owner = this_module; cdev. Ops = & FOPS;
Cdev_add (& cdev, devno, 1); cdev_del (& cdev );
Unregister_chrdev_region (first, count );
Interruption:
Processor device management methods, round robin, interrupt + DMA;
S3C2410 supports 56 interrupt devices and 32 interrupt numbers. srcpnd, intpnd, and intmsk are written to 1 to 0;
Request_irq (IRQ, & handler, flags, & dev_name, & dev_id); free_irq (IRQ, & dev_id );

Gpio experiment:
Note these directories: ASM/arch-s3c2410/regs-irq.h ASM/arc-s3c2410/regs-serial.h
Register name: s3c2410_eintpend
Register read/write function: _ raw_writel () _ raw_writeb () _ raw_readl () _ raw_readb ()
Registers srcpnd, intpnd, and eintpent all write 1 clear 0;
Irq_return_t is the return type of the interrupted service function;
Static struct semaphore key_sem;
Up (& key_sem); down_interruptible (& key_sem );
Open is interrupted, release is disconnected, and rmmod is free (IRQ );
Set_irq_type: Set the interrupt type;

. Bashrc: + PS1 = '$' can change the display content of the shell prompt;
Recommended books: Linux kernel design and implementation = Chen Lijun, Linux driver Ji Li

NIC Driver:
NIC: real mode, 286, 1 m;/protection mode, 386, 4G
Bootrom: Start Novell Network, IPX protocol, Virtual Disk in memory;
MAC protocol layer + PHY & Transport Layer, Physical Layer
Mac requests six hexadecimal numbers from IEEE, And the last six hexadecimal companies have their own configurations. 00. xx. xx. yy
The device ID identifies the manufacturer and model. It is saved in the device list and maintained by PCI, USB, and other protocols;
Network cable, 4-wire, and 8-wire have a group of backups;
LCD and tvout. If they use separate sources, conflicts may occur;
Nic debugging method: hardware (power supply, crystal oscillator...); software (...);
After removing the NIC of the arm Development Board, you can use the serial port to transmit the program:
1. Start PC-side minicom and start the development board
2. Go to Linux, CD/tmp
3. Rx file name; C + A, s; select XMODEM;
4. Select a file (double space-> directory; space + press Enter );
If the PC does not work, install lrzsz.
Define several types of conditions: typedef, struct, # define, etc; Search Method: grep STR key $, key {, key null {and other methods;
S3c2410_irqreg (x)-> C (x) + s3c24xx_va_irq)
The soket system calls to operate network devices, rather than opening a device file;
Check the hardware method of the network card. Make sure there are several network cards. CAT/proc/NET/dev or ifconfig-
One method of viewing the IP address of the Local Machine, ping an IP address that cannot be connected; (in the absence of ifconfig );
Ifconfig up --> open ifconfig down --> close;
Register_netdev initializes net_device and calls the init function;
Main net_device members: init, open (request_irq), stop (free_irq), hard_start_xmit, net_stats;
After receiving and transmitting data, netif _rx delivers the received data to the protocol layer, netif-start/stop/wake-queue
# Define smdk2410_eth_irq irqeint8
Smdk2410 exists in four directories: Include/ASM (ARM-arm)/arch (arch-s3c2410 );
Dual-index register operation, scalable storage space;
Lxr & source insight are two tools for viewing source code;
Nic experiment:
Two packet capture tools: TCPDUMP-I eth1 // wire shark
Main steps:
1. Start a non-network Linux;
2. Download driver8900.ko, server, and client to the Board;
3. mknod/dev/mynet C 242 0
4. insmod driver8900.ko
5../server or./client

Hardware part 1015:
AGND-----L----DGND
Storage mode, with cache I/O mode, without cache;
Nandflash d [7: 0] data/command/address multiplexing
Ram uses six tubes, while SDRAM uses one pipe and one capacitor;
Candence merges orcad and is easy to use;

Nic experiment:
1. Write (pp_txtmd), write (pp_txlength) read (pp_busst); if the order is reversed, the write fails;
2. The received ping packet contains 64 bytes, And the last 4 bytes may be the CRC verification code;
3. You can put Buf = {0x11, 0x12...} in the header file, and the program references it for data transmission;
4. If rdonly is used for open, it cannot be written successfully;

You can view CAT/proc/ioports/observe the IO space;
Eint8-> 0xf0000000 + 36

USB1.1, USB2.0/master, slave, OTG device (5-core)
USB disadvantages: unstable, line "ello ";
If (defined (x) can be a variable; ifdef X can only be a macro;
The output result of 2.0/3.0 is different from that of 2/3. The former is float data;
Dpkg-l nfs-kernel-server display installation directory
Generally, server configuration problems can be solved by copying the correct configuration file;

Macro definitions, Conditional compilation, and annotations are used in programming;

Some examples of driver:

# Driver makefile

Ifneq ($ (kernelrelease ),)
# Kbuild part of makefile
OBJ-M: = driver. o
Else

Kernelsrc: =/home/username/linux-2.6.17.14
Modules:
Make-C $ (kernelsrc) subdirs = $ (PWD) $ @

Clean:
For specific source code, see the original source.

Http://blog.chinaunix.net/u1/53151/showart_423232.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.