LINUX HOME
Logo Image

Configuring Serial Ports for Linux

Important note for linux 2.6.22 and newer kernels: CONFIG_SERIAL_8250_NR_UARTS and CONFIG_SERIAL_8250_RUNTIME_UARTS kernel compilation parameters have been defaulted to "4", which causes no end of problems. You may need to recompile your kernel with larger values in these parameters to install more than four serial ports in your system using the information provided below.

In order to configure serial ports for Linux, you will need to make use of the setserial command.
Firstly, you will need to know the card's base address and and which IRQ it is using.

For an ISA card, this can be read off the jumpers on the card.

For a PCI card, our pcifind.plx PERL script provides a friendly listing of all our PCI cards in your system, including their base addresses and IRQs. To run it, open a terminal window and change to its directory, then type "perl pcifind.plx". Please note, pcifind.plx can't be run directly from the CD.

If, for some reason, you can't run pcifind.plx, type

     /sbin/lspci -vv -d 494f:*
at the command line; this will produce a more detailed but less readable listing of all the resources of our PCI cards. You will also need to consult the card's manual for its device ID. (Because lspci doesn't know about our cards specifically, it simply prints device IDs.)

It may also be useful to determine the UART type of the card as well, but setserial can configure this automatically.

Setserial assigns the serial port to one of the devices in /dev. Serial ports use either the /dev/cua[0-3] devices (which are obsolete; only older serial ports will use these), or more likely the /dev/ttyS* devices (/dev/ttyS[0-3] are reserved for the standard serial ports).

A typical call of the setserial command is:

     setserial /dev/ttySx baud_base 115200 port y irq z autoconfig

where x is the number of the ttyS device you wish to assign the serial port to, y is the port's base address, and z is the port's IRQ. The autoconfig parameter tells setserial to determine the UART type automatically. The baud_base 115200 must be present. Some customers of ACCES I/O Products have found setserial's -z parameter to be useful. For more information on how to use setserial , and it's parameters and arguments, see man setserial.

The command setserial -g /dev/ttyS* will list serial devices, and their port and irq assignments. You can use this list to help you decide which devices are available to use with setserial either because they are unused (they will be listed as "No such device") or because they are configured to a device that is not really there (the UART will be listed as "unknown").

Some distributions of Linux (such as Caldera) may not install more than the 4 standard ttyS devices (ie, ttyS0, ttyS1, ttyS2 & ttyS3; the standard COM 1-4 ports). If the setserial -g /dev/ttyS* command lists less ttyS devices than you will need (one for each port you are configuring), you will need to use the mknod command to create new devices. Some distributions of Linux include the MAKEDEV script, which easily creates ttyS devices for you. To use this script, type:

     ./MAKEDEV ttySx
from the /dev directory, where x is the number of the ttyS device you wish to create (make sure it is higher than any already existing ttyS).
If your Linux distribution does not include MAKEDEV, you'll need to use the mknod command. Type:
     mknod -m 666 /dev/ttySx c 4 y
at the command prompt. In this case, the "666" is the user permissions, "4" is the device's major number (all ttyS devices are major number 4, and 5 for the obsolete cua devices), x is the number of the ttyS device you wish to create, and y is 64+x. See man mknod for further information.

Saving Your Serial Port Configuration

It is possible to save your serial port configurations so that they can be run at start-up, rather than having to be re-configured every time you run Linux.How you save your serial configuration depends on which version of setserial, and which Linux distribution you are using. Issue the command setserial -V to check your version.
For versions of setserial prior to 2.15, and for certain Linux distributions (such as Caldera), the way to configure setserial is to manually edit the shell-script that ran setserial at boot-time. This script is /etc/rc.d/rc.serial, and instructions for editing it correctly can be found in that file. Edit it usung your preferred text editor program. The line "exit 0" will need to be commented out (by placing a # at the begining of the line), and other lines in the script edited, uncommented or added to reflect your setserial settings. Basically, you can add lines to the script that are exactly the same as the setserial commands you would type at a command prompt. The script will then run setserial appropriately automatically at system boot.

Starting with version 2.15 (1999) of setserial, some distributions of Linux (such as RedHat) simplified the process of saving you serial settings. The /etc/rc.d/rc.serial shell-script is not edited but instead the serial ports are setup automatically at system boot using data from a configuration file: /etc/serial.conf. Furthermore, you may not even need to edit serial.conf because using the setserial command may edit serial.conf for you automatically.
However, there are some considerations to be taken into account with this automatic configuration saving:

Firstly, depending on which distribution of Linux you are running, and how it has been setup during and since installation, it may need to be explicitly told to allow setserial configurations to be run at start-up. The file most commonly used to run setserial at boot-time (in conformance with the configuration file) will be /etc/init.d/serial (for Redhat, or something similar for other Linux distributions). This file should not normally be edited directly. For setserial >= 2.15, Redhat has a file /usr/doc/setserial-[version]/rc.serial (where [version] is the version number of your setserial) which you will have to move to /etc/init.d/ if you want setserial to run at boot-time. Once you have moved this file, run the command chkconfig --add serial to let Linux know that it should run serial port configurations at start-up.

Secondly, the configuration is not saved until your computer (Linux) is shut down properly. Subsequently, this can lead to problems in certain situations. For example, if the computer is not shut down properly (power failure, computer crashed, etc), the configuration will not be saved. Alternatively, if you are experimenting with various serial configurations, but forget to restore the configuration to it's original state (or make an error) before shut down, your "experimental" or erroneous settings will be saved.
To help prevent loss of serial configurations in this manner, you can force the setserial configurations to be saved at a time other than shut-down by running the shell-script

/etc/init.d/{set}serial stop
from a command prompt.

Please read your Linux documentation for more information on how your specific distribution handles saving your serial configurations.

Additional sources of information on this topic are:

  • man setserial
  • man mknod
  • man chkconfig
  • the Linux Serial HOWTO, which can be found at many places on the Internet.