WO2021120960A1 - Usb serial port realization method for linux system console, and related product - Google Patents

Usb serial port realization method for linux system console, and related product Download PDF

Info

Publication number
WO2021120960A1
WO2021120960A1 PCT/CN2020/129511 CN2020129511W WO2021120960A1 WO 2021120960 A1 WO2021120960 A1 WO 2021120960A1 CN 2020129511 W CN2020129511 W CN 2020129511W WO 2021120960 A1 WO2021120960 A1 WO 2021120960A1
Authority
WO
WIPO (PCT)
Prior art keywords
serial port
terminal
usb serial
console
usb
Prior art date
Application number
PCT/CN2020/129511
Other languages
French (fr)
Chinese (zh)
Inventor
吴天准
贺传敏
Original Assignee
深圳先进技术研究院
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳先进技术研究院 filed Critical 深圳先进技术研究院
Publication of WO2021120960A1 publication Critical patent/WO2021120960A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2213/00Indexing scheme relating to interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F2213/0042Universal serial bus [USB]

Definitions

  • This application relates to the field of software, in particular to a method for implementing a USB serial port of a Linux system console and related products.
  • Embedded Linux is an operating system that tailors the increasingly popular Linux operating system to make it run on an embedded computer system. Embedded Linux not only inherits the unlimited open source code resources on the Internet, but also has the characteristics of an embedded operating system. Embedded Linux is characterized by free copyright fees, free software developers around the world to provide support, and excellent performance, easy software transplantation, open code, support for many application software, short application product development cycle, rapid launch of new products, and Many public codes can be referenced and transplanted. The information generated during the startup and operation of the Linux system will be sent to the terminal.
  • the console (console) is a buffer concept, which actually provides information printing for the kernel; embedded Linux terminals generally use uart serial ports. The transmission speed of the existing uart serial port is very slow and low in efficiency.
  • this application discloses a method for implementing a USB serial port of a Linux system console, which can realize the printing of kernel information through the USB serial port, which improves the data transmission speed and efficiency.
  • the first aspect of the embodiments of the present application provides a method for implementing a USB serial port of a Linux system console.
  • the method includes the following steps:
  • the console terminal When the console terminal detects that the USB cable is inserted, it sets the connection status of the USB cable to the connected status, and calls the function to adjust the status of the USB serial port to open;
  • the console terminal determines that the first USB serial port opposite to the USB serial port is open, the console terminal sets the status of the USB serial port to an open state;
  • the console terminal obtains the printk information, and calls the write function of the console port to send the printk information and the data in the preset buffer area to the peer device through the USB serial port.
  • the registering the USB serial port as a terminal specifically includes:
  • the calling function to adjust the status of the USB serial port to open specifically includes:
  • the console terminal calls the open function to adjust the status of the USB serial port to the open state.
  • the method further includes:
  • the console terminal determines that the first USB serial port opposite to the USB serial port is closed, the console terminal caches the acquired printk information in the preset cache area.
  • a terminal is provided, the terminal is an embedded Linux system, the terminal further includes a USB serial port, and the terminal further includes:
  • the startup unit is used to call the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup, and to register the USB serial port as a terminal;
  • the processing unit is used to set the connection status of the USB cable to the connected status when detecting that the USB cable is inserted, and call a function to adjust the status of the USB serial port to open; determine that the first USB serial port opposite to the USB serial port is open At this time, the console terminal sets the status of the USB serial port to the open state; obtains the printk information, and calls the write function of the console port to send the printk information and the data in the preset buffer area to the opposite device through the USB serial port.
  • the processing unit is specifically configured to register the USB serial port as a terminal through the register_console function when the module_init is driven in the gadget serial driver code.
  • the processing unit is specifically configured to call an open function to adjust the state of the USB serial port to an open state.
  • the processing unit is further configured to determine that when the first USB serial port opposite to the USB serial port is closed, the console terminal caches the acquired printk information in the preset cache area
  • a Linux hardware system includes: a peer device and a console terminal;
  • the console terminal is used to invoke the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup and register the USB serial port as a terminal; when the USB cable is detected, the connection status of the USB cable is set to the connected state and called The function adjusts the status of the USB serial port to open;
  • the opposite device is used to start the terminal application, start the first USB serial port corresponding to the USB serial port, and set the state of the first USB serial port to the open state; send the start action to the console terminal;
  • the console terminal is also used to determine that when the first USB serial port opposite to the USB serial port is opened, the console terminal sets the status of the USB serial port to the open state; obtains printk information, and calls the write function of the console port to set the printk information and presets The data in the buffer area is sent to the peer device through the USB serial port.
  • the fourth aspect of the embodiments of the present application provides a computer-readable storage medium that stores a computer program, and the computer program includes program instructions that, when executed by a processor, cause the processor to Perform the method described in the first aspect of the embodiments of the present application.
  • the technical solution provided by this application modifies the console terminal so that the console terminal can print (ie, transmit and display) printk information through the USB serial port. Since the transmission speed of the USB serial port is much faster than that of the ordinary serial port, this The technical solution provided by the application has the advantage of increasing the transmission speed.
  • Figure 1 is a schematic diagram of the hardware system structure in an embodiment of the application
  • FIG. 2 is a schematic diagram of a flow diagram of a method for implementing a USB serial port of a Linux system console in an embodiment of the application;
  • FIG. 3 is a schematic structural diagram of a terminal in an embodiment of the application.
  • Fig. 4 is a schematic structural diagram of a Linux hardware system in an embodiment of the application.
  • FIG 1 is a schematic diagram of a hardware system structure provided by this application.
  • the operating system of the host side device (which can be a personal computer or a server) can be windows or Linux, and the host side can include: CAC ACM or generic USB serial driver; it can also include expanded US host controller hardware module.
  • the gadget device side device may also be called the terminal side, the system running on the gadget device side may be embedded Linux, and the gadget device side device may include a gadget serial driver and a USB device controller hardware module.
  • the host-side device and the terminal-side device are connected through a USB cable, and the USB cable may be a universal USB data cable.
  • Figure 2 provides a method for implementing the USB serial port of the Linux system console. This method is implemented in the hardware system shown in Figure 1.
  • the host side device is determined to be PC (windows) here. Determine the device on the Gadget device side as the console terminal. As shown in Figure 2, the method includes the following steps:
  • Step S201 When the console terminal is started, the kernel is called to configure cmdline (kernel command line) as a multi-terminal startup, and the USB serial port is registered as a terminal;
  • cmdline kernel command line
  • the aforementioned USB serial port may be: a USB gadget serial port.
  • the foregoing implementation method of registering the USB serial port as a terminal may specifically include:
  • Step S202 When the console terminal detects that the USB cable is inserted, it sets the connection state of the USB cable to the connected state, and calls the function to adjust the state of the USB serial port to open;
  • the above calling function to adjust the status of the USB serial port to open may specifically include:
  • the console terminal calls the open function to adjust the status of the USB serial port to the open state.
  • the above-mentioned open function can be specifically: do_gs_open.
  • a close function needs to be set, specifically: do_gs_close, which is used to adjust the state of the USB serial port to the closed state.
  • Step S203 The PC starts the terminal application program, starts the first USB serial port corresponding to the USB serial port, and sets the state of the first USB serial port to the open state; sends the start action to the console terminal;
  • Step S204 The console terminal sets the status of the USB serial port to an open state, obtains printk information, and calls the write function of the console port to send the printk information and the data in the preset buffer area to the PC through the USB serial port;
  • the write function of the aforementioned console port may specifically include: do_gs_write.
  • Step S205 The PC receives the printk information and the data of the preset buffer area through the first USB serial port, and displays the printk information and the data of the preset buffer area.
  • the foregoing preset cache area may be 128k bytes in size, and the preset cache area is used to store the print information output by the kernel.
  • the technical solution provided by this application modifies the console terminal so that the console terminal can print (ie, transmit and display) printk information through the USB serial port. Since the transmission speed of the USB serial port is much faster than that of the ordinary serial port, this The technical solution provided by the application has the advantage of increasing the transmission speed.
  • do_gs_open, do_gs_write, and do_gs_close functions are shared with the open, write, and close functions in the file_operations of the USB tty serial port.
  • This setting can make the corresponding open/close operations interoperable between the terminal and tty file operations, and also make the code more cohesive.
  • the above method may also include:
  • the printk information is stored in the preset buffer area.
  • the first embodiment of the present application provides a method for implementing a USB serial port of a Linux system console.
  • the method is implemented in the hardware system as shown in FIG. 1.
  • the method may specifically include:
  • console terminal in the cmdline (kernel command line) of the kernel As a multi-terminal startup, including ordinary serial ports (RS232 serial ports) and USB gadget serial ports.
  • the gadget serial port has the highest priority.
  • the implementation process of the USB serial port implementation method of the Linux system console is as follows.
  • the USB serial port is registered as a terminal through the register_console function, and a ring buffer memory area is allocated in the terminal at this time.
  • the size of the buffer memory area can be 128K bytes.
  • the terminal calls the gserial_connect function to set the connection status of the USB cable to 1 (that is, the connection status), and the terminal calls the function of opening/closing the USB serial port;
  • the above open or close function can be operated through the work struct of the Linux kernel work queue.
  • the specific operation can be: open the USB serial port in the started work queue, and set the open state of the terminal console port to 1.
  • the gadget serial driver code of the embedded terminal device can receive this opening action (PC opening action), and the embedded terminal device sets the status of the USB serial port to the open state; next, when the embedded terminal device has printk information to be output , The embedded terminal device will call the write function of the console port, that is, the do_gs_write function can be used here to send all terminal print information to the PC through the USB serial port, including the content previously cached in the ring buffer memory area.
  • the Windows PC receives the printk information and the cached content and displays it.
  • the Windows PC peer end closes the serial port in the terminal application, such as Putty, SecureCRT, etc.
  • the Linux kernel printk information will be saved in the 128K byte ring buffer allocated by the driver.
  • the output printk information exceeds 128K bytes, the print information output by the previous kernel will be lost.
  • the USB serial line is unplugged next, it will trigger the execution of the task queue to open and close the serial port in the gserial_disconnect function that is called subsequently, call the do_gs_close function in the task queue to close the USB serial port, and set the USB line connection status and interrupt start The status is all 0.
  • do_gs_open, do_gs_write, do_gs_close functions are shared with the corresponding functions in the file_operations call of the USB tty serial port. Doing so can make the corresponding open/close operations interoperable between the terminal and the tty file operation, and also make the code more cohesive.
  • Fig. 3 provides a terminal, the terminal is an embedded Linux system, the terminal further includes a USB serial port, and the terminal further includes:
  • the startup unit is used to call the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup, and to register the USB serial port as a terminal;
  • the processing unit is used to set the connection status of the USB cable to the connected status when detecting that the USB cable is inserted, and call a function to adjust the status of the USB serial port to open; determine that the first USB serial port opposite to the USB serial port is open At this time, the console terminal sets the status of the USB serial port to the open state; obtains the printk information, and calls the write function of the console port to send the printk information and the data in the preset buffer area to the opposite device through the USB serial port.
  • the technical solution provided by this application modifies the console terminal so that the console terminal can print (ie, transmit and display) printk information through the USB serial port. Since the transmission speed of the USB serial port is much faster than that of the ordinary serial port, this The technical solution provided by the application has the advantage of increasing the transmission speed.
  • the processing unit is specifically configured to register the USB serial port as a terminal through the register_console function when the module_init is driven in the gadget serial driver code.
  • the processing unit is specifically configured to call an open function to adjust the state of the USB serial port to an open state.
  • the processing unit is further configured to determine that when the first USB serial port opposite to the USB serial port is closed, the console terminal caches the acquired printk information in the preset cache area.
  • Figure 4 provides a Linux hardware system.
  • the hardware Linux system includes: a peer device and a console terminal;
  • the console terminal is used to invoke the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup and register the USB serial port as a terminal; when the USB cable is detected, the connection status of the USB cable is set to the connected state and called The function adjusts the status of the USB serial port to open;
  • the opposite device is used to start the terminal application, start the first USB serial port corresponding to the USB serial port, and set the state of the first USB serial port to the open state; send the start action to the console terminal;
  • the console terminal is also used to determine that when the first USB serial port opposite to the USB serial port is opened, the console terminal sets the status of the USB serial port to the open state; obtains printk information, and calls the write function of the console port to set the printk information and presets The data in the buffer area is sent to the peer device through the USB serial port.
  • An embodiment of the present application also provides a computer storage medium, wherein the computer storage medium stores a computer program for electronic data exchange, and the computer program causes a computer to execute all or part of the method steps in FIG. 2.
  • the foregoing computer-readable storage medium may be the internal storage unit of the foregoing server in any of the foregoing embodiments, such as the hard disk or memory of the server.
  • the aforementioned computer-readable storage medium may also be an external storage device of the aforementioned server, such as a plug-in hard disk equipped on the aforementioned server, a Smart Media Card (SMC), a Secure Digital (SD) card, and a flash memory card. (Flash Card) and so on.
  • the above-mentioned computer-readable storage medium may also include both an internal storage unit of the above-mentioned server and an external storage device.
  • the aforementioned computer-readable storage medium is used to store the aforementioned computer program and other programs and data required by the aforementioned server.
  • the aforementioned computer-readable storage medium can also be used to temporarily store data that has been output or will be output.
  • the disclosed server and method may be implemented in other ways.
  • the terminal embodiments described above are merely illustrative.
  • the division of the above-mentioned units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components may be combined or may be Integrate into another system, or some features can be ignored or not implemented.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, terminals or units, and may also be electrical, mechanical or other forms of connection.
  • the units described above as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments of the present invention.
  • the functional units in the various embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated unit can be implemented in the form of hardware or software functional unit.
  • the above integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium.
  • the technical solution of the present invention is essentially or the part that contributes to the existing technology, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium.
  • several instructions are included to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the above-mentioned method in each embodiment of the present invention.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code .
  • U disk mobile hard disk
  • read-only memory Read-Only Memory
  • RAM random access memory
  • magnetic disk or optical disk and other media that can store program code .

