tiny4412 Serial drive analysis of nine---shell terminal

Source: Internet
Author: User

Pengdonglin

Email:[email protected]

Development Board: tiny4412adk+s700 4GB Flash

Host: Wind7 64-bit

Virtual machine: vmware+ubuntu12_04

U-boot:u-boot 2010.12

Linux kernel version: linux-3.0.31

Android version: android-4.1.2

In the above we know how/DEV/TTYSACX is generated, and you can also see the device node/dev/console and/dev/tty and other device nodes under/dev.

You can see the input characters to/DEV/TTYSAC0,/dev/console, and/dev/tty, and then the characters are output to the serial terminal:

However, if you use the ADB shell login, the phenomenon is different:

Where the left window is under the ADB shell, the right window is the serial terminal display, you can see if the ADB shell under the/dev/ttysac0 and/dev/console write characters, this character is not displayed under the ADB shell Terminal, Instead, it shows up in the serial terminal, when writing characters under the ADB shell terminal to/dev/tty, it is displayed under the ADB shell terminal, and does not affect the display of the serial terminal.

What are the reasons behind the above phenomena? Below we begin to analyze the kernel source code to explain.

First you need to know how these device nodes are generated:

Late_initcall (Chr_dev_init);

----Tty_init () (DRIVERS/TTY/TTY_IO.C)

int__init Tty_init (void) {Cdev_init (&tty_cdev, &tty_fops); if(Cdev_add (&tty_cdev, MKDEV (Ttyaux_major,0),1) ||register_chrdev_region (MKDEV (Ttyaux_major,0),1,"/dev/tty") <0) Panic ("couldn ' t register/dev/tty driver\n"); Device_create (Tty_class, NULL, MKDEV (Ttyaux_major,0), NULL,"TTY"); Cdev_init (&console_cdev, &console_fops); if(Cdev_add (&console_cdev, MKDEV (Ttyaux_major,1),1) ||register_chrdev_region (MKDEV (Ttyaux_major,1),1,"/dev/console") <0) Panic ("couldn ' t register/dev/console driver\n"); Consdev= Device_create (Tty_class, NULL, MKDEV (Ttyaux_major,1), NULL,"Console"); if(Is_err (Consdev)) Consdev=NULL; Elsewarn_on (Device_create_file (Consdev,&dev_attr_active) <0); return 0;}

The console and TTY two device nodes are generated here under/dev/, and their corresponding fops are Tty_fops and Console_fops respectively.

The Tty_register_device function analyzed above generates/DEV/TTYSACX, and its corresponding fops is set in the function tty_register_driver in order to Tty_fops. So the key here is to analyze how tty_fops and Console_fops are implemented.

The comparison found that Console_fops and Tty_fops are the same:

Static Const structFile_operations Tty_fops ={. Llseek=No_llseek,. Read=Tty_read,. Write=Tty_write,. Poll=tty_poll,. Unlocked_ioctl=tty_ioctl,. Compat_ioctl=tty_compat_ioctl,. Open=Tty_open,. Release=tty_release,. Fasync=Tty_fasync,};Static Const structFile_operations Console_fops ={. Llseek=No_llseek,. Read=Tty_read,. Write=Redirected_tty_write,. Poll=tty_poll,. Unlocked_ioctl=tty_ioctl,. Compat_ioctl=tty_compat_ioctl,. Open=Tty_open,. Release=tty_release,. Fasync=Tty_fasync,};

When the echo "Peng" >/dev/ttysac0 is executed, the Tty_open is called and then Tty_write is called, and the tty_release is finally called.

tiny4412 Serial drive analysis of nine---shell terminal

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.