Apple II Serial Terminal


One of my on-again, off-again, side-projects has been getting my Apple //e setup as a dumb terminal for OS X. I've been tinkering with this for about 9-years now, but never really had a setup I was happy with. I occasionally re-visit the project, but could never dedicate the time to get it right.

In my ideal setup, I wanted one monitor that handles multiple devices (Atari 7800, G5, Apple //e, etc...). For the most part my Dell 20" LCD has served me well, but one source of dissatisfaction with regards to the Apple //e is how it handled the composite video output in 80-column mode. The video would twitch every few seconds which is very annoying and tough to read. About a week ago, the display started to fail. The screen would go black after several minutes of use. I suspect that the inverter is failing, but don't want to just throw $100 at a hunch. For $150, I decided to replace it with a 22" 1080p HDTV instead of a new monitor, primarily because of the variety of inputs available. One happy coincidence of getting the new display is that 80-column mode now displays perfectly, which gave me the inspiration to revisit perfecting the Apple //e terminal project.

The second source of dissatisfaction came from Mac OS X. In general, I love OS X, but serial terminal support isn't exactly one of it's primary functions. Apple has either disabled or excluded necessary software to achieve this. Typically, to setup a serial login on a *NIX system you would add a line similar to the following to /etc/ttys:

tty.KeySerial1 "/usr/libexec/getty std.9600" vt100 on local secure

However, just doing this in OS X gets you nothing.

As it turns out in OS X, login_tty can only be invoked by the launchd process. There are MANY examples of getting a serial terminal running in OS X, and they all get hung up here and resort to using the "screen" command to get a serial terminal running. This is what I have done in the past, and what I have been searching to resolve. It's clunky, and requires intervention on the Mac before you can connect from the Apple. I just want to boot the //e, and get a login prompt without entering commands into the Mac first.

Eventually, I found a solution to my problem here:

http://www.club.cc.cmu.edu/~mdille3/doc/mac_osx_serial_console.html
In the Unix world, getty is the program that presents a login prompt. In earlier versions of Mac OS, one could add the appropriate line to /etc/ttys and have a prompt appear on a serial port. It appears that as of 10.6, this is no longer possible.
Instead, I found that creating a script to spawn the getty that is run by launchd does the trick. Note that running the getty on the command line appears to fail because the login_tty syscall can only be invoked by the init process (which on Mac OS is launchd). I therefore created a file called serialconsole.plist (name it as you wish) in /Library/LaunchDaemons/ containing the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>serialconsole</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/libexec/getty</string>
                <string>std.115200</string>
                <string>tty.usbserial-FTCCBMZ3</string>
<!--            <string>tty.PL2303-0000201A</string> -->
        </array>
        <key>KeepAlive</key>
        <true/>
</dict>
</plist>
Note that first bit sets the daemon name, the second bit sets the program arguments (one "string" per argument), and the last bit (keepalive) instructs launchd to restart the daemon when it exits (eg, the user logs out of the console). The first program argument is the getty program to execute, the second is the relevant line in /etc/gettytab that defines the desired serial port configuration (in this case the typical 115200 baud, 8 data bits, no parity, 1 stop bit; "8N1"), and the third argument to getty must be the name of the serial port device in /dev, which for the two devices I had were one of the two listed.
I installed the script (which I modified to reflect 9600 baud instead of 115200), rebooted the G5, booted the Apple //e from the Modem.MGR work disk (and set my baud rate, parity, and entered terminal mode), and I received a login prompt from the G5. Success! Or, so I thought... I proceeded to enter my credentials and received an error:

PAM ERROR (Cannot make/remove an entry for the specified session)

Sigh... back to research mode... I did a bit more searching and found my answer here:

http://www.puredarwin.org/users/users 
Thanks to Apple's Damien Sorresso on the launchd-dev mailing list for providing the answer to this. login needs a new security session created for it before it can set it up for the new user. This is what sshd does for in-coming users, and what loginwindow.app does for GUI users under OS X. For the moment, a small PAM module (pam_sessioncreate, available on the Downloads page) can be added to /usr/lib/pam/ and to /etc/pam.d/login just above pam_launchd ("session required pam_sessioncreate.so") to create the necessary session. The file should now include:

[...]
password    required    pam_deny.so
session     required    pam_sessioncreate.so    <- data-blogger-escaped-here="here" data-blogger-escaped-inserted="inserted" data-blogger-escaped-line="line" data-blogger-escaped-new="new" data-blogger-escaped-span="span">
session     required    pam_launchd.so
[...]
So, again I followed directions and downloaded the pam_sessioncreate.so file to /usr/lib/pam on the G5, modified /etc/pam.d/login adding the appropriate line, rebooted everything, tried again and was FINALLY able to login successfully on the Apple //e.

One anticipated side-effect of this project is that the Keyspan serial port is now monopolized. It is always in use by Getty waiting for a connection, which prevents me from using ADT (Apple Disk Transfer) to transfer disk images to the Apple //e and writing them to floppy. As a result, I am adding an additional phase to this project. To resolve the latest problem, I am going to install a second USB-Serial adapter to the G5, and use an A/B serial swich box to switch between them. I plan to start by getting the second adapter working with a direct connection, then add the additional cables and switch box later. I'll post my results in a future update...

Project Notes:

Commands used to start a terminal session after booting the ModemMGR work disk:
  • Boot from Modem.MGR work disk
  • Esc-M to set Baud Rate: 9600
  • Esc-J to set parity: 8-1-None
  • Esc-: to set Terminal: VT220
  • Press enter and you should get a logon prompt.
Websites I referenced:
  • http://pdw.weinstein.org/2007/06/apple-hacking-for-fun-and-profit.html
  • http://www.club.cc.cmu.edu/~mdille3/doc/mac_osx_serial_console.html
  • http://www.puredarwin.org/users/users
  • http://www.puredarwin.org/downloads
Hardware and Software used:
  • Apple //e
  • SuperSerial card (set to modem, not printer)
  • Null Modem cable
  • Keyspan USB-Serial adapter
  • Modem.MGR
  • ADT (Apple Disk Transfer - To copy the Modem.MGR disk image from the G5 to 5.25" floppy via serial transfer)
  • PowerMac G5
  • Mac OS X 10.5.8

Comments

Unknown said…
Hi Jason -

I'm trying to get serial console logins working properly on my 10.5.8 Mac and your article has been very helpful. I can get a login prompt and login via the USB serial port on the Mac, but I'm having the following issues...

- text is somewhat garbled, i.e. Carriage Return doesn't always work, weird characters display
- top and vi commands do not work/don't display correctly
- TERM environment variable does not get set

If I plug the USB serial port adaptor into a configured Ubuntu box, everything works perfectly, including top and vi. It seems like getty on the Mac is not getting configured properly for VT100 emulation.

Would it be possible for you to confirm that the top and vi commands start/display properly via USB serial logins via your Apple //e?

The only difference between our setups is that I'm using a TrendNet TU-S9 adaptor instead of your Keyspan adaptor. I suppose it's possible my issues are being caused by the TU-S9 drivers on the Mac, but I'm not convinced because I can boot-strap my Apple //e using the TU-S9 on the Mac using ADT and well as transfer disk images to physical floppies.

Anyway, just wanted to confirm with you before I tried purchasing a Keyspan adaptor.

Thank you!
Patrick
Aftermac said…
Patrick,

Thanks for the comment, I'm glad you found this helpful!

This definitely sounds like a terminal emulation problem. My first thought is that you might not be setting Modem.MGR to VT220. That part of my instructions doesn't read very well. To set VT220 make sure to press ESC and then type a colon ":", and then select the option for VT220. I tested this tonight and verified that Top and Vi do display and function correctly.

I was able to replicate a scenario similar to what you described, by just hitting ESC and then Enter (not typing ":" to set VT220). I got a login prompt and at first it seemed to work, but Top was completely useless and displayed nothing but garbage.

Let me know if this helps.

Thanks,

Jason

Unknown said…
Hi Jason -

I tried replying earlier this week, but I think it got lost. Anyway, thank you for confirming that vi and top work for you. I'm able to get top and vi working of I run 'export TERM=vt220' after logging in, or by adding something like that to my /etc/profile. That part is working fine in Unbuntu because getty on there support a TERM flag like you have listed in your /etc/ttys line example. Getty in Mac OS does not support that flag, so I I needed to do it manually. Can you confirm that you are not setting a TERM value on your Mac box? If not, I'm curious how it's getting set for you.

I'm still have the weird character issue. Here is an example of me hitting 'Enter' a number of times...
patrick@macpro[~]$
patrick@macpro[~]$ ??H?patrick@macpro[~]$ ???H?patrick@macpro[~]$ ?C?patrick@macpro[~]$
patrick@macpro[~]$
patrick@macpro[~]$
patrick@macpro[~]$
patrick@macpro[~]$
!?patrick@macpro[~]$
patrick@macpro[~]$
patrick@macpro[~]$
patrick@macpro[~]$
patrick@macpro[~]$
patrick@macpro[~]$
patrick@macpro[~]$
?H?patrick@macpro[~]$
patrick@macpro[~]$
patrick@macpro[~]$

It's interesting to note that running 'screen' works and the bash session inside of screen works flawlessly.

Anyway, thanks for the help!

Patrick
Unknown said…
Also, wanted to say that I am using the Esc-: command to set emulation to vt200 in MODEM.MGR. You instructions were very clear :)

Patrick
Aftermac said…
I'm glad you're making some progress! :) I'm definitely not manually setting a TERM value.

