The goal of this lab is to take the first steps toward giving your embedded system dialup capabilities. We will be enabling one of the serial ports and using mgetty to answer login requests from that port.
Much of the information in this document was gleaned from:
To begin with, we need to verify that the serial ports on our system is available. Using setserial, we can get the current status of our ports. (Note: on the machine that I was developing this lab on, /dev/ttyS0 or COM1 was already being used by a PROM programmer, so I used /dev/ttyS1 or COM2. Substitute the appropriate device for your setup.) I typed setserial -a /dev/ttyS1 and got the following results:
#setserial -a /dev/ttyS1
/dev/ttyS1, Line 1, UART: 16550A, Port: 0x02f8, IRQ: 5
Baud_base: 115200, close_delay: 256, divisor: 0
closing_wait: 15360
Flags: spd_normal skip_test
To verify that there are no interrupt conflicts, type cat /proc/interrupts. This will print the table of interrupts contained in the file /proc/interrupts to the screen. The far left column lists all of the interrupts in use by the kernel. If the IRQ listed by set serial doesn't appear in this column, then the interrupt is available for your use.
Next, we need to configure Linux to initialize our serial ports upon boot. Begin by looking in the directory /etc/rc.d/init.d/ for the file serial. Do this with the command:ls -l /etc/rc.d/init.d/serial
If no file exists, there is one that we can copy. Type:
cp /usr/share/doc/setserial-2.17/rc.serial /etc/rc.d/init.d/serial
After we do this, we need to add it to the installation configuration. Type:
chkconfig --add serial
In order to have the serial ports automatically configured upon boot-up, we need to add the following code to either /etc/rc.d/rc.serial or /etc/rc.d/rc.local.
setserial /dev/ttyS1 autoconfig ^skip_test
setserial -a /dev/ttyS1
At this point, our serial ports should be available to us upon boot. If you were to reboot the machine now, then take a directory of /etc/rc.d/init.d using the command ls -ltru /etc/rc.d/init.d/, you would see that serial was accessed upon system initialization.
A getty program is the "brains" that will watch the serial port for login requests and provide the access to the server's services. The getty program that appears to be receiving the most interest is mgetty. The latest version can be downloaded from ftp://alpha.greenie.net/pub/mgetty/source/1.1/. The version I downloaded to test for this lab is mgetty1.1.30-Dec16.tar.gz. The stabler version is probably the one with the odd version number, mgetty1.1.29-Nov25.tar.gz.
After downloading the source and putting it onto your development machine, decompress it with the command:
tar -xvzf mgetty1.1.30-Dec16.tar.gz
Change into the subdirectory created by tar. There should be a file named policy.h-dist. Make a copy of this file named policy.h.
cp policy.h-dist policy.h
policy.h can be customized for your application, but I found that the default settings worked fine. Mostly, this file just defines items such as the names of the configuration files and the type of login prompt. Notice, however, that the file references are all made relative to a directory referred to as CONFDIR. CONFDIR is defined in the Makefile.
Next, open the file Makefile for editing. Search for the text prefix. This text represents the root directory where the components of mgetty will be created and stored. I think the default value for this is "/usr/local". Change this to "/usr".
mgetty is also capable of being used for fax modems. This is not a concern of ours, but I've been told that odd things might happen if the user that is configured for receiving faxes does not exist as a user on your system. Search the Makefile for the string FAX_OUT_USER. The default value for this user is "fax". You have one of two options. Either add the user fax to your system or replace fax with a non-root user that already exists on your system.
After you save and close the Makefile, type make. This should build all of the programs for mgetty. After this build is complete, install mgetty by typing make install.
Assuming you specified the same "prefix" setting in the Makefile and kept the default values for the directories specified in the policy.h file, the directories indicated here will be the same as those on your installation.
First, the mgetty executable should be located in /usr/sbin. You can verify this by typing:
ls -l /usr/sbin/mgetty
For your system to run mgetty continuously as a background process, you need to add the following line to your inittab which is found in the /etc directory. Open inittab, and add the line:
S2:2345:respawn:/usr/sbin/mgetty -r ttyS1 /dev/ttyS1
The 2345 portion of this line indicates that mgetty will be executed on run levels 2, 3, 4, or 5. (See the comments in inittab for the corresponding modes.) respawn tells the system to reload mgetty if it ever closes. -r means that in this instance we will be using a direct serial connection, i.e., there is no modem to initialize (remove the -r if you use a modem). The /dev/ttyS1 indicates to mgetty which port we will be using.
Save and close inittab.
In the directory /usr/etc/mgetty+sendfax, there should be a number of files that we are interested in verifying for the mgetty configuration. First, open mgetty.config. Using the #-sign, comment out all lines referring to the fax. Next, add the following lines (some may already by added).
debug 4
port ttyS1
speed 38400
term vt100
data-only y
Note that the speed can actually be set to a faster setting such as 115200. This is the baud rate that we will be connecting at, so be sure to set the system you are dialing in with to the same value.
In the same directory there should be a file called login.config. This file will direct mgetty to the login information. We simply want to allow the same users that have access to our system to log into the dialup connections. Therefore, the following line should remain in the login.config file as is.
* - - /bin/login @
In the same directory, there should be a file called dialin.config. This file allows for caller ID to be used to limit the phones from which this server can be called. This file should not have any entries setup and therefore allow all numbers to call in.
It should be time to get things going. To get the new settings in inittab to run without rebooting the system, type init q. Once mgetty has been started, you can view the mgetty log which lists all of its activity since the log was first opened. In the case of my system, the log was in the file /var/log/mgetty.ttyS1.
Begin by connecting the port of a machine with a terminal program on it such as minicom to the port of the machine where you just installed mgetty through a null modem.
It is vital that you use a null modem as serious damage could be done to one or both ports if you use a straight through cable.
Using your terminal program, set the port settings such as baud rate to match those of the machine with mgetty installed. Remember, configuring minicom involves pressing CTRL-A Z then selecting O to configure the port.
If everything worked correctly, then you should simply need to press ENTER from minicom and you will receive a login prompt from the machine with mgetty installed.
Once you get the set up working on your development system, see if you can move it to your embedded system. Good luck!
Developed by David Tarnoff for the Summer 2003 section of CSCI 4956-011 at ETSU