Abstract

A USB serial port realization method for a Linux system console. The method comprises the following steps: when a console terminal is started, invoking a kernel to configure a kernel command line cmdline to be a multi-terminal start, and registering a USB serial port as a terminal; when the console terminal detects that a USB cable is inserted, configuring the connection state of the USB cable to be a connected state, and invoking a function to adjust the state of the USB serial port to be open; when it is determined that a first USB serial port at a peer end of the USB serial port is open, configuring the state of the USB serial port to be an open state; and the console terminal acquiring printk information, and invoking a write function of a console port to send the printk information and data in a preset cache region to a peer device by means of the USB serial port. The method has the advantage of a high transmission speed.

Description

Linux系统控制台的USB串口实现方法及相关产品Implementation method of USB serial port of Linux system console and related products 技术领域Technical field
本申请涉及软件领域,特别是一种Linux系统控制台的USB串口实现方法及相关产品。This application relates to the field of software, in particular to a method for implementing a USB serial port of a Linux system console and related products.
背景技术Background technique
嵌入式linux是将日益流行的Linux操作系统进行裁剪修改,使之能在嵌入式计算机系统上运行的一种操作系统。嵌入式linux既继承了Internet上无限的开放源代码资源,又具有嵌入式操作系统的特性。嵌入式Linux的特点是版权费免费,全世界的自由软件开发者提供支持,而且性能优异,软件移植容易,代码开放,有许多应用软件支持,应用产品开发周期短,新产品上市迅速,又有许多公开的代码可以参考和移植。Linux系统启动运行过程中所产生的信息会发送到终端上,console(控制台)是一个缓冲的概念,其实是为内核提供信息的打印;嵌入式Linux的终端一般都是使用uart串口。现有的uart串口的传输速度很慢,效率低。Embedded Linux is an operating system that tailors the increasingly popular Linux operating system to make it run on an embedded computer system. Embedded Linux not only inherits the unlimited open source code resources on the Internet, but also has the characteristics of an embedded operating system. Embedded Linux is characterized by free copyright fees, free software developers around the world to provide support, and excellent performance, easy software transplantation, open code, support for many application software, short application product development cycle, rapid launch of new products, and Many public codes can be referenced and transplanted. The information generated during the startup and operation of the Linux system will be sent to the terminal. The console (console) is a buffer concept, which actually provides information printing for the kernel; embedded Linux terminals generally use uart serial ports. The transmission speed of the existing uart serial port is very slow and low in efficiency.
发明内容Summary of the invention
为解决上述问题,本申请公开了一种Linux系统控制台的USB串口实现方法,可以实现通过USB串口实现内核信息的打印,提高了数据的传输速度,提高了效率。In order to solve the above problems, this application discloses a method for implementing a USB serial port of a Linux system console, which can realize the printing of kernel information through the USB serial port, which improves the data transmission speed and efficiency.
本申请实施例第一方面提供了一种Linux系统控制台的USB串口实现方法,所述方法包括如下步骤:The first aspect of the embodiments of the present application provides a method for implementing a USB serial port of a Linux system console. The method includes the following steps:
console终端在启动时,调用核kernel将内核命令行cmdline配置为多终端启动,将USB串口注册为终端;When the console terminal is started, call the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup, and register the USB serial port as a terminal;
console终端检测到USB线插入时,将USB线的连接状态设置成连接态,并调用函数将所述USB串口的状态调整至打开;When the console terminal detects that the USB cable is inserted, it sets the connection status of the USB cable to the connected status, and calls the function to adjust the status of the USB serial port to open;
console终端确定与所述USB串口对端的第一USB串口打开时,console 终端将该USB串口的状态设置成打开状态;When the console terminal determines that the first USB serial port opposite to the USB serial port is open, the console terminal sets the status of the USB serial port to an open state;
console终端获取printk信息,调用console口的write函数将printk信息以及预设缓存区域的数据通过该USB串口发送给对端设备。The console terminal obtains the printk information, and calls the write function of the console port to send the printk information and the data in the preset buffer area to the peer device through the USB serial port.
可选的,所述将USB串口注册为终端具体包括:Optionally, the registering the USB serial port as a terminal specifically includes:
在gadget serial驱动代码中驱动module_init时,通过register_console函数将该USB串口注册为终端。When driving module_init in the gadget serial driver code, register the USB serial port as a terminal through the register_console function.
可选的,所述调用函数将该USB串口的状态调整至打开具体包括:Optionally, the calling function to adjust the status of the USB serial port to open specifically includes:
console终端调用打开函数将USB串口的状态调整至打开状态。The console terminal calls the open function to adjust the status of the USB serial port to the open state.
可选的,所述方法还包括:Optionally, the method further includes:
console终端确定与所述USB串口对端的第一USB串口关闭时,console终端将获取的printk信息缓存于所述预设缓存区域。When the console terminal determines that the first USB serial port opposite to the USB serial port is closed, the console terminal caches the acquired printk information in the preset cache area.
第二方面,提供一种终端,所述终端为嵌入式Linux系统,所述终端还包括:USB串口,所述终端还包括:In a second aspect, a terminal is provided, the terminal is an embedded Linux system, the terminal further includes a USB serial port, and the terminal further includes:
启动单元,用于在启动时,调用核kernel将内核命令行cmdline配置为多终端启动,将USB串口注册为终端;The startup unit is used to call the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup, and to register the USB serial port as a terminal;
处理单元,用于检测到USB线插入时,将USB线的连接状态设置成连接态,并调用函数将所述USB串口的状态调整至打开;确定与所述USB串口对端的第一USB串口打开时,console终端将该USB串口的状态设置成打开状态;获取printk信息,调用console口的write函数将printk信息以及预设缓存区域的数据通过该USB串口发送给对端设备。The processing unit is used to set the connection status of the USB cable to the connected status when detecting that the USB cable is inserted, and call a function to adjust the status of the USB serial port to open; determine that the first USB serial port opposite to the USB serial port is open At this time, the console terminal sets the status of the USB serial port to the open state; obtains the printk information, and calls the write function of the console port to send the printk information and the data in the preset buffer area to the opposite device through the USB serial port.
可选的,所述处理单元,具体用于在gadget serial驱动代码中驱动module_init时,通过register_console函数将该USB串口注册为终端。Optionally, the processing unit is specifically configured to register the USB serial port as a terminal through the register_console function when the module_init is driven in the gadget serial driver code.
可选的,所述处理单元,具体用于调用打开函数将USB串口的状态调整至打开状态。Optionally, the processing unit is specifically configured to call an open function to adjust the state of the USB serial port to an open state.
可选的,所述处理单元,还用于确定与所述USB串口对端的第一USB串口关闭时,console终端将获取的printk信息缓存于所述预设缓存区域Optionally, the processing unit is further configured to determine that when the first USB serial port opposite to the USB serial port is closed, the console terminal caches the acquired printk information in the preset cache area
第三方面,提供一种Linux硬件系统,所述Linux硬件系统包括:对端设备和console终端;In a third aspect, a Linux hardware system is provided, and the Linux hardware system includes: a peer device and a console terminal;
console终端,用于在启动时,调用核kernel将内核命令行cmdline配置为多终端启动,将USB串口注册为终端;检测到USB线插入时,将USB线的连接状态设置成连接态,并调用函数将所述USB串口的状态调整至打开;The console terminal is used to invoke the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup and register the USB serial port as a terminal; when the USB cable is detected, the connection status of the USB cable is set to the connected state and called The function adjusts the status of the USB serial port to open;
对端设备,用于启动终端应用程序,启动与该USB串口对应的第一USB串口,并将第一USB串口状态置位成打开状态;将该启动动作发送至console终端;The opposite device is used to start the terminal application, start the first USB serial port corresponding to the USB serial port, and set the state of the first USB serial port to the open state; send the start action to the console terminal;
console终端,还用于确定与所述USB串口对端的第一USB串口打开时,console终端将该USB串口的状态设置成打开状态;获取printk信息,调用console口的write函数将printk信息以及预设缓存区域的数据通过该USB串口发送给对端设备。The console terminal is also used to determine that when the first USB serial port opposite to the USB serial port is opened, the console terminal sets the status of the USB serial port to the open state; obtains printk information, and calls the write function of the console port to set the printk information and presets The data in the buffer area is sent to the peer device through the USB serial port.
本申请实施例第四方面提供了一种计算机可读存储介质,所述计算机存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令当被处理器执行时使所述处理器执行本申请实施例第一方面所描述的方法。The fourth aspect of the embodiments of the present application provides a computer-readable storage medium that stores a computer program, and the computer program includes program instructions that, when executed by a processor, cause the processor to Perform the method described in the first aspect of the embodiments of the present application.
实施本申请实施例时,具有如下有益效果:When implementing the embodiments of this application, it has the following beneficial effects:
本申请提供的技术方案通过对console终端进行改动,使得该console终端能够通过USB串口实现对printk信息数据的打印(即传输显示),由于USB串口的传输速度比普通串口的速度快很多,因此本申请提供的技术方案具有提高传输速度的优点。The technical solution provided by this application modifies the console terminal so that the console terminal can print (ie, transmit and display) printk information through the USB serial port. Since the transmission speed of the USB serial port is much faster than that of the ordinary serial port, this The technical solution provided by the application has the advantage of increasing the transmission speed.
附图说明Description of the drawings
为了更清楚地说明本发明实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to explain the technical solutions of the embodiments of the present invention more clearly, the following will briefly introduce the drawings used in the description of the embodiments. Obviously, the drawings in the following description are some embodiments of the present invention. Ordinary technicians can obtain other drawings based on these drawings without creative work.
图1为本申请实施例中硬件系统结构示意图;Figure 1 is a schematic diagram of the hardware system structure in an embodiment of the application;
图2为本申请实施例中Linux系统控制台的USB串口实现方法流程示意图;FIG. 2 is a schematic diagram of a flow diagram of a method for implementing a USB serial port of a Linux system console in an embodiment of the application;
图3为本申请实施例中终端的结构示意图;FIG. 3 is a schematic structural diagram of a terminal in an embodiment of the application;
图4为本申请实施例中一种Linux硬件系统的结构示意图。Fig. 4 is a schematic structural diagram of a Linux hardware system in an embodiment of the application.
具体实施方式Detailed ways
为了使本技术领域的人员更好地理解本发明方案,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be described clearly and completely in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only These are a part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present invention.
本发明的说明书和权利要求书及上述附图中的术语“包括”和“具有”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元,或可选地还包括对于这些过程、产品或设备固有的其他步骤或单元。The terms "including" and "having" in the specification and claims of the present invention and the above-mentioned drawings and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally also includes Other steps or units inherent in a process, product, or equipment.
在本文中提及“实施例”意味着,结合实施例描述的特定特征、结构或特性可以包含在本发明的至少一个实施例中。在说明书中的各个位置出现该短语并不一定均是指相同的实施例,也不是与其它实施例互斥的独立的或备选的实施例。本领域技术人员显式地和隐式地理解的是,本文所描述的实施例可以与其它实施例相结合。Reference to "embodiments" herein means that a specific feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art clearly and implicitly understand that the embodiments described herein can be combined with other embodiments.
参阅图1,图1为本申请提供的一种硬件系统结构示意图,如图1所示,主机侧设备(可以为个人电脑或服务器)的操作系统可以为windows或Linux,主机侧可以包括:CAC ACM或generic USB serial驱动;还可以包括扩US主机控制器硬件模块。Gadget device侧设备也可以称为终端侧,该Gadget device侧运行的系统可以是嵌入式Linux,Gadget device侧设备可以包括:Gadget serial驱动和USB设备控制器硬件模块。主机侧设备与终端侧设备通过USB线连接,该USB线可以为通用的USB数据线。Refer to Figure 1. Figure 1 is a schematic diagram of a hardware system structure provided by this application. As shown in Figure 1, the operating system of the host side device (which can be a personal computer or a server) can be windows or Linux, and the host side can include: CAC ACM or generic USB serial driver; it can also include expanded US host controller hardware module. The gadget device side device may also be called the terminal side, the system running on the gadget device side may be embedded Linux, and the gadget device side device may include a gadget serial driver and a USB device controller hardware module. The host-side device and the terminal-side device are connected through a USB cable, and the USB cable may be a universal USB data cable.
参阅图2,图2提供了一种Linux系统控制台的USB串口实现方法,该方法在如图1所示的硬件系统中实现,为了方便描述,这里将主机侧设备确定为PC(windows),将Gadget device侧设备确定为console终端,该方法如图2所示,包括如下步骤:Refer to Figure 2. Figure 2 provides a method for implementing the USB serial port of the Linux system console. This method is implemented in the hardware system shown in Figure 1. For the convenience of description, the host side device is determined to be PC (windows) here. Determine the device on the Gadget device side as the console terminal. As shown in Figure 2, the method includes the following steps:
步骤S201、console终端在启动时,调用kernel将cmdline(内核命令行) 配置为多终端启动,将USB串口注册为终端;Step S201: When the console terminal is started, the kernel is called to configure cmdline (kernel command line) as a multi-terminal startup, and the USB serial port is registered as a terminal;
上述USB串口可以为:USB gadget串口。The aforementioned USB serial port may be: a USB gadget serial port.
可选的,上述将USB串口注册为终端的实现方法具体可以包括:Optionally, the foregoing implementation method of registering the USB serial port as a terminal may specifically include:
在gadget serial驱动代码中驱动module_init时,通过register_console函数将该USB串口注册为终端。When driving module_init in the gadget serial driver code, register the USB serial port as a terminal through the register_console function.
步骤S202、console终端检测到USB线插入时,将USB线的连接状态设置成连接态,并调用函数将该USB串口的状态调整至打开;Step S202: When the console terminal detects that the USB cable is inserted, it sets the connection state of the USB cable to the connected state, and calls the function to adjust the state of the USB serial port to open;
上述调用函数将该USB串口的状态调整至打开具体可以包括:The above calling function to adjust the status of the USB serial port to open may specifically include:
console终端调用打开函数将USB串口的状态调整至打开状态。上述打开函数具体可以为:do_gs_open。当然在实际应用中,还需要设置关闭函数,具体为:do_gs_close,该关闭函数用于将USB串口的状态调整至关闭状态。The console terminal calls the open function to adjust the status of the USB serial port to the open state. The above-mentioned open function can be specifically: do_gs_open. Of course, in practical applications, a close function needs to be set, specifically: do_gs_close, which is used to adjust the state of the USB serial port to the closed state.
步骤S203、PC启动终端应用程序,启动与该USB串口对应的第一USB串口,并将第一USB串口状态置位成打开状态;将该启动动作发送至console终端;Step S203: The PC starts the terminal application program, starts the first USB serial port corresponding to the USB serial port, and sets the state of the first USB serial port to the open state; sends the start action to the console terminal;
步骤S204、console终端将该USB串口的状态设置成打开状态,获取printk信息,调用console口的write函数将printk信息以及预设缓存区域的数据通过该USB串口发送给PC;Step S204: The console terminal sets the status of the USB serial port to an open state, obtains printk information, and calls the write function of the console port to send the printk information and the data in the preset buffer area to the PC through the USB serial port;
可选的,上述console口的write函数具体可以包括:do_gs_write。Optionally, the write function of the aforementioned console port may specifically include: do_gs_write.
步骤S205、PC通过第一USB串口接收该printk信息以及预设缓存区域的数据,显示该printk信息以及预设缓存区域的数据。Step S205: The PC receives the printk information and the data of the preset buffer area through the first USB serial port, and displays the printk information and the data of the preset buffer area.
上述预设缓存区域可以为128k字节大小,所述预设缓存区域用于存储内核输出打印信息。The foregoing preset cache area may be 128k bytes in size, and the preset cache area is used to store the print information output by the kernel.
本申请提供的技术方案通过对console终端进行改动,使得该console终端能够通过USB串口实现对printk信息数据的打印(即传输显示),由于USB串口的传输速度比普通串口的速度快很多,因此本申请提供的技术方案具有提高传输速度的优点。The technical solution provided by this application modifies the console terminal so that the console terminal can print (ie, transmit and display) printk information through the USB serial port. Since the transmission speed of the USB serial port is much faster than that of the ordinary serial port, this The technical solution provided by the application has the advantage of increasing the transmission speed.
可选的,上述do_gs_open、do_gs_write、do_gs_close函数均与USB tty串口的file_operations中打开、写入、关闭函数共用。此设置这样做可以使得 对应的打开/关闭等操作在终端和tty文件操作之间是互通的,并且也使得代码的内聚性更高。Optionally, the aforementioned do_gs_open, do_gs_write, and do_gs_close functions are shared with the open, write, and close functions in the file_operations of the USB tty serial port. This setting can make the corresponding open/close operations interoperable between the terminal and tty file operations, and also make the code more cohesive.
上述方法还可以包括:The above method may also include:
如果第一USB串口为关闭状态,则将该printk信息存储至预设缓存区域。If the first USB serial port is in the closed state, the printk information is stored in the preset buffer area.
实施例一Example one
本申请实施例一提供了一种Linux系统控制台的USB串口实现方法,该方法在如图1所示的硬件系统中实现,该方法具体可以包括:The first embodiment of the present application provides a method for implementing a USB serial port of a Linux system console. The method is implemented in the hardware system as shown in FIG. 1. The method may specifically include:
系统启动的时候在kernel(核)的cmdline(内核命令行)配置console终端为多终端启动,包括普通的串口(RS232串口)和USB gadget串口,其中gadget串口的优先级是最高的。When the system is started, configure the console terminal in the cmdline (kernel command line) of the kernel as a multi-terminal startup, including ordinary serial ports (RS232 serial ports) and USB gadget serial ports. The gadget serial port has the highest priority.
Linux系统控制台的USB串口实现方法的实现过程是这样的,在gadget serial驱动代码中驱动module_init的时候通过register_console函数将USB串口注册为终端,并在此时在终端分配一个环形缓冲内存区,该缓冲内存区的空间大小可以为128K字节。接下来当USB线插入终端的时候,终端调用gserial_connect函数,将USB线的连接状态设置为1(即连接状态),终端调用USB串口打开/关闭的函数;The implementation process of the USB serial port implementation method of the Linux system console is as follows. When the module_init is driven in the gadget serial driver code, the USB serial port is registered as a terminal through the register_console function, and a ring buffer memory area is allocated in the terminal at this time. The size of the buffer memory area can be 128K bytes. Next, when the USB cable is inserted into the terminal, the terminal calls the gserial_connect function to set the connection status of the USB cable to 1 (that is, the connection status), and the terminal calls the function of opening/closing the USB serial port;
上述打开或关闭函数可以通过Linux内核工作队列work struct来操作。具体操作可以为:在该启动的工作队列中将USB串口打开,并置终端console口的打开状态为1。The above open or close function can be operated through the work struct of the Linux kernel work queue. The specific operation can be: open the USB serial port in the started work queue, and set the open state of the terminal console port to 1.
如果接下来使用Windows PC通过USB线连接到USB串口终端设备,启动PC端的终端应用程序(比如Putty、SecureCRT等等),并且启动与USB串口对应的第一USB串口,打开第一USB串口,嵌入式终端设备的gadget serial驱动代码就能接收到这个打开动作(PC打开动作),嵌入式终端设备将USB串口的状态置位成打开状态;接下来当嵌入式终端设备有printk信息要输出的时候,嵌入式终端设备就会调用console口的write函数,即这里可以采用do_gs_write函数将所有的终端打印信息都通过USB串口发送给PC,包括之前缓存在环形缓冲内存区的内容。Windows PC接收到printk信息以及缓存的内容并显示出来。If you use Windows PC to connect to the USB serial port terminal device through the USB cable, start the terminal application on the PC side (such as Putty, SecureCRT, etc.), and start the first USB serial port corresponding to the USB serial port, open the first USB serial port, and embed The gadget serial driver code of the embedded terminal device can receive this opening action (PC opening action), and the embedded terminal device sets the status of the USB serial port to the open state; next, when the embedded terminal device has printk information to be output , The embedded terminal device will call the write function of the console port, that is, the do_gs_write function can be used here to send all terminal print information to the PC through the USB serial port, including the content previously cached in the ring buffer memory area. The Windows PC receives the printk information and the cached content and displays it.
如果Windows PC对端在终端应用程序,比如Putty、SecureCRT等中将串口关闭。这时Linux内核printk信息会在驱动分配的128K字节的环形缓冲区中保存下来。另外如果输出的printk信息超过了128K字节,那么前面内核输出的打印信息将会丢失掉。如果接下来再将USB串口线拔掉,则会在随后调用的gserial_disconnect函数中触发打开关闭串口的任务队列执行,在任务队列中调用do_gs_close函数将USB串口关闭,并置USB线连接状态和中断启动状态都为0。If the Windows PC peer end closes the serial port in the terminal application, such as Putty, SecureCRT, etc. At this time, the Linux kernel printk information will be saved in the 128K byte ring buffer allocated by the driver. In addition, if the output printk information exceeds 128K bytes, the print information output by the previous kernel will be lost. If the USB serial line is unplugged next, it will trigger the execution of the task queue to open and close the serial port in the gserial_disconnect function that is called subsequently, call the do_gs_close function in the task queue to close the USB serial port, and set the USB line connection status and interrupt start The status is all 0.
在这里do_gs_open、do_gs_write、do_gs_close函数,都是和USB tty串口的file_operations调用中相应的函数共用的。这样做可以使得对应的打开/关闭等操作在终端和tty文件操作之间是互通的,并且也使得代码的内聚性更高。Here do_gs_open, do_gs_write, do_gs_close functions are shared with the corresponding functions in the file_operations call of the USB tty serial port. Doing so can make the corresponding open/close operations interoperable between the terminal and the tty file operation, and also make the code more cohesive.
参阅图3,图3提供一种终端,所述终端为嵌入式Linux系统,所述终端还包括:USB串口,所述终端还包括:Referring to Fig. 3, Fig. 3 provides a terminal, the terminal is an embedded Linux system, the terminal further includes a USB serial port, and the terminal further includes:
启动单元,用于在启动时,调用核kernel将内核命令行cmdline配置为多终端启动,将USB串口注册为终端;The startup unit is used to call the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup, and to register the USB serial port as a terminal;
处理单元,用于检测到USB线插入时,将USB线的连接状态设置成连接态,并调用函数将所述USB串口的状态调整至打开;确定与所述USB串口对端的第一USB串口打开时,console终端将该USB串口的状态设置成打开状态;获取printk信息,调用console口的write函数将printk信息以及预设缓存区域的数据通过该USB串口发送给对端设备。The processing unit is used to set the connection status of the USB cable to the connected status when detecting that the USB cable is inserted, and call a function to adjust the status of the USB serial port to open; determine that the first USB serial port opposite to the USB serial port is open At this time, the console terminal sets the status of the USB serial port to the open state; obtains the printk information, and calls the write function of the console port to send the printk information and the data in the preset buffer area to the opposite device through the USB serial port.
本申请提供的技术方案通过对console终端进行改动,使得该console终端能够通过USB串口实现对printk信息数据的打印(即传输显示),由于USB串口的传输速度比普通串口的速度快很多,因此本申请提供的技术方案具有提高传输速度的优点。The technical solution provided by this application modifies the console terminal so that the console terminal can print (ie, transmit and display) printk information through the USB serial port. Since the transmission speed of the USB serial port is much faster than that of the ordinary serial port, this The technical solution provided by the application has the advantage of increasing the transmission speed.
可选的,所述处理单元,具体用于在gadget serial驱动代码中驱动module_init时,通过register_console函数将该USB串口注册为终端。Optionally, the processing unit is specifically configured to register the USB serial port as a terminal through the register_console function when the module_init is driven in the gadget serial driver code.
可选的,所述处理单元,具体用于调用打开函数将USB串口的状态调整至打开状态。Optionally, the processing unit is specifically configured to call an open function to adjust the state of the USB serial port to an open state.
可选的,所述处理单元,还用于确定与所述USB串口对端的第一USB串口关闭时,console终端将获取的printk信息缓存于所述预设缓存区域。Optionally, the processing unit is further configured to determine that when the first USB serial port opposite to the USB serial port is closed, the console terminal caches the acquired printk information in the preset cache area.
参阅图4,图4提供一种Linux硬件系统,所述硬件Linux系统包括:对端设备和console终端;Referring to Figure 4, Figure 4 provides a Linux hardware system. The hardware Linux system includes: a peer device and a console terminal;
console终端,用于在启动时,调用核kernel将内核命令行cmdline配置为多终端启动,将USB串口注册为终端;检测到USB线插入时,将USB线的连接状态设置成连接态,并调用函数将所述USB串口的状态调整至打开;The console terminal is used to invoke the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup and register the USB serial port as a terminal; when the USB cable is detected, the connection status of the USB cable is set to the connected state and called The function adjusts the status of the USB serial port to open;
对端设备,用于启动终端应用程序,启动与该USB串口对应的第一USB串口,并将第一USB串口状态置位成打开状态;将该启动动作发送至console终端;The opposite device is used to start the terminal application, start the first USB serial port corresponding to the USB serial port, and set the state of the first USB serial port to the open state; send the start action to the console terminal;
console终端,还用于确定与所述USB串口对端的第一USB串口打开时,console终端将该USB串口的状态设置成打开状态;获取printk信息,调用console口的write函数将printk信息以及预设缓存区域的数据通过该USB串口发送给对端设备。The console terminal is also used to determine that when the first USB serial port opposite to the USB serial port is opened, the console terminal sets the status of the USB serial port to the open state; obtains printk information, and calls the write function of the console port to set the printk information and presets The data in the buffer area is sent to the peer device through the USB serial port.
本申请实施例还提供一种计算机存储介质,其中,该计算机存储介质存储用于电子数据交换的计算机程序,该计算机程序使得计算机执行图2的全部或部分方法步骤。An embodiment of the present application also provides a computer storage medium, wherein the computer storage medium stores a computer program for electronic data exchange, and the computer program causes a computer to execute all or part of the method steps in FIG. 2.
上述计算机可读存储介质可以是前述任一实施例上述的服务器的内部存储单元,例如服务器的硬盘或内存。上述计算机可读存储介质也可以是上述服务器的外部存储设备,例如上述服务器上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,上述计算机可读存储介质还可以既包括上述服务器的内部存储单元也包括外部存储设备。上述计算机可读存储介质用于存储上述计算机程序以及上述服务器所需的其他程序和数据。上述计算机可读存储介质还可以用于暂时地存储已经输出或者将要输出的数据。The foregoing computer-readable storage medium may be the internal storage unit of the foregoing server in any of the foregoing embodiments, such as the hard disk or memory of the server. The aforementioned computer-readable storage medium may also be an external storage device of the aforementioned server, such as a plug-in hard disk equipped on the aforementioned server, a Smart Media Card (SMC), a Secure Digital (SD) card, and a flash memory card. (Flash Card) and so on. Further, the above-mentioned computer-readable storage medium may also include both an internal storage unit of the above-mentioned server and an external storage device. The aforementioned computer-readable storage medium is used to store the aforementioned computer program and other programs and data required by the aforementioned server. The aforementioned computer-readable storage medium can also be used to temporarily store data that has been output or will be output.
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一 般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。A person of ordinary skill in the art may be aware that the units and algorithm steps of the examples described in the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both, in order to clearly illustrate the hardware and software Interchangeability, in the above description, the composition and steps of each example have been generally described in accordance with the function. Whether these functions are executed by hardware or software depends on the specific application and design constraint conditions of the technical solution. Professionals and technicians can use different methods for each specific application to implement the described functions, but such implementation should not be considered as going beyond the scope of the present invention.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的服务器和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and conciseness of description, the specific working process of the server and unit described above can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
在本申请所提供的几个实施例中,应该理解到,所揭露的服务器和方法,可以通过其它的方式实现。例如,以上所描述的终端实施例仅仅是示意性的,例如,上述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口、终端或单元的间接耦合或通信连接,也可以是电的,机械的或其它的形式连接。In the several embodiments provided in this application, it should be understood that the disclosed server and method may be implemented in other ways. For example, the terminal embodiments described above are merely illustrative. For example, the division of the above-mentioned units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components may be combined or may be Integrate into another system, or some features can be ignored or not implemented. In addition, the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, terminals or units, and may also be electrical, mechanical or other forms of connection.
上述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本发明实施例方案的目的。The units described above as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments of the present invention.
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以是两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, the functional units in the various embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or software functional unit.
上述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分,或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例上述方法的全部或部分步 骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。If the above integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the existing technology, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium. Among them, several instructions are included to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the above-mentioned method in each embodiment of the present invention. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code . In the above-mentioned embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in an embodiment, reference may be made to related descriptions of other embodiments.

