Disclosure of Invention
In order to solve the problems, the application discloses a method for realizing the USB serial port of the Linux system console, which can realize the printing of kernel information through the USB serial port, improve the transmission speed of data and improve the 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, where the method includes the following steps:
when the console terminal is started, calling a kernel to configure the kernel command line cmdlene into multi-terminal starting, and registering the USB serial port as a terminal;
when the Console terminal detects that the USB wire is inserted, the connection state of the USB wire is set to be a connection state, and a function is called to adjust the state of the USB serial port to be opened;
when the console terminal determines that a first USB serial port at the opposite end of the USB serial port is opened, the console terminal sets the state of the USB serial port to be an open state;
and the Console terminal acquires the printk information, calls the write function of the Console port and sends the printk information and the data of the preset cache area to the opposite terminal equipment through the USB serial port.
Optionally, registering the USB serial port as the terminal specifically includes:
when the module _ init is driven in the gadget serial driver code, the USB serial port is registered as a terminal through a register _ console function.
Optionally, the adjusting the state of the USB serial port to be opened by the calling function specifically includes:
and the console terminal calls an opening function to adjust the state of the USB serial port to an opening state.
Optionally, the method further includes:
and when the console terminal determines that the first USB serial port of the USB serial port opposite terminal is closed, the console terminal caches the acquired printk information in the preset cache area.
In a second aspect, a terminal is provided, where the terminal is an embedded Linux system, and the terminal further includes: USB serial ports, the terminal still includes:
the starting unit is used for calling the kernel to configure the kernel command line cmdlene into multi-terminal starting and register the USB serial port as a terminal when the starting unit is started;
the processing unit is used for setting the connection state of the USB line into a connection state when detecting that the USB line is inserted, and calling a function to adjust the state of the USB serial port to be opened; when the first USB serial port of the opposite end of the USB serial port is determined to be opened, the console terminal sets the state of the USB serial port to be an open state; and acquiring the printk information, calling a write function of the console port, and sending the printk information and the data of the preset cache area to the opposite terminal equipment through the USB serial port.
Optionally, the processing unit is specifically configured to register the USB serial port as the terminal through a register _ console function when the module _ init is driven in the gadget serial driver code.
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.
Optionally, the processing unit is further configured to, when determining that the first USB serial port of the USB serial port opposite end is closed, cache, by the container terminal, the acquired printk information in the preset cache area
In a third aspect, a Linux hardware system is provided, where the Linux hardware system includes: the system comprises opposite terminal equipment and a console terminal;
the console terminal is used for calling the kernel to configure the kernel command line cmdlene into multi-terminal starting and register the USB serial port as a terminal when the console terminal is started; when the USB cable is detected to be inserted, setting the connection state of the USB cable into a connection state, and calling a function to adjust the state of the USB serial port to be opened;
the opposite terminal equipment is used for starting a terminal application program, starting a first USB serial port corresponding to the USB serial port and setting the state of the first USB serial port into an open state; sending the starting action to the console terminal;
the console terminal is also used for setting the state of the USB serial port to be an open state when the first USB serial port of the USB serial port opposite end is determined to be open; and acquiring the printk information, calling a write function of the console port, and sending the printk information and the data of the preset cache area to the opposite terminal equipment through the USB serial port.
A fourth aspect of embodiments of the present application provides a computer-readable storage medium, in which a computer program is stored, the computer program comprising program instructions that, when executed by a processor, cause the processor to perform the method described in the first aspect of embodiments of the present application.
When the embodiment of the application is implemented, the following beneficial effects are achieved:
the technical scheme who this application provided changes through the Console terminal for this Console terminal can realize printing (transmission shows promptly) to printk information data through the USB serial ports, because the transmission speed of USB serial ports is very much fast than the speed of ordinary serial ports, consequently the technical scheme who this application provided has the advantage that improves transmission speed.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terms "including" and "having," and any variations thereof, in the description and claims of this invention and the above-described drawings are intended to cover non-exclusive inclusions. For example, a process, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements but may alternatively include other steps or elements not expressly listed or inherent to such process, system, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the invention. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
Referring to fig. 1, fig. 1 is a schematic diagram of a hardware system structure provided in the present application, as shown in fig. 1, an operating system of a host-side device (which may be a personal computer or a server) may be windows or Linux, and the host side may include: CDC ACM or generic USB serial drive; and the USB host controller hardware module can be further included. The device at the Gadget device side may also be referred to as a terminal side, the system operated by the Gadget device side may be embedded Linux, and the device at the Gadget device side may include: the device comprises a Gadget serial driver and a USB device controller hardware module. The host side device and the terminal side device are connected by a USB cable, which may be a universal USB data cable.
Referring to fig. 2, fig. 2 provides a method for implementing a USB serial port of a Linux system console, where the method is implemented in a hardware system shown in fig. 1, and for convenience of description, a host side device is determined as a pc (windows), and a Gadget device is determined as a console terminal, where the method is shown in fig. 2 and includes the following steps:
step S201, when the console terminal is started, calling a kernel to configure cmdlene (kernel command line) into multi-terminal starting, and registering a USB serial port as a terminal;
the USB serial port can be as follows: and a USB gadget serial port.
Optionally, the implementation method for registering the USB serial port as the terminal may specifically include:
when the module _ init is driven in the gadget serial driver code, the USB serial port is registered as a terminal through a register _ console function.
Step S202, when the Console terminal detects that the USB wire is inserted, the connection state of the USB wire is set to be a connection state, and a function is called to adjust the state of the USB serial port to be opened;
the adjusting the state of the USB serial port to be opened by the calling function may specifically include:
and the console terminal calls an opening function to adjust the state of the USB serial port to an opening state. The opening function may specifically be: do _ gs _ open. Certainly, in practical application, a shutdown function needs to be set, specifically: and do _ gs _ close, wherein the close function is used for adjusting the state of the USB serial port to be in a closed state.
Step S203, the PC starts a terminal application program, starts a first USB serial port corresponding to the USB serial port, and sets the state of the first USB serial port to be in an open state; sending the starting action to the console terminal;
step S204, the console terminal sets the state of the USB serial port to be an open state, acquires the printk information, and calls the write function of the console port to send the printk information and the data of the preset cache area to the PC through the USB serial port;
optionally, the write function of the 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 preset cache area may be 128 kbytes in size, and the preset cache area is used for storing the kernel output printing information.
The technical scheme who this application provided changes through the Console terminal for this Console terminal can realize printing (transmission shows promptly) to printk information data through the USB serial ports, because the transmission speed of USB serial ports is very much fast than the speed of ordinary serial ports, consequently the technical scheme who this application provided has the advantage that improves transmission speed.
Optionally, the do _ gs _ open, do _ gs _ write, and do _ gs _ close functions are all shared with the open, write, and close functions in the file _ operations of the USB tty serial port. This arrangement can make the corresponding opening/closing operations intercommunicate between the terminal and the tty file operation, and also make the cohesion of the code higher.
The above method may further comprise:
and if the first USB serial port is in a closed state, storing the printk information into a preset cache region.
Example one
An embodiment of the present application provides a method for implementing a USB serial port of a Linux system console, where the method is implemented in a hardware system shown in fig. 1, and the method may specifically include:
when the system is started, a console terminal is configured in a cmdlene (kernel command line) of a kernel to start a multi-terminal, and the console terminal comprises a common serial port (RS232 serial port) and a USB gadget serial port, wherein the priority of the gadget serial port is the highest.
The implementation process of the USB serial port implementation method of the Linux system console is that when the module _ init is driven in the gadget serial port driving code, the USB serial port is registered as the terminal through the register _ Console function, and a ring buffer memory area is distributed at the terminal at the moment, and the space size of the buffer memory area can be 128 Kbytes. Next, when the USB cable is inserted into the terminal, the terminal calls a gselial _ connect function, sets the connection state of the USB cable to 1 (i.e., the connection state), and calls a function for opening/closing the USB serial port;
the above-described open or close function may be operated through the Linux kernel work queue work struct. The specific operation can be as follows: in the started work queue, the USB serial port is opened, and the opening state of the collocated terminal console port is 1.
If the Windows PC is connected to the USB serial port terminal equipment through the USB line, a terminal application program (such as Putty, SecureCRT and the like) of the PC end is started, a first USB serial port corresponding to the USB serial port is started, the first USB serial port is opened, the gadget serial drive code of the embedded terminal equipment can receive the opening action (PC opening action), and the embedded terminal equipment sets the state of the USB serial port to be in an opening state; when the embedded terminal device has printk information to be output, the embedded terminal device calls the write function of the console port, that is, the do _ gs _ write function can be used to send all the terminal printing information to the PC through the USB serial port, including the content cached in the ring buffer memory. And the Windows PC receives and displays the printk information and the cached content.
If the opposite end of the Windows PC closes the serial port in the terminal application program, such as Putty, SecureCRT and the like. At this time, the Linux kernel printk information is stored in the ring buffer of 128 kbytes allocated by the driver. In addition, if the output printk information exceeds 128K bytes, the print information output by the previous core is lost. If the USB serial port line is pulled out next, the task queue for opening and closing the serial port is triggered to execute in the gserial _ disconnect function called later, the do _ gs _ close function is called in the task queue to close the USB serial port, and the connection state and the interrupt starting state of the USB line are both 0.
Herein, the do _ gs _ open, do _ gs _ write and do _ gs _ close functions are all shared with the corresponding functions in the file _ operations call of the USB tty serial port. This makes it possible to make the corresponding opening/closing operations interwork between the terminal and the tty file operation, and also makes the cohesion of the code higher.
Referring to fig. 3, fig. 3 provides a terminal, where the terminal is an embedded Linux system, and the terminal further includes: USB serial ports, the terminal still includes:
the starting unit is used for calling the kernel to configure the kernel command line cmdlene into multi-terminal starting and register the USB serial port as a terminal when the starting unit is started;
the processing unit is used for setting the connection state of the USB line into a connection state when detecting that the USB line is inserted, and calling a function to adjust the state of the USB serial port to be opened; when the first USB serial port of the opposite end of the USB serial port is determined to be opened, the console terminal sets the state of the USB serial port to be an open state; and acquiring the printk information, calling a write function of the console port, and sending the printk information and the data of the preset cache area to the opposite terminal equipment through the USB serial port.
The technical scheme who this application provided changes through the Console terminal for this Console terminal can realize printing (transmission shows promptly) to printk information data through the USB serial ports, because the transmission speed of USB serial ports is very much fast than the speed of ordinary serial ports, consequently the technical scheme who this application provided has the advantage that improves transmission speed.
Optionally, the processing unit is specifically configured to register the USB serial port as the terminal through a register _ console function when the module _ init is driven in the gadget serial driver code.
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.
Optionally, the processing unit is further configured to cache, by the console terminal, the acquired printk information in the preset cache region when it is determined that the first USB serial port of the USB serial port opposite terminal is closed.
Referring to fig. 4, fig. 4 provides a Linux hardware system, including: the system comprises opposite terminal equipment and a console terminal;
the console terminal is used for calling the kernel to configure the kernel command line cmdlene into multi-terminal starting and register the USB serial port as a terminal when the console terminal is started; when the USB cable is detected to be inserted, setting the connection state of the USB cable into a connection state, and calling a function to adjust the state of the USB serial port to be opened;
the opposite terminal equipment is used for starting a terminal application program, starting a first USB serial port corresponding to the USB serial port and setting the state of the first USB serial port into an open state; sending the starting action to the console terminal;
the console terminal is also used for setting the state of the USB serial port to be an open state when the first USB serial port of the USB serial port opposite end is determined to be open; and acquiring the printk information, calling a write function of the console port, and sending the printk information and the data of the preset cache area to the opposite terminal equipment through the USB serial port.
Embodiments of the present application also provide a computer storage medium, wherein the computer storage medium stores a computer program for electronic data exchange, and the computer program enables a computer to execute all or part of the method steps of fig. 2.
The computer readable storage medium may be an internal storage unit of the server according to any of the foregoing embodiments, for example, a hard disk or a memory of the server. The computer readable storage medium may be an external storage device of the server, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like provided in the server. Further, the computer-readable storage medium may include both an internal storage unit and an external storage device of the server. The computer-readable storage medium is used for storing the computer program and other programs and data required by the server. The above-described computer-readable storage medium may also be used to temporarily store data that has been output or is to be output.
Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the server and the unit described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed server and method may be implemented in other ways. For example, the above-described terminal embodiments are merely illustrative, and for example, the division of the above-described units is only one logical functional division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. Further, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, terminals or units, and may also be an electrical, mechanical or other form of connection.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment of the present invention.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit may be stored in a computer-readable storage medium if it is implemented in the form of a software functional unit and sold or used as a separate product. Based on such understanding, the technical solution of the present invention essentially or partially contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the above method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk. In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.