日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux远程登录uart,Linux console,uart,tty的关联关系

發(fā)布時間:2025/3/20 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux远程登录uart,Linux console,uart,tty的关联关系 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

console,uart,tty 的關(guān)聯(lián)關(guān)系

console可以是串口,也可以是vga,console確實是只能輸出,write,內(nèi)核打印。

在 UNIX系統(tǒng)中,計算機(jī)顯示器通常被稱為控制臺終端(Console),它仿真了類型 為的一種終端(TERM=),

并且有一些設(shè)備特殊文件與之相關(guān)聯(lián):tty0、tty1、tty2等。當(dāng)你在控制臺上登錄時,使用的是

tty1。使用Alt+[F1~F6]組合鍵時,我們就可以切換到tty2、tty3等上面去。tty1~tty6等稱為虛擬終端,而tty0則是當(dāng)前所

使用虛擬終端的一個別名,系統(tǒng)所產(chǎn)生的信息會發(fā)送到該終端上。因此不管當(dāng)前正在使用哪個虛擬終端,系統(tǒng)信息都會發(fā)送到控制臺終端上。你可以登錄到不同的虛

擬終端上去,因而可以讓系統(tǒng)同時有幾個不同的會話期存在。只有系統(tǒng)或超級用戶root可以向/dev /tty0進(jìn)行寫操作,

serial_em86xx.c實現(xiàn)的是串口uart驅(qū)動,也注冊了console,在

console_init中調(diào)用console初始化,但是如果serial不做console的話,應(yīng)該就不用注冊console,但是串口uart驅(qū)

動是必須的,就是uart_register_driver,其中涉及最關(guān)鍵的tty_driver,

tty是一類char設(shè)備的通稱,它們有相同的特性,比如對 [^C]的處理,驅(qū)動使用tty_register_driver注冊一個tty。

/dev/console是一個虛擬的tty,它映射到真正的tty上,如何映射等會再說。

console 有多種含義,這里特指printk輸出的設(shè)備,驅(qū)動使用register_console注冊一個console。

console和tty有很大區(qū)別:console是個只輸出的設(shè)備,功能很簡單,只能在內(nèi)核中訪問;tty是char設(shè)備,可以被用戶程序訪問。

實際的驅(qū)動比如串口對一個物理設(shè)備會注冊兩次,一個是tty,一個是console,并通過在console的結(jié)構(gòu)中記錄tty的主次設(shè)備號建立了聯(lián)系。

在 內(nèi)核中,tty和console都可以注冊多個。當(dāng)內(nèi)核命令行上指定console=ttyS0之類的參數(shù)時,首先確定了printk實際使用那個

console作為輸出,其次由于console和tty之間的對應(yīng)關(guān)系,打開/dev/console時,就會映射到相應(yīng)的tty上。用一句話說:

/dev/console將映射到默認(rèn)console對應(yīng)的tty上。

順便說一句,console=ttyS0和/dev/ttyS0包含相同的設(shè)備名字完全是巧合,不同也沒事。

以如果是一個單純的串口通信,可以不用實現(xiàn)console,只要實現(xiàn)uart驅(qū)動,包括tty_driver,就可以在應(yīng)用層調(diào)用串口設(shè)備實現(xiàn)的接口,比

如open(/dev/ttyS0),然后select,用于等待串口上的數(shù)據(jù),而在內(nèi)核層,驅(qū)動中,就是用wait_queue等來實現(xiàn)

select的。/dev/tty,

/dev/console,/dev/tty是正在使用的虛擬終端,因此在這里tty_open就是ttyS0,因為

前臺進(jìn)程的控制終端現(xiàn)在就是ttyS0,/dev/tty可以在用戶空間訪問,就是用戶打印可以在該空間。

serial.c不是必須的,而serial_em86xx.c中提供了與其相似的功能,比如shutdown,startup等方法,以及

console_write等,而console是在內(nèi)核打印,而在erial_em86xx.c中,已經(jīng)有串口uart驅(qū)動,而且與

tty_driver關(guān)聯(lián)起來,所以tty_open打開的就是ttyS0了。如果當(dāng)前進(jìn)程有控制終端(Controlling

Terminal)的話,那么/dev/tty就是當(dāng)前進(jìn)程的控制終端的設(shè)備特殊文件,用戶打印。tty_io.c中除了有

tty_init,tty_open之外還有tty_poll,用于實現(xiàn)poll,另外還有用于異步通知的tty_fasync,主要是通過SIGIO信

號來通知用戶進(jìn)程,因為串口速度不快,用異步通知也可以。而如果速度要求快的話,就需要在中斷中喚醒進(jìn)程,用戶程序用poll,select來等待了。

ldd3中有tty_driver的介紹了。

tty_ldisc是和console有關(guān)系的,n_tty,多串口支持,SIGIO。

tty_ldisc下面才是tty_driver。

