Simple process of Device Driver learning in Linux

Source: Internet
Author: User

In order to record the learning-driven process, I took notes. A month later, when I became a driver, I looked back at my thoughts... It should be a wonderful feeling.

So, come on! Everyday is nice!

About Basics

1. tar can be used to back up key data, while dd can be used to back up the entire partition or the entire disk

2. vim Block selection (Visual Block) Function

3. In addition to the environment variables, the set command will list all our custom variables and all variables.

4. view the startup running time in uptime

5. head and tail commands

Usage: head-n file name

6. lsmod rmmod insmod modprobe

7. Use the disassembly command

Arm-linux-objdump-D-S hello> log

8. wireshark network protocol analyzer

-----------------------------------------------------------------

9. Shell Learning

If [$ a1 = $ a2]

. There are spaces on both sides of the [and] symbol.
. = Spaces exist on both the left and right sides.

A1 = "hello"
Echo $ a1

There cannot be spaces on both sides of the variable assignment.
A semicolon is not required for statements in. bash.

. Comparison Symbol:-eq-gt-lt-ne-ge-le-z (empty)-n (not empty)

. Determine the file Symbol:-e-f-s-d-r-w-x

. If statement

If []
Then
# Code
Else if []
Then
# Code
Else
# Code
Fi
Fi

. For statement
For VaR in [LIST]
Do
# Code
Done

. While statement
While []
Do
# Code
Done

. Until statement
Until []
Do
# Code
Done

. Case statement
Case "$ Var" in
Condition1)
;;
Condition2)
;;
*)
Default statments ;;
Esac

-----------------------------------------------------------------

10. makefile

. $ ^: Indicates all dependent files.
. $ @: Indicates the target
. $ <: Indicates the first dependent file.

11. Time

Time_t t;
T = time (NULL); // current time

Gettimeofday (& tpstart, NULL); // start time
Function ();
Gettimeofday (& tpend, NULL); // End Time

-----------------------------------------------------------------

12.
The fork sub-process copies the data segment of the parent process. The execution sequence is not fixed.
Vfork: The child process shares the data segment with the parent process. The child process runs first.

-----------------------------------------------------------------

13.exe c function family
Exec starts a new program, replacing the original process with the PID unchanged

-----------------------------------------------------------------

14. Process Communication
. Pipe Communication
. Signal Communication
. Shared Memory

MPs queue:
. Unknown pipeline pipe (int fd [2])
. Famous pipe mkfifo (const char * filename, mode_t, Mode)

15. POSIX portable operating system interfaces

-----------------------------------------------------------------

16. Message Queue
. Return key value key_t ftok (char * pathname, char proj)
. Get the queue description int msgget (key_t key, int msgflag)
. Send message int msgsnd (INT msqid, struct msgbuf * msgp, int msgsz, int msgflg)
. Read Information int msgrcv (INT msqid, struct msgbuf * msgp, int msgsz, long msgtyp, int msgflg)

17. semaphores
. Binary signal 0, 1
The Count signal lamp is not negative.

18. Multi-Thread Programming

. Create thread
Int pthread_create (pthread_t * TIDP, const pthread_attr_t * ATTR, void * (* start_rtn) (void), void * Arg)
TIDP: thread ID
ATTR: thread attributes
Start_rtn: the thread executes the function.
Parameters of Arg start_rtn:

. Waiting thread
Int pthread_join (pthread_t * tid, void ** rval_ptr)
TID: ID of the thread waiting to exit
Rval_ptr: pointer to the thread Return Value

. Thread ID
Pthread_t pthead_self (void)
Return thread ID

-----------------------------------------------------------------

19. Linux TCP/IP
. Application layer transport layer network interface layer

. Socket three types: stream socket (sock_stream) ---- reliable, datagram socket (sock_dgram) ---- unreliable, original socket (sock_raw ).

. Struct sockaddr_in record the network address