Claims (10)

  1. 一种Linux系统控制台的USB串口实现方法,其特征在于,所述方法包括如下步骤:A method for implementing a USB serial port of a Linux system console is characterized in that the method includes the following steps:
    console终端在启动时,调用核kernel将内核命令行cmdline配置为多终端启动,将USB串口注册为终端;When the console terminal is started, call the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup, and register the USB serial port as a terminal;
    console终端检测到USB线插入时,将USB线的连接状态设置成连接态,并调用函数将所述USB串口的状态调整至打开;When the console terminal detects that the USB cable is inserted, it sets the connection status of the USB cable to the connected status, and calls the function to adjust the status of the USB serial port to open;
    console终端确定与所述USB串口对端的第一USB串口打开时,console终端将该USB串口的状态设置成打开状态;When the console terminal determines that the first USB serial port opposite to the USB serial port is open, the console terminal sets the status of the USB serial port to an open state;
    console终端获取打印printk信息,调用console口的write函数将printk信息以及预设缓存区域的数据通过该USB串口发送给对端设备。The console terminal obtains and prints printk information, and calls the write function of the console port to send the printk information and the data in the preset buffer area to the opposite device through the USB serial port.
  2. 根据权利要求1所述的方法,其特征在于,所述将USB串口注册为终端具体包括:The method according to claim 1, wherein the registering the USB serial port as a terminal specifically comprises:
    在gadget serial驱动代码中驱动module_init时,通过register_console函数将该USB串口注册为终端。When driving module_init in the gadget serial driver code, register the USB serial port as a terminal through the register_console function.
  3. 根据权利要求1所述的方法,其特征在于,所述调用函数将该USB串口的状态调整至打开具体包括:The method according to claim 1, wherein the calling function to adjust the status of the USB serial port to open specifically comprises:
    console终端调用打开函数将USB串口的状态调整至打开状态。The console terminal calls the open function to adjust the status of the USB serial port to the open state.
  4. 根据权利要求1所述的方法,其特征在于,所述方法还包括:The method according to claim 1, wherein the method further comprises:
    console终端确定与所述USB串口对端的第一USB串口关闭时,console终端将获取的printk信息缓存于所述预设缓存区域。When the console terminal determines that the first USB serial port opposite to the USB serial port is closed, the console terminal caches the acquired printk information in the preset cache area.
  5. 一种终端,所述终端为嵌入式Linux系统,所述终端还包括:USB串口,其特征在于,所述终端还包括:A terminal, the terminal is an embedded Linux system, the terminal further includes: a USB serial port, characterized in that the terminal further includes:
    启动单元,用于在启动时,调用核kernel将内核命令行cmdline配置为多终端启动,将USB串口注册为终端;The startup unit is used to call the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup, and to register the USB serial port as a terminal;
    处理单元,用于检测到USB线插入时,将USB线的连接状态设置成连接态,并调用函数将所述USB串口的状态调整至打开;确定与所述USB串口对端的第一USB串口打开时,console终端将该USB串口的状态设置成打开状态;获取printk信息,调用console口的write函数将printk信息以及预设缓存区域的数据通过该USB串口发送给对端设备。The processing unit is used to set the connection status of the USB cable to the connected status when detecting that the USB cable is inserted, and call a function to adjust the status of the USB serial port to open; determine that the first USB serial port opposite to the USB serial port is open At this time, the console terminal sets the status of the USB serial port to the open state; obtains the printk information, and calls the write function of the console port to send the printk information and the data in the preset buffer area to the opposite device through the USB serial port.
  6. 根据权利要求5所述的终端,其特征在于,The terminal according to claim 5, wherein:
    所述处理单元,具体用于在gadget serial驱动代码中驱动module_init时,通过register_console函数将该USB串口注册为终端。The processing unit is specifically configured to register the USB serial port as a terminal through the register_console function when the module_init is driven in the gadget serial driver code.
  7. 根据权利要求5所述的终端,其特征在于,The terminal according to claim 5, wherein:
    所述处理单元,具体用于调用打开函数将USB串口的状态调整至打开状态。The processing unit is specifically configured to call an open function to adjust the state of the USB serial port to an open state.
  8. 根据权利要求5所述的终端,其特征在于,The terminal according to claim 5, wherein:
    所述处理单元,还用于确定与所述USB串口对端的第一USB串口关闭时,console终端将获取的printk信息缓存于所述预设缓存区域。The processing unit is further configured to determine that when the first USB serial port opposite to the USB serial port is closed, the console terminal buffers the acquired printk information in the preset buffer area.
  9. 一种Linux硬件系统,其特征在于,所述Linux硬件系统包括:对端设备和console终端;A Linux hardware system, characterized in that the Linux hardware system includes: a peer device and a console terminal;
    console终端,用于在启动时,调用核kernel将内核命令行cmdline配置为多终端启动,将USB串口注册为终端;检测到USB线插入时,将USB线的连接状态设置成连接态,并调用函数将所述USB串口的状态调整至打开;The console terminal is used to invoke the kernel kernel to configure the kernel command line cmdline as a multi-terminal startup and register the USB serial port as a terminal; when the USB cable is detected, the connection status of the USB cable is set to the connected state and called The function adjusts the status of the USB serial port to open;
    对端设备,用于启动终端应用程序,启动与该USB串口对应的第一USB串口,并将第一USB串口状态置位成打开状态;将该启动动作发送至console终端;The opposite device is used to start the terminal application, start the first USB serial port corresponding to the USB serial port, and set the state of the first USB serial port to the open state; send the start action to the console terminal;
    console终端,还用于确定与所述USB串口对端的第一USB串口打开时,console终端将该USB串口的状态设置成打开状态;获取printk信息,调用 console口的write函数将printk信息以及预设缓存区域的数据通过该USB串口发送给对端设备。The console terminal is also used to determine that when the first USB serial port opposite to the USB serial port is opened, the console terminal sets the status of the USB serial port to the open state; obtains printk information, and calls the write function of the console port to set the printk information and presets The data in the buffer area is sent to the peer device through the USB serial port.
  10. 一种计算机可读存储介质,其特征在于,所述计算机存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令当被处理器执行时使所述处理器执行如权利要求1~4任一项所述的方法。A computer-readable storage medium, wherein the computer storage medium stores a computer program, the computer program includes program instructions, and when executed by a processor, the program instructions cause the processor to execute as claimed in claim 1. The method of any one of ~4.