串口如果是普通功能,就可以不跟tty關(guān)聯(lián)起來,而實現(xiàn)char設(shè)備即可。

console是內(nèi)核打印,在tty_io.c中console_init中有初始化

em86xx_uart_console_init,在serial_em86xx.c中,有register_console,而

register_console的實現(xiàn)是在printk.c,從而也說明了console內(nèi)核打印和用戶打印tty底層實現(xiàn)不一樣。而用戶程序打印以及

輸入是tty,代碼在行規(guī)n_tty.c中,而tty_ldisc的注冊也是在console_init開始部分的,

(void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY);

只不過這里的console_init部分是與定義的

CONFIG_SERIAL_EM86XX_CONSOLE沒有關(guān)系的,而是與tty有關(guān)

的,n_tty->tty_io->serial_em86xx,serial_core.也就是說即使沒有

CONFIG_SERIAL_EM86XX_CONSOLE,假設(shè)console內(nèi)核打印是在framebuffer,鍵盤的tty0,但用戶程序的打印

輸入是在/dev/tty,最終是可以是在/dev/ttyS0,從而用戶程序就可以通過/dev/ttyS0普通串口通信與串口通信設(shè)備通信了,而此時

串口驅(qū)動可以不實現(xiàn)serial_console功能.

console.c

#ifdef CONFIG_VT

con_init();

#endif

tty_init

#ifdef CONFIG_VT

dev_console_driver = dev_tty_driver;

dev_console_driver.driver_name = "/dev/vc/0";

dev_console_driver.name = dev_console_driver.driver_name + 5;

dev_console_driver.major = TTY_MAJOR;

dev_console_driver.type = TTY_DRIVER_TYPE_SYSTEM;

dev_console_driver.subtype = SYSTEM_TYPE_CONSOLE;

if (tty_register_driver(&dev_console_driver))panic("Couldn't register /dev/tty0 driver\n");

kbd_init();

#endif

console.c以及CONFIG_VT是內(nèi)核控制臺,內(nèi)核打印方面的。

config VT

bool "Virtual terminal" if EMBEDDED

select INPUT

default y if !VIOCONS

---help---

If you say Y here, you will get support for terminal devices with

display and keyboard devices. These are called "virtual" because you

can run several virtual terminals (also called virtual consoles) on

one physical terminal. This is rather useful, for example one

virtual terminal can collect system messages and warnings, another

one can be used for a text-mode user session, and a third could run

an X session, all in parallel. Switching between virtual terminals

is done with certain key combinations, usually Alt-.

The setterm command ("man setterm") can be used to change the

properties (such as colors or beeping) of a virtual terminal. The

man page console_codes(4) ("man console_codes") contains the special

character sequences that can be used to change those properties

directly. The fonts used on virtual terminals can be changed with

the setfont ("man setfont") command and the key bindings are defined

with the loadkeys ("man loadkeys") command.

You need at least one virtual terminal device in order to make use

of your keyboard and monitor. Therefore, only people configuring an

embedded system would want to say N here in order to save some

memory; the only way to log into such a system is then via a serial

or network connection.

If unsure, say Y, or else you won't be able to do much with your new

shiny Linux system :-)

config VT_CONSOLE

bool "Support for console on virtual terminal" if EMBEDDED

depends on VT

default y

---help---

The system console is the device which receives all kernel messages

and warnings and which allows logins in single user mode. If you

answer Y here, a virtual terminal (the device used to interact with

a physical terminal) can be used as system console. This is the most

common mode of operations, so you should say Y here unless you want

the kernel messages be output only to a serial port (in which case

you should say Y to "Console on serial port", below).

If you do say Y here, by default the currently visible virtual

terminal (/dev/tty0) will be used as system console. You can change

that with a kernel command line option such as "console=tty3" which

would use the third virtual terminal as system console. (Try "man

bootparam" or see the documentation of your boot loader (lilo or

loadlin) about how to pass options to the kernel at boot time.)

If unsure, say Y.

config SERIAL_8250_CONSOLE

bool "Console on 8250/16550 and compatible serial port"

depends on SERIAL_8250=y

select SERIAL_CORE_CONSOLE

---help---

If you say Y here, it will be possible to use a serial port as the

system console (the system console is the device which receives all

kernel messages and warnings and which allows logins in single user

mode). This could be useful if some terminal or printer is connected

to that serial port.

Even if you say Y here, the currently visible virtual console

(/dev/tty0) will still be used as the system console by default, but

you can alter that using a kernel command line option such as

"console=ttyS1". (Try "man bootparam" or see the documentation of

your boot loader (grub or lilo or loadlin) about how to pass options

to the kernel at boot time.)

If you don't have a VGA card installed and you say Y here, the

kernel will automatically use the first serial line, /dev/ttyS0, as

system console.

If unsure, say N.

總結(jié)

以上是生活随笔為你收集整理的linux远程登录uart,Linux console,uart,tty的关联关系的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。