. Address Conversion
Int inet_aton (const char * CP, struct in_addr * indium) to network IP address
Char * inet_ntoa (struct in_addr in) to convert characters

. Byte order
Network Transmission big endian

The host sequence used for sending htons/htonl to the network Sequence
Ntohs/ntohl used for receiving, network order conversion to host order

. Obtain the IP address or host name
Struct hostent * gethostbyname (const char * hostname)

-----------------------------------------------------------------
20. Virtual File System
VFS hides the details of various file systems and provides unified interfaces for file operations.
 
21. kernel development, mainly modifying driver and arch (Architecture)

-----------------------------------------------------------------

22. Kernel configuration and compilation

. Clear command: Make clean/make mrproper/make distclean

Determine the hardware and software configurations of the target system, such as the CPU type, Nic model, and supported network protocols.

. Start Kernel configuration
Run the command: Make menuconfig

. Compile
Make zimage/make bzimage
* Make zimage v = 1 to get compilation Information

The compiled kernel is located at: ARCH/<CPU>/boot/

. Compile the kernel module
Make modules

. Install the kernel module
Make modules_install

/Lib/modules

. Create init ramdisk

Mkinitrd initrd-2.6.29 2.6.29

23. kernel Installation Steps
. Cp arch/x86/boot/bzimage/boot/vmlinuz-$ version
. CP $ initrd/boot/
. Modify/etc/grub. conf or/etc/Lilo. conf.

24. kernel module

Main makefile:

Ifneq ($ (kernelrelease ),)

OBJ-M: = Hello. o

Hello_objs: Main. o add. O (Multi-file)

Else
Kdir: =/lib/modules/2.6.18-53. EL5/build

ALL:
Make-C $ (kdir) M = $ (PWD) Modules
Clean:
Rm-f *. Ko *. O *. Mod. O *. Mod. C. symvers
Endif

Module parameters: module_param (name, type, Perm)
Int A = 3;
Module_param (A, Int, s_irugo );

-----------------------------------------------------------------

25. kernel symbol export-two or more modules are useful
Export_symbol (symbol name)
Export_symbol_gpl (symbol name)

26. kernel printing/proc/sys/kernel/printk

27. tool chain arm-Linux-gcc

-----------------------------------------------------------------

28. bootloader Workflow
Stage1
Hardware Device Initialization
. Prepare the ram space for loading the stage2 of bootloader.
. Copy the stage2 of bootloader to the ram space.
. Set the stack.
. Jump to the C entry point of stage2

Stage2
. Initialize the hardware devices to be used in this phase
. Copy the kernel and root file system from flash to ram
. Call the kernel

-----------------------------------------------------------------

29. uboot

Command: Help/printenv/setenv (add, delete, modify)/saveenv \
MD/MM/flinfo/protect off (on) All/Erase start end/
CP/go/bdinfo (Development Board Information)

Port: mCu/MPU reference

30. Embedded kernel Creation
1. Clear make distclean
2. Configure make menuconfig arch = arm
3. Compile make uimage arch = arm cross_compile = arm-Linux-

-----------------------------------------------------------------
31. Create a root file system
@ Create a directory for the root file system
. Mkdir rootfs
. CD rootfs
. Mkdir bin Dev etc lib proc sbin sys usr mnt tmp VaR
. Mkdir usr/bin usr/lib usr/sbin lib/modules

@ Create a device file
. Cd dev/
. Mknod-M 666 console C 5 1
. Mknod-M 666 null C 1 3

@ Install/etc
. Tar etc.tar.gz-C/XXX/rootfs

@ Compile the kernel module
. Make modules arch = arm cross_compile = arm-Linux-

@ Install the kernel module
. Make modules_install arch = arm
Install_mod_path =/XXX/rootfs

@ Configure busybox

@ Compile and install
Make arch = arm cross_compile = arm-Linux
Make install

 

 

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.