PCT/CN2020/129511 2019-12-18 2020-11-17 Usb serial port realization method for linux system console, and related product WO2021120960A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911311533.0A CN111045977B (en) 2019-12-18 2019-12-18 USB serial port implementation method of Linux system console and related product
CN201911311533.0 2019-12-18

Publications (1)

Publication Number Publication Date
WO2021120960A1 true WO2021120960A1 (en) 2021-06-24

Family

ID=70237615

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/129511 WO2021120960A1 (en) 2019-12-18 2020-11-17 Usb serial port realization method for linux system console, and related product

Country Status (2)

Country Link
CN (1) CN111045977B (en)
WO (1) WO2021120960A1 (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110175139B (en) * 2019-05-08 2021-01-05 厦门亿联网络技术股份有限公司 Universal debugging method for USB (Universal Serial bus) equipment and USB equipment
CN111045977B (en) * 2019-12-18 2021-07-27 深圳先进技术研究院 USB serial port implementation method of Linux system console and related product
CN112948311B (en) * 2021-03-30 2022-11-08 几维通信技术(深圳)有限公司 Serial port information interception method in Linux system
CN113961495A (en) * 2021-10-21 2022-01-21 青岛海信宽带多媒体技术有限公司 Method for disabling serial port function of Linux system

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080005375A1 (en) * 2006-05-07 2008-01-03 Quanta Computer Inc. Method for controlling USB device between incompatible processing platforms
CN105278927A (en) * 2014-06-11 2016-01-27 中兴通讯股份有限公司 Printing message obtaining method and printing message obtaining device
CN109344107A (en) * 2018-08-21 2019-02-15 深圳市科陆电子科技股份有限公司 A kind of method and apparatus of linux system console setting
CN111045977A (en) * 2019-12-18 2020-04-21 深圳先进技术研究院 USB serial port implementation method of Linux system console and related product

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101673218B (en) * 2009-10-15 2014-09-10 中兴通讯股份有限公司 Method and system for acquiring Linux kernel information
CN103577308B (en) * 2013-11-15 2017-01-18 惠州Tcl移动通信有限公司 Method for obtaining log files of mobile device
CN109460310B (en) * 2018-10-09 2022-03-08 普联技术有限公司 Information collection system, method, equipment and storage medium based on WEB interface

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080005375A1 (en) * 2006-05-07 2008-01-03 Quanta Computer Inc. Method for controlling USB device between incompatible processing platforms
CN105278927A (en) * 2014-06-11 2016-01-27 中兴通讯股份有限公司 Printing message obtaining method and printing message obtaining device
CN109344107A (en) * 2018-08-21 2019-02-15 深圳市科陆电子科技股份有限公司 A kind of method and apparatus of linux system console setting
CN111045977A (en) * 2019-12-18 2020-04-21 深圳先进技术研究院 USB serial port implementation method of Linux system console and related product

Also Published As

Publication number Publication date
CN111045977B (en) 2021-07-27
CN111045977A (en) 2020-04-21

Similar Documents

Publication Publication Date Title
WO2021120960A1 (en) Usb serial port realization method for linux system console, and related product
EP1591891A2 (en) Generic USB drivers
KR101620655B1 (en) Loading operating systems using memory segmentation and acpi based context switch
US8694695B2 (en) System and method for remotely operating a wireless device using a server and client architecture
US6128731A (en) Advanced boot sequence for an +86 computer system that maintains expansion card device compatibility
US9081709B2 (en) Virtualizable and forward-compatible hardware-software interface
WO2021013243A1 (en) Method for starting mini program, device, and computer storage medium
US8813071B2 (en) Storage reclamation systems and methods
JP4117193B2 (en) How to enable a port on a computing device
US20120124595A1 (en) Method and program for selective suspension of usb network device
US6357003B1 (en) Advanced firmware boot sequence x86 computer system that maintains legacy hardware and software compatibility
US8973019B1 (en) Method and system for emulation of super speed devices in virtual machines
CN111857961A (en) Display card transparent transmission method, virtual desktop management system and computer equipment
JP2001519060A (en) Controllerless modem
CN110175139B (en) Universal debugging method for USB (Universal Serial bus) equipment and USB equipment
CN116302006A (en) Thermal upgrade method of simulator and related device
US9087031B2 (en) Method and program for selective suspension of USB device
CN108932142A (en) A kind of picture catching method and terminal
CN112416521A (en) Serial port virtualization implementation method based on linux tty subsystem
CN116841773B (en) Data interaction method and device, electronic equipment and storage medium
JP2003330873A (en) Information processor, input output method, and program
US11422963B2 (en) System and method to handle uncompressible data with a compression accelerator
CN117294697A (en) USB device redirection method, device, network device and medium
WO2021081730A1 (en) Direct memory access control method, system, computer apparatus, and storage medium
CN117555650A (en) Method and device for communication between virtual machines, electronic equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20901325

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20901325

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 12/01/2023)

122 Ep: pct application non-entry in european phase

Ref document number: 20901325

Country of ref document: EP

Kind code of ref document: A1