Setting up a simple serial connection with OpenBSD
Abstract
This description is not meant for serious work, please look elsewhere for such information.
This document describes how to connect a computer to an
OpenBSD machine over a serial wire, and have it display
output coming in over this cable. The document describes what cables are
needed and how to make them, plus a description on how to configure your systems.
While this describes OpenBSD systems, I assume the same goes for
other BSD variants and Linux as well. This is a very primitive
description; I made my cable out of household items and wrote
some software which I then ran using the OpenBSD installation
disks as starting point. In other words - if something bad
happens, it is not my fault.
History
One rainy day I had an old 386 lying around collecting dust, and
I decided to connect it to my existing OpenBSD machine in one way
or another. Since network cards are too expensive for such a purpose,
I decided to go for a null modem connection. Since null modem cables
would have forced me to go out in the rain and spend hard earned cash for
a proper cable, I instead decided to create the cable myself. The rest
of the history follows below...
Goal
We want to have an old 386 with a monitor running OpenBSD being
able to display whatever comes in on serial port COM1. This way we can
connect the crappy 386 - called Zenith from now on - to a real computer
running OpenBSD - we'll call that machine Tau. By writing data from Tau
to Zenith, we can let Zenith display whatever comes in and it will all
look fancy and perhaps even a bit useful...
The diagram below shows the configuration.
| Zenith (old 386) |
>- (DE-9 connector) |
----------------------- (null modem cable) |
-< (DE-9 connector) |
Tau (real computer) |
Prerequisites
You should have the following
Building a null modem cable
With two DE-9 connector, the connections for our null modem cable using 3 wires
is very simple. Connect pin 5 to 5 straight through. Swap pin 2 and 3 on each
connector. Pin 5 is signal ground. Pin 2 and 3 are receive/transmit data.
I was unlucky enough to have just a single a DE-9 connector, meaning I had to create my null modem cable by using rubber tape to connect the wires to the connector. Then I wired the wires around a needle, approximately as thick as the computer's DE-9 male connector. Then wrap rubber tape around them, and you'll have three small individual female connectors which you can then carefully insert over your computers connector pins.
Real null modem cables seem to have more wires, and I am not sure if a 3-wire null modem cable is an actual null modem cable. It will work for this specific purpose however.
Testing the cable
If you have two fully working computers this is very simple. Connect your
cable between the computers. On one computer, enter cat </dev/cua00
and on the other cat >/dev/cua00. When writing something into
the other computer, it should show up on the first.
If nothing happens, try switching and run the cat commands on the other machine. If this works, it may mean your cable is broken and can only transmit or receive data one way. My cable does that currently, so I am not entirely sure whether bidirectional data is at all possible (*). However, since we will be using Zenith to simply display data, it is enough that the cable can transmit data from Tau to Zenith.
*) Note! Someone told me that in order for data to be transfered bidirectionally over this kind of cable you have to connect pin 1, 4, 6 and pin 7, 8 on both connectors. I have not tried this myself yet, but if you want data to be transmitted bidirectionally this is probably what you want. Thanks!
Configuring Zenith
Since this computer was old and crappy, it had no hard drive and no keyboard,
and I certainly would not spend any money on such. What to do? I went to my
working OpenBSD system, cd /usr/src/sys/arch/i386/conf, copied
RAMDISK to ZENITH, then edited ZENITH to remove unneeded things. Then build
the kernel, go down to /usr/src/distrib/i386/floppies/ and
make a copy of ramdisk and common. Build the ramdisk
image, dd it out to a 1.44 MB floppy, and boot Zenith with it.
Does it work? Good. That means you can start modifying things and make it work even better. If you lack a keyboard you probably want to have something nice starting up automatically, displaying whatever comes in on /dev/cua00 or do some other stuff - instead of the installation instructions.
Here is what I did: Change common/dot.profile to launch a program named readcua directly at startup. I wrote this program in order to get some remote control over Zenith, due to the lack of a keyboard. Download the source code and remember to compile it statically! You will have to change some files in common/list as well in order to get the readcua binary onto the floppy. The program will listen on /dev/cua00 by default and display everything that comes in. When the incoming data starts with a '!' it means the rest of the command should be executed with a system() call, effectively giving you primitive shell access.
My very own boot floppy can be downloaded here, just dd it onto a floppy and off you go.
What now
This is the funny part. Start up your connected systems, let the boot disk
load on Zenith and wait for it to start listening on the serial port. Now
try tcpdump >/dev/cua00 on Tau and look at all the fancy data
flashing by on Zenith's monitor. (if you have an active local network, that is).
To get remote shell access, first do cat >/dev/cua00 on Tau. Then enter !ls -lF and !cat /kern/msgbuf, and you get an idea of how it works - first prefix with '!' and then a shell command.
So whenever you need to display something important, logging information, monitoring data, or whatever, you simply redirect/tee it to /dev/cua00 and it will look very fancy. :)
Useful links