I double checked the entry in my /etc/ttys, which displayed:

tty.KeySerial1 "/usr/libexec/getty std.1200" vt100 on local secure

And the changes I made to the /Library/LaunchDaemons/serialconsole.plist script:

(These lines are in the STRING tags)

/usr/libexec/getty
std.9600
tty.KeySerial1


The changes I made to the script may make a difference for you. I'm also using a pretty low baud rate for a vintage feel. In the morning I'll fire up my Apple IIe and try hitting enter at the command prompt rapidly to see what happens. I'll let you know what I find.
Unknown said…
Ok... I get it now. I had thought that /Library/LaunchDaemons/serialconsole.plist *replaced* the entry in /etc/ttys. Once I added in a matching entry in /etc/ttys, $TERM gets set automatically - awesome!

Also, switching to a Keyspan adaptor resolved my strange character issue, so I'm 100% working now.

THANK YOU for the help, Jason!

Patrick


Unknown said…
This comment has been removed by the author.
Unknown said…
Hi Patrick, I am having the same problems connecting my Mac OS X (10.7.5) to a vintage DEC Writer III. Using screen, or CU in terminal, I get a perfect connection, using getty, launched by a daemon produces the logon prompt, I can log in, but get 50% garbage text mixed with the actual text. I modified the gettytab reference in various ways, baud rate, parity, stop bits, no luck. Somehow, going via getty corrupts my connection. I don't know how to set up terminal type via the getty launch daemon like was possible in older versions of OS X using a ttys entry. Have you had luck resolving your issue?
Aftermac said…
John, when you replied I realized that I still had an unpublished comment from Patrick. If you ready his comment below you'll see that he did get his issue resolved.

Unfortunately, I've only tested my setup on on 10.5.8. If Apple has made further changes in newer versions, then there may be a few more hoops to jump through.

Do you happen to be using a Keyspan serial adapter?

Popular posts from this blog

The NeXT Mac

Fried Apple