Information wants to be free...

Linux System on a Floppy

Referring to my previous project to build a Linux distribution for LOADLIN. It is actually possible to also boot this directly from a 1.44M floppy disk, which can be quite useful. The output from that build should be the Linux kernel "bzImage" and the root filesystem "rootfs.cramfs". I renamed "rootfs.cramfs" to simply "rootfs" to avoid any conflicts with the 8.3 filename format.

SYSLINUX will be used for booting, and it needs "syslinux.cfg" configuration file with the followng contents:

DEFAULT linux
LABEL linux
  KERNEL bzImage
  APPEND initrd=rootfs
          


These are the steps to make the floppy disk image:

dd if=/dev/zero of=floppy.img bs=512 count=2880
mkdosfs floppy.img
syslinux --install floppy.img
mkdir /tmp/floppy
mount -o loop floppy.img /tmp/floppy
cp bzImage /tmp/floppy/
cp rootfs /tmp/floppy/
cp syslinux.cfg /tmp/floppy/
umount /tmp/floppy
          


The floppy disk image can be tested in QEMU with:

qemu-system-i386 -fda floppy.img -boot a
          


Writing the floppy disk image to an actual floppy disk is typically done like so:

dd if=floppy.img of=/dev/fd0 bs=512
          


For convenience, download the floppy disk image here.

Topic: Configuration, by Kjetil @ 05/09-2021, Article Link

Amiga 500 with the Framemeister

Here is how I connected the Amiga 500 to the Micomsoft XRGB-mini Framemeister to be able to get color graphics on a modern display through HDMI.

The tricky part is getting a "DB23" connector, but I ended up using a regular DB25 connector (made from plastic) and shaving off part of it to make it fit into the Amiga 500. The mini-DIN connector on the Framemeister only accepts composite sync (not separate horizontal and vertical which is more common) but this is available on one of the pins on the Amiga. However, it is a 5V TTL level signal which is a little bit too hot so it's recommended to reduce this with a resistor. I ended up using two 360 Ohm resistors in series at 720 Ohm since that is what I found in stock at the moment. Some diagrams I found online claim that ground should be taken from pin 16 from the Amiga, but this did NOT work for me. Pin 19 which is composite video ground worked fine.

Here is the cable pin out:

|----------------|-------|---------|--------------|
|                | Amiga |         | Framemeister |
| Signal         | DB23  |         | Mini-DIN     |
|----------------|-------|---------|--------------|
| Red            | 3     |         | 8            |
| Green          | 4     |         | 7            |
| Blue           | 5     |         | 6            |
| Composite Sync | 10    | 720 Ohm | 3            |
| Ground         | 19    |         | 4            |
|----------------|-------|---------|--------------|
          


When testing the connections with clip leads I got some "jail bars" (faint traces of vertical lines) on the display, but these more or less disappeared when I soldered everything together properly. Not sure if that was caused by general noise or by poor clip lead cables.

The finished cable connected:

Amiga to Framemeister connection.


Topic: Configuration, by Kjetil @ 24/07-2021, Article Link

DVB-T USB Stick Playback

I got one of those DVB-T tuners a while ago, in the form of a USB stick, specifically this one:

15a4:1001 Afatech Technologies, Inc. AF9015/AF9035 DVB-T stick
          


However, it took me many years to finally get this working on Linux after a lot of trial and error. There are two important things I discovered during this time. The first is that MPlayer is quite bad at handling MPEG TS files (or streams). The second is that, at least in my case with this particular stick, the /dev/dvb/adapter0/dvr0 device would not work as advertised.

The solution I ended up with is w_scan for scanning, v4l-utils for tuning and ffmpeg for playback.

Use these steps to scan and generate the channels list:

w_scan --output-initial > channels.conf
dvbv5-scan --input-format=CHANNEL --output=dvb_channel.conf channels.conf
          


Then use these steps for playback:

mkfifo /tmp/dvb.ts
dvbv5-zap -c dvb_channel.conf "name-of-the-channel" -o /tmp/dvb.ts &
ffplay /tmp/dvb.ts
          


I found that TV (video and audio) playback works OK, but radio (audio only) will buffer for a very long time before playback starts, so not very convenient.

Topic: Configuration, by Kjetil @ 27/03-2021, Article Link

Toshiba Satellite Pro 410CDT Tweaks

I got hold of an old Toshiba Satellite Pro 410CDT laptop with a Pentium 90MHz processor, which I have cleaned up and refurbished. Since I already got tons of Linux boxes I figured to use this a "DOS Gaming Laptop" instead. It has a Sound Blaster compatible ESS688 sound chipset and a Adlib compatible FM synthesizer, making this perfect for that use.

Important notice! The internal batteries in this had already started to shown signs of leakage, the typical turquoise spots:

Toshiba 410CDT Batteries

I immediately removed the batteries and cleaned up the spots with vinegar. It will now complain about lost CMOS settings every time, but I can live with that for now.

Another challenge is that this laptop has no floppy drive, since that is swappable with a CD-ROM drive that I (only) got instead. To be able to install DOS I used QEMU to install it on a virtual drive, then removed the original hard drive from the laptop and DD'd over the virtual drive to it.

I knew the hard drive was 815394816 bytes, meaning 1592568 512-byte sectors, so a virtual drive can be made like this:

dd if=/dev/zero of=Toshiba_DOS.dd bs=512 count=1592568
          


QEMU is launched like this:

qemu-system-i386 -drive format=raw,file=Toshiba.dd -cpu pentium -m 32 -monitor stdio -fda DOS_Floppy_1.dd
          


One can then use the QEMU monitor to change and eject virtual floppies like so:

change floppy0 DOS_Floppy_2.dd
change floppy0 DOS_Floppy_3.dd
eject floppy0
          


Afterwards it is also possible to loopback mount he virtual hard drive to put more stuff on there, like tools and games. Since the first partition starts at sector 63, an offset of 32256 bytes must be used:

sudo mount -o loop,offset=32256 Toshiba_DOS.dd /mnt/loop/
          


I used one of those USB-to-IDE adapter and the virtual hard drive is typically DD'd back just like this:

dd if=Toshiba_DOS.dd of=/dev/sdd bs=512 status=progress
          


Finally, for reference, here is the "AUTOEXEC.BAT" file I ended up using for the laptop:

C:\DOS\SMARTDRV.EXE /X
@ECHO OFF
PROMPT $p$g
PATH C:\DOS;C:\VI;C:\MSKERMIT;C:\PKZIP
SET TEMP=C:\DOS
MODE CON CODEPAGE PREPARE=((850) C:\DOS\EGA.CPI)
MODE CON CODEPAGE SELECT=850
LOADHIGH=C:\DOS\KEYB NO,,C:\DOS\KEYBOARD.SYS
LOADHIGH=C:\DOS\DOSKEY.COM
LOADHIGH=C:\DRIVERS\MOUSE.COM
LOADHIGH=C:\DRIVERS\MSCDEX.EXE /D:MSCD001 /L:D
C:\ESSUTIL\ESSVOL.EXE /V:8 /L:8 /W:8 /M:0 /C:8 /S:8
SET BLASTER=A220 I7 D1 T6 P330 H5
          


And the "CONFIG.SYS" file:

DEVICE=C:\DOS\HIMEM.SYS
DEVICE=C:\DOS\EMM386.EXE NOEMS
DOS=HIGH,UMB
COUNTRY=047,,C:\DOS\COUNTRY.SYS
DEVICEHIGH=C:\DOS\SETVER.EXE
DEVICEHIGH=C:\DOS\DISPLAY.SYS CON=(EGA,,1)
FILES=50
BUFFERS=10,0
DEVICEHIGH=C:\DRIVERS\OAKCDROM.SYS /D:MSCD001
          


Topic: Configuration, by Kjetil @ 15/11-2020, Article Link

Compaq Deskpro XL 5133 with Red Hat 5.2

I decided to install the classic Red Hat Linux 5.2 distribution on my classic Compaq Deskpro XL 5133 machine. The 5.2 version is one of the more well known from the late 90's, and several others have used this to experience the past. It is using the 2.0.36 version of the Linux kernel.

Before any of the SW installation could take place, the on-board battery had to be changed to be able to keep the system configuration intact. Luckily the battery is a Lithium type, so it doesn't leak, but it was soldered in place. I changed it with a CR2032 battery holder, which works fine.

CR2032 battery holder replacement


After configuring the system with the special Compaq floppy disks (there is no BIOS setup menu!) I was able to install Red Hat 5.2 using the CD-ROM without any trouble. The machine has a Matrox Millennium VGA card which works fine in X Windows and a on-board AMD PCnet32 Ethernet controller working out of the box.

The troublesome part was getting the audio to work, which is classified as "Compaq Deskpro XL Business Audio", but is in reality a "Microsoft Sound System" compatible chip of the AD1847 type:

AD1847JP SoundPort Chip


When playing any audio, it would stutter and the following error would appear:

Sound: DMA (output) timed out - IRQ/DRQ config error?
          

I tried all kinds of different IRQ and DMA settings, but to no avail. To troubleshoot further I setup a QEMU emulated environment also with Red Hat 5.2 to be able to quickly recompile the ad1848.o module device driver.

I figured out that in vanilla Linux 2.0.36 the sound drivers are not modularized, and Red Hat had actually applied a patch to modularize them. So this exact setup had to be re-recreated. The original sources can be found here as "kernel-2.0.36-0.7.src.rpm". But these still needs to be patched, where I did the following:

tar -xvzf linux-2.0.35.tar.gz
gunzip 2.0.36-pre-patch-14.gz
gunzip sound.diff.gz
patch -p0 < 2.0.36-pre-patch-14
patch -p0 < sound.diff
mv linux linux-2.0.36
patch -p0 < kernel-2.0.36-sound-new.patch
cp kernel-2.0.36-i386.config linux-2.0.36/.config
          

Yes, the original sources is actually Linux 2.0.35, but with a patch to bump it up to 2.0.36!

After enabling debugging flags, I eventually found out that this stock driver is detecting the audio chip wrongly as a "OPTi 82C930" chip, which in turn causes the IRQ status to be read from the wrong register!

Here is my own patch to fix this problem and enabling the debug:

--- ad1848.c.orig    2020-08-30 12:42:45.362175159 +0200
+++ ad1848.c    2020-08-30 12:42:52.142175232 +0200
@@ -37,6 +37,9 @@
 
 #include "soundmodule.h"
 
+#define DEBUGXL
+#define DDB
+
 #define DEB(x)
 #define DEB1(x)
 #include "sound_config.h"
@@ -1532,10 +1535,19 @@
     {
         if ((tmp1 = ad_read(devc, i)) != (tmp2 = ad_read(devc, i + 16)))
         {
-            DDB(printk("ad1848 detect step F(%d/%x/%x) - OPTi chip???\n", i, tmp1, tmp2));
-            if (!ad1847_flag)
-                optiC930 = 1;
-            break;
+            if (deskpro_xl)
+            {
+                DDB(printk("Deskpro XL, so assuming AD1847\n"));
+                ad1847_flag = 1;
+                break;
+            }
+            else
+            {
+                DDB(printk("ad1848 detect step F(%d/%x/%x) - OPTi chip???\n", i, tmp1, tmp2));
+                if (!ad1847_flag)
+                    optiC930 = 1;
+                break;
+            }
         }
     }
 
@@ -1688,7 +1700,10 @@
                         }
                         else
                         {
-                            devc->model = MD_4231;
+                            if (! deskpro_xl)
+                            {
+                                devc->model = MD_4231;
+                            }
                         }
                 }
             }
@@ -1708,6 +1723,7 @@
     if (devc->model == MD_1848 && ad1847_flag)
         devc->chip_name = "AD1847";
 
+    DDB(printk("ad1848_detect() - '%s' (%d)\n", devc->chip_name, devc->model));
 
     return 1;
 }
          

Or you can download my recompiled version here.

The /etc/conf.modules section ended up being like this for the driver:

alias sound ad1848
alias midi opl3
options opl3 io=0x388
options ad1848 io=0x530 irq=9 dma=1,0 type=2 deskpro_xl=1
          


Compaq Deskpro XL 5133


Topic: Configuration, by Kjetil @ 01/11-2020, Article Link

Linux Distribution for LOADLIN

This is a similar project to the Linux Distribution for 386SX but this with some different goals. Most importantly to boot it with LOADLIN directly from DOS and keeping the root filesystem in RAM using Cramfs. In addition, I wanted to have functioning SLIP support.

I ended up using these specific software versions:
* linux-2.4.37.11
* gcc-3.4.6
* busybox-1.19.4
* uClibc-0.9.33.2
* binutils-2.32

Get the necessary scripts, configuration and patches here to make it yourself. Or just get the completed kernel and root filesystem here.

For easy reference, here is the script to compile everything:

#!/bin/bash
set -e

TARGET="i386-linux-uclibc"
PREFIX="${HOME}/opt/gcc-${TARGET}/"
SYSROOT="${PREFIX}/${TARGET}/sysroot"

GCC_SRC="gcc-3.4.6.tar.bz2"
BINUTILS_SRC="binutils-2.32.tar.xz"
UCLIBC_SRC="uClibc-0.9.33.2.tar.xz"
LINUX_SRC="linux-2.4.37.11.tar.xz"
BUSYBOX_SRC="busybox-1.19.4.tar.bz2"

export PATH="${PREFIX}bin:$PATH"

# Prepare Prefix and System Root
if [ -d "$SYSROOT" ]; then
  echo "Old system root directory detected, please remove it."
  exit 1
else
  mkdir -p "$SYSROOT/usr"
fi

# Prepare Build Directories:
if [ -d build ]; then
  echo "Old build directory detected, please remove it."
  exit 1
else
  mkdir -p build/binutils
  mkdir -p build/gcc-stage1
  mkdir -p build/gcc-stage2
  mkdir -p build/uclibc
  mkdir -p build/linux
  mkdir -p build/busybox
fi

# Unpack Sources:
if [ -d source ]; then
  cd source
  tar -xvjf "$GCC_SRC"
  tar -xvJf "$BINUTILS_SRC"
  tar -xvJf "$UCLIBC_SRC" -C ../build/uclibc
  tar -xvJf "$LINUX_SRC" -C ../build/linux
  tar -xvjf "$BUSYBOX_SRC" -C ../build/busybox
  cd -
else
  echo "No source directory, please download sources."
  exit 1
fi

# Patch gcc-3.4.6:
cd "source/gcc-3.4.6/gcc/config/i386/"
if ! fgrep --silent "inhibit_libc" linux.h; then
  patch -p 0 < ../../../../../gcc-3.4.6-linux.h.patch
fi
cd -

# Patch linux-2.4.37.11:
cd "build/linux/linux-2.4.37.11/include/linux/"
if ! fgrep --silent "<linux/types.h>" filter.h; then
  patch -p 0 < ../../../../../linux-2.4.37.11-filter.h.patch
fi
cd -

# Install Linux 2.4 Headers:
cd build/linux/linux-*
make ARCH=i386 mrproper
make ARCH=i386 include/linux/version.h
make ARCH=i386 symlinks
mkdir -p "$SYSROOT/usr/include/asm"
cp -v -R -H include/asm "$SYSROOT/usr/include"
cp -v -R include/asm-generic "$SYSROOT/usr/include"
cp -v -R include/linux "$SYSROOT/usr/include"
touch "${SYSROOT}/usr/include/linux/autoconf.h"
cd -

# Build binutils:
cd build/binutils
../../source/binutils-*/configure --target="$TARGET" --prefix="$PREFIX" --with-sysroot="$SYSROOT" --disable-werror --enable-languages=c,c++ --enable-shared --without-newlib --disable-libgomp --enable-fast-install=N/A
make all-{binutils,gas,ld}
make install-{binutils,ld,gas}
cd -

# Build Stage 1 GCC3:
cd build/gcc-stage1
../../source/gcc-3*/configure --target="$TARGET" --prefix="$PREFIX" --with-sysroot="$SYSROOT" --with-cpu=i386 --disable-fast-install --disable-werror --disable-multilib --enable-languages=c --without-headers --disable-shared --disable-libssp --disable-libmudflap --with-newlib --disable-c99 --disable-libgomp --disable-threads
make all-gcc
make install-gcc
cd -

# Install uClibc Headers:
cd build/uclibc/uClibc-*
cp -v ../../../config-uclibc .config
sed -i -e "s%KERNEL_HEADERS=.*%KERNEL_HEADERS=\"$SYSROOT/usr/include/\"%" .config
make ARCH=i386 PREFIX="$SYSROOT" install_headers
cd -

# Build uClibc:
cd build/uclibc/uClibc-*
make ARCH=i386 PREFIX="$SYSROOT"
make ARCH=i386 PREFIX="$SYSROOT" install
cd -

# Build Stage 2 GCC3:
cd build/gcc-stage2
../../source/gcc-3*/configure --target="$TARGET" --prefix="$PREFIX" --with-sysroot="$SYSROOT" --with-cpu=i386 --enable-fast-install=N/A --disable-werror --enable-languages=c,c++ --disable-shared --without-newlib --disable-libgomp --disable-threads
make all-gcc
make install-gcc
cd -

# Build Linux 2.4:
cd build/linux/linux-*
cp -v ../../../config-linux .config
make ARCH=i386 CROSS_COMPILE=i386-linux-uclibc- oldconfig
make ARCH=i386 CROSS_COMPILE=i386-linux-uclibc- dep
make ARCH=i386 CROSS_COMPILE=i386-linux-uclibc- bzImage
cd -

# Build Busybox:
cd build/busybox/busybox-*
cp -v ../../../config-busybox .config
make CROSS_COMPILE=i386-linux-uclibc-
cd -
          


And here is the script to make the root filesystem:

#!/bin/bash
set -e

ROOTFS="`pwd`/rootfs/"

TARGET="i386-linux-uclibc"
PREFIX="${HOME}/opt/gcc-${TARGET}/"
SYSROOT="${PREFIX}/${TARGET}/sysroot"

export PATH="${PREFIX}bin:$PATH"

if [ -d "$ROOTFS" ]; then
  echo "Old root FS directory detected, please remove it."
  exit 1
fi
mkdir -p "$ROOTFS"

# Install Busybox:
cd build/busybox/busybox-*
make CROSS_COMPILE=i386-linux-uclibc- CONFIG_PREFIX="$ROOTFS" install
cd -

# Create some essential directories
cd "$ROOTFS"
mkdir etc
mkdir etc/init.d
mkdir lib
mkdir proc
mkdir sys
mkdir tmp
mkdir root
mkdir dev
mkdir dev/pts
cd -

# Initial rc.S:
cat > rcS <<EOF
#!/bin/sh
mount -t proc /proc /proc
mount -t devpts /dev/pts /dev/pts
mount -t tmpfs /tmp /tmp
loadkmap < /etc/no-latin1.bmap
hostname busybox
EOF
mv -v rcS "$ROOTFS/etc/init.d/"

# Initial inittab:
cat > inittab <<EOF
::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::restart:/sbin/init
EOF
mv -v inittab "$ROOTFS/etc/"

# Copy this system's keymap:
loadkeys -b /usr/share/kbd/keymaps/i386/qwerty/no-latin1.map.gz > "$ROOTFS/etc/no-latin1.bmap"

# Make everything root user:
sudo chown -R root:root "$ROOTFS"

# Create some critical devices:
sudo mknod "$ROOTFS/dev/tty" c 5 0
sudo mknod "$ROOTFS/dev/console" c 5 1
sudo mknod -m 0666 "$ROOTFS/dev/null" c 1 3

# Create some useful devices:
sudo mknod "$ROOTFS/dev/rtc" c 10 135
sudo mknod "$ROOTFS/dev/tty0" c 4 0
sudo mknod "$ROOTFS/dev/tty1" c 4 1
sudo mknod "$ROOTFS/dev/tty2" c 4 2
sudo mknod "$ROOTFS/dev/tty3" c 4 3
sudo mknod "$ROOTFS/dev/ttyS0" c 4 64
sudo mknod "$ROOTFS/dev/ttyS1" c 4 65
sudo mknod "$ROOTFS/dev/fd0" b 2 0
sudo mknod "$ROOTFS/dev/fd1" b 2 1
sudo mknod "$ROOTFS/dev/root" b 4 0
sudo mknod "$ROOTFS/dev/lp0" c 6 0

# SetUID on busybox binary:
sudo chmod +s "$ROOTFS/bin/busybox"

# Make rcS executable:
sudo chmod +x "$ROOTFS/etc/init.d/rcS"

# Make Compressed ROM archive:
mkfs.cramfs rootfs rootfs.cramfs
          


Instead of using LOADLIN, it is actually easy to start this with QEMU as well, like so:

qemu-system-i386 -kernel bzImage -initrd rootfs.cramfs
          


Topic: Configuration, by Kjetil @ 12/09-2020, Article Link

Outlaws in Wine

I have made an effort in getting the classic LucasArts game Outlaws working in Wine with music, which is essential due to its excellent soundtrack. This is a similar to my other effort with M.I.A., except this time the music playback mechanism is more advanced. I had to make additional hacks to the Wine "mcicda" library to make it pause and resume in the middle of tracks.

Here is a rough guide for the commands required for installation. Also, when the installation asks about DirectX 3.0A, just skip this.

mkdir -p ~/opt/outlaws
mkdir ~/opt/outlaws/cd1 # Then copy files from CD1 into here.
mkdir ~/opt/outlaws/cd2 # Then copy files from CD2 into here.
echo "OUTLAWS_1" > ~/opt/outlaws/cd1/.windows-label
echo "OUTLAWS_2" > ~/opt/outlaws/cd2/.windows-label
ln -s "cd1" ~/opt/outlaws/drive_d
WINEARCH=win32 WINEPREFIX=~/opt/outlaws winecfg # D: = "drive_d" = CD-ROM
WINEARCH=win32 WINEPREFIX=~/opt/outlaws wine ~/opt/outlaws/drive_d/SETUP.EXE
          


I had to enable the "Virtual Desktop" setting with "winecfg" for certain stuff like menus to work. I also just configured my X windows resolution to 800x600 before playing the game.

To make the music playback work, a lot of additional steps are required. First the patched "mcicda.dll", which can be downloaded here. This should placed at "~/opt/outlaws/drive_c/windows/system32/mcicda.dll"

Here is the patched code in case you want to compile it yourself, using the Wine 4.0.2 source code as a basis:

--- mcicda.c.orig	2020-08-22 14:22:13.861217377 +0200
+++ mcicda.c	2020-08-22 14:22:18.323217425 +0200
@@ -20,11 +20,21 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#define MPLAYER_FIFO_LOCATION "/tmp/mplayer.fifo"
+#define TOC_FILE_LOCATION "/tmp/toc.txt"
+
 #include "config.h"
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <time.h>
+
 #define WIN32_NO_STATUS
 #include "windef.h"
 #include "winbase.h"
@@ -79,10 +89,211 @@
 typedef HRESULT(WINAPI*LPDIRECTSOUNDCREATE)(LPCGUID,LPDIRECTSOUND*,LPUNKNOWN);
 static LPDIRECTSOUNDCREATE pDirectSoundCreate;
 
+static int mplayer_current_track = 0;
+static int mplayer_current_min   = 0;
+static int mplayer_current_sec   = 0;
+static int mplayer_current_frame = 0;
+static struct timespec mplayer_playback_started = {0,0};
+
+static void mplayer_command(const char *command)
+{
+    int fd, written;
+
+    fd = open(MPLAYER_FIFO_LOCATION, O_NONBLOCK | O_WRONLY);
+    if (fd == -1) {
+        TRACE("No pipe\n");
+        return;
+    }
+
+    written = write(fd, command, strlen(command));
+    if (written <= 0) {
+        TRACE("Write failed\n");
+    }
+
+    close(fd);
+}
+
 static BOOL device_io(HANDLE dev, DWORD code, void *inbuffer, DWORD insize, void *outbuffer, DWORD outsize, DWORD *retsize, OVERLAPPED *overlapped)
 {
     const char *str;
-    BOOL ret = DeviceIoControl(dev, code, inbuffer, insize, outbuffer, outsize, retsize, overlapped);
+
+    int track_no, min, sec, frame;
+    BOOL ret = TRUE;
+    CDROM_TOC *toc;
+    CDROM_SUB_Q_DATA_FORMAT *qfmt;
+    SUB_Q_CHANNEL_DATA *qdata;
+    FILE *fh;
+    char buf[16];
+    struct timespec now;
+
+    *retsize = 0;
+
+    switch (code) {
+    case IOCTL_CDROM_READ_TOC:
+        toc = (CDROM_TOC *)outbuffer;
+        *retsize = CDROM_TOC_SIZE;
+
+        toc->Length[0] = 0;
+        toc->Length[1] = 0;
+        toc->FirstTrack = 1;
+        toc->LastTrack = 1;
+
+        // Set up first track as data track.
+        toc->TrackData[0].TrackNumber = 1;
+        toc->TrackData[0].Control = 0x4;
+        toc->TrackData[0].Address[1] = 0;
+        toc->TrackData[0].Address[2] = 0;
+        toc->TrackData[0].Address[3] = 0;
+
+        // Get other audio tracks from toc file.
+        fh = fopen(TOC_FILE_LOCATION, "r");
+        if (fh == NULL) {
+          TRACE("IOCTL_CDROM_READ_TOC, Failed to open: %s\n", TOC_FILE_LOCATION);
+          break;
+        }
+
+        while (fgets(buf, sizeof(buf), fh) != NULL)
+        {
+          sscanf(buf, "%02d:%02d:%02d", &min, &sec, &frame);
+
+          toc->TrackData[toc->LastTrack].TrackNumber = toc->LastTrack + 1;
+          toc->TrackData[toc->LastTrack].Control = 0;
+          toc->TrackData[toc->LastTrack].Address[1] = min;
+          toc->TrackData[toc->LastTrack].Address[2] = sec;
+          toc->TrackData[toc->LastTrack].Address[3] = frame;
+
+          toc->LastTrack++;
+
+          TRACE("IOCTL_CDROM_READ_TOC, Track %d = %02d:%02d:%02d\n", toc->LastTrack, min, sec, frame);
+        }
+
+        toc->LastTrack--; // Remove the last dummy track:
+
+        fclose(fh);
+        break;
+
+    case IOCTL_CDROM_STOP_AUDIO:
+        mplayer_command("stop\n");
+        break;
+
+    case IOCTL_CDROM_PAUSE_AUDIO:
+        mplayer_command("stop\n");
+        break;
+
+    case IOCTL_CDROM_READ_Q_CHANNEL:
+        qfmt  = (CDROM_SUB_Q_DATA_FORMAT *)inbuffer;
+        qdata = (SUB_Q_CHANNEL_DATA *)outbuffer;
+        *retsize = sizeof(SUB_Q_CHANNEL_DATA);
+
+        if (qfmt->Format == IOCTL_CDROM_CURRENT_POSITION)
+        {
+            qdata->CurrentPosition.FormatCode = IOCTL_CDROM_CURRENT_POSITION;
+            qdata->CurrentPosition.Control = 0;
+            qdata->CurrentPosition.ADR = 0;
+            qdata->CurrentPosition.TrackNumber = mplayer_current_track;
+            qdata->CurrentPosition.IndexNumber = 0;
+
+            clock_gettime(CLOCK_MONOTONIC, &now);
+            TRACE("IOCTL_CDROM_READ_Q_CHANNEL, Started = %lu.%lu\n",
+                mplayer_playback_started.tv_sec, mplayer_playback_started.tv_nsec);
+            TRACE("IOCTL_CDROM_READ_Q_CHANNEL, Now = %lu.%lu\n", now.tv_sec, now.tv_nsec);
+
+            min = (now.tv_sec - mplayer_playback_started.tv_sec) / 60;
+            sec = (now.tv_sec - mplayer_playback_started.tv_sec) % 60;
+            frame = (now.tv_nsec - mplayer_playback_started.tv_nsec);
+            if (frame < 0) {
+                frame = 0 - frame;
+                sec--;
+                if (sec < 0) {
+                  sec = 59;
+                  min--;
+                }
+            }
+            frame = (frame / 10000000) * 0.75;
+
+            if (mplayer_current_min > 0 ||
+                mplayer_current_sec > 0 ||
+                mplayer_current_frame > 0)
+            {
+                min += mplayer_current_min;
+                sec += mplayer_current_sec;
+                if (sec >= 60) {
+                    sec -= 60;
+                    min++;
+                }
+                frame += mplayer_current_frame;
+                if (frame >= 76) {
+                    frame -= 76;
+                    sec++;
+                    if (sec >= 60) {
+                        sec -= 60;
+                        min++;
+                    }
+                }
+            }
+
+            qdata->CurrentPosition.TrackRelativeAddress[0] = 0;
+            qdata->CurrentPosition.TrackRelativeAddress[1] = min;
+            qdata->CurrentPosition.TrackRelativeAddress[2] = sec;
+            qdata->CurrentPosition.TrackRelativeAddress[3] = frame;
+
+            qdata->CurrentPosition.AbsoluteAddress[0] = 0;
+            qdata->CurrentPosition.AbsoluteAddress[1] = min;
+            qdata->CurrentPosition.AbsoluteAddress[2] = sec;
+            qdata->CurrentPosition.AbsoluteAddress[3] = frame;
+
+            fh = fopen(TOC_FILE_LOCATION, "r");
+            if (fh == NULL) {
+              TRACE("IOCTL_CDROM_READ_Q_CHANNEL, Failed to open: %s\n", TOC_FILE_LOCATION);
+              break;
+            }
+
+            track_no = 2;
+            while (fgets(buf, sizeof(buf), fh) != NULL)
+            {
+                if (track_no == mplayer_current_track) {
+                    sscanf(buf, "%02d:%02d:%02d", &min, &sec, &frame);
+                    qdata->CurrentPosition.AbsoluteAddress[1] += min;
+                    qdata->CurrentPosition.AbsoluteAddress[2] += sec;
+                    if (qdata->CurrentPosition.AbsoluteAddress[2] >= 60) {
+                        qdata->CurrentPosition.AbsoluteAddress[2] -= 60;
+                        qdata->CurrentPosition.AbsoluteAddress[1]++;
+                    }
+                    qdata->CurrentPosition.AbsoluteAddress[3] += frame;
+                    if (qdata->CurrentPosition.AbsoluteAddress[3] >= 76) {
+                        qdata->CurrentPosition.AbsoluteAddress[3] -= 76;
+                        qdata->CurrentPosition.AbsoluteAddress[2]++;
+                        if (qdata->CurrentPosition.AbsoluteAddress[2] >= 60) {
+                            qdata->CurrentPosition.AbsoluteAddress[2] -= 60;
+                            qdata->CurrentPosition.AbsoluteAddress[1]++;
+                        }
+                    }
+                    break;
+                }
+                track_no++;
+            }
+
+            fclose(fh);
+
+            TRACE("IOCTL_CDROM_READ_Q_CHANNEL, Current Track = %d\n", mplayer_current_track);
+            TRACE("IOCTL_CDROM_READ_Q_CHANNEL, Rel Pos = %02d:%02d:%02d\n",
+                qdata->CurrentPosition.TrackRelativeAddress[1],
+                qdata->CurrentPosition.TrackRelativeAddress[2],
+                qdata->CurrentPosition.TrackRelativeAddress[3]);
+            TRACE("IOCTL_CDROM_READ_Q_CHANNEL, Abs Pos = %02d:%02d:%02d\n",
+                qdata->CurrentPosition.AbsoluteAddress[1],
+                qdata->CurrentPosition.AbsoluteAddress[2],
+                qdata->CurrentPosition.AbsoluteAddress[3]);
+        }
+        else
+        {
+           TRACE("IOCTL_CDROM_READ_Q_CHANNEL, Unknown format: %d\n", qfmt->Format);
+        }
+        break;
+
+    default:
+        break;
+    }
 
 #define XX(x) case (x): str = #x; break
     switch (code)
@@ -906,6 +1117,9 @@
     SUB_Q_CHANNEL_DATA          data;
     CDROM_TOC			toc;
 
+    int track_no, min, sec, frame;
+    char command[PATH_MAX];
+
     TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
 
     if (lpParms == NULL)
@@ -914,6 +1128,35 @@
     if (wmcda == NULL)
 	return MCIERR_INVALID_DEVICE_ID;
 
+    mplayer_command("stop\n");
+
+    track_no = MCI_TMSF_TRACK(lpParms->dwFrom);
+    min      = MCI_TMSF_MINUTE(lpParms->dwFrom);
+    sec      = MCI_TMSF_SECOND(lpParms->dwFrom);
+    frame    = MCI_TMSF_FRAME(lpParms->dwFrom);
+    TRACE("Track no: %d (%02d:%02d:%02d)\n", track_no, min, sec, frame);
+
+    snprintf(command, PATH_MAX, "loadfile track%02d.flac\n", track_no);
+    mplayer_command(command);
+
+    mplayer_current_track = track_no;
+    clock_gettime(CLOCK_MONOTONIC, &mplayer_playback_started);
+
+    if (min > 0 || sec > 0 || frame > 0) {
+      mplayer_current_min = min;
+      mplayer_current_sec = sec;
+      mplayer_current_frame = frame;
+
+      sec += (min * 60);
+      frame *= 1.333333;
+      TRACE("Seek to: %d.%02d\n", sec, frame);
+
+      snprintf(command, PATH_MAX, "seek %d.%02d 2\n", sec, frame);
+      mplayer_command(command);
+    }
+
+    return 0; // Because of hijacking, this ends here.
+
     if (!MCICDA_ReadTOC(wmcda, &toc, &br))
         return MCICDA_GetError(wmcda);
          


To make music playback work as painlessly as possible, I have once again made a script to start the game:

#!/bin/sh
export WINEPREFIX=~/opt/outlaws

MPLAYER_FIFO=/tmp/mplayer.fifo
TOC_FILE=/tmp/toc.txt
MPLAYER_PID_FILE=/tmp/mplayer.pid

function mplayer_stop {
  if [ -f "$MPLAYER_PID_FILE" ]; then
    kill `cat "$MPLAYER_PID_FILE"`
    rm -f "$MPLAYER_PID_FILE"
  fi
  rm -f "$MPLAYER_FIFO"
}

function mplayer_start {
  if [ ! -p "$MPLAYER_FIFO" ]; then
    mkfifo "$MPLAYER_FIFO"
  fi
  cd "${WINEPREFIX}/drive_d"
  mplayer -vo null -idle -slave -input file=$MPLAYER_FIFO 1&>/dev/null &
  echo "$!" > "$MPLAYER_PID_FILE"
  cd -
}

CD_NO="0"
while [ "$CD_NO" != "1" ] && [ "$CD_NO" != "2" ]; do
  read -p "CD number? [1 or 2] " CD_NO
done

MODE="0"
while [ "$MODE" != "g" ] && [ "$MODE" != "c" ]; do
  read -p "Start [g]ame or [c]hange CD only? " MODE
done

mplayer_stop

rm -f "${WINEPREFIX}/drive_d"
ln -s "cd$CD_NO" "${WINEPREFIX}/drive_d"
cp "${WINEPREFIX}/drive_d/toc.txt" "$TOC_FILE"

mplayer_start

if [ "$MODE" == "c" ]; then
  # If only changing CD, exit now.
  exit 0
fi

(cd "${WINEPREFIX}/drive_c/Program Files/LucasArts/Outlaws" && WINEARCH=win32 wine OLWIN.EXE)

mplayer_stop
rm -f "$TOC_FILE"
          

The same script is also used to change the CD while the game is running, as this is required in some instances.

The CD audio tracks should be ripped to FLAC format and be placed as track02.flac to track08.flac in "~/opt/outlaws/cd1/" for CD1, followed by track02.flac to track09.flac in "~/opt/outlaws/cd2/" for CD2. In addition, you will need a couple of "Table of Contents" files for each CD. These will inform the patched "mcicda.dll" file about the length of each track.

Put the following in "~/opt/outlaws/cd1/toc.txt"

00:00:00
03:16:64
07:34:64
11:23:01
15:13:33
19:58:24
23:39:66
27:15:61
          


Put the following in "~/opt/outlaws/cd2/toc.txt"

00:00:00
04:42:15
10:16:03
13:41:47
20:55:08
24:58:10
30:09:45
33:50:23
36:16:17
          


Enjoy!

Topic: Configuration, by Kjetil @ 24/08-2020, Article Link

M.I.A. in Wine

M.I.A.: Missing In Action is a relatively unknown game that came out for Windows back in 1998. I got the game back then in my childhood as part of some bundle with a new computer. I do remember the game being fun, but I had issues getting it to run later on because it will only install on Windows 98. Fast forward some 20 years, Wine has now become a better Windows than Windows on Linux in many aspects, especially running older games.
I have been using Wine version 4.0.2 for these experiments.

Using some tricks I finally got to run and play this on Linux! In order to get there I had do spend some time with both Winedbg and OllyDbg debuggers to figure out what the game tried to do and failed on.

The first problem was the detection of the CDs, which I figured out it does by calling GetVolumeInformationA() and looking at the volume label. This is fixed by creating a ".windows-label" file in the emulated CD drive with the correct label.

The second problem was getting the CD audio to work correctly. Apart from having to fake this somehow, the game uses the ancient Media Control Interface which still have some missing features (bugs?) in Wine at the time of writing. Maybe this will be fixed in an upcoming version, but I had no time to wait for that. The root of the problem is that Wine returns the code (as string) "1088" instead of the string "audio" when the game asks what type of track is on the CD. The quickest way to fix this is to simply patch the game binary to look for that other string.

To actually play the CD audio without the CDs I figured out it was easiest to hack the Wine "mcicda.dll" library and make it call MPlayer to play the tracks as .FLAC files. This is done in MPlayer's FIFO mode to avoid blocking anything.

A third problem is that the in-game video cutscenes, using Smacker Video Technology still does not play correctly in Wine. The symptom is that the video may play for some seconds, but then just hangs. Since it's possible to bypass this by hitting Escape, I have simply ignored this for now.

Anyway, the common steps to install and run are as follows:
1) Create a new directory to store a Wine prefix for M.I.A.:
mkdir -p ~/opt/mia
2) Run winecfg on the prefix, in 32-bit mode, and set it has "Windows 98":
WINEARCH=win32 WINEPREFIX=~/opt/mia winecfg
3) Create two directories for each M.I.A. CD in the prefix:
mkdir ~/opt/mia/cd1
mkdir ~/opt/mia/cd2
4) Copy the CD contents into the respective directories.
Either directly from the CDs or ISO images mounted as loopback devices.
5) Create fake volume labels for each CD, as needed by the game:
echo "MIA_VOL1" > ~/opt/mia/cd1/.windows-label
echo "MIA_VOL2" > ~/opt/mia/cd2/.windows-label
6) Create a symbolic link kalled "drive_d" pointing to "cd1"
ln -s "cd1" ~/opt/mia/drive_d
7) Run winecfg again to map D: to the newly created "drive_d" directory.
Also set the type as "CD-ROM".
WINEARCH=win32 WINEPREFIX=~/opt/mia winecfg
8) Allow low memory to be mapped, since it is needed by M.I.A. installer.
sudo sysctl vm.mmap_min_addr=0
9) Start the M.I.A. installation through Wine,
WINEARCH=win32 WINEPREFIX=~/opt/mia wine ~/opt/mia/drive_d/mia.exe
10) When prompted for installation of installation type...
Select "Leave ground textures on CD".
This is needed because the installer has issues finding CD #2.
11) Run the following script to easily start the game:

#!/bin/sh
export WINEPREFIX=~/opt/mia

sudo sysctl vm.mmap_min_addr=0 # Wine needs to be allowed to map low memory.

CD_NO=0
while [ "$CD_NO" != "1" ] && [ "$CD_NO" != "2" ]; do
  read -p "CD Number? (1 or 2) " CD_NO
done

rm -f "${WINEPREFIX}/drive_d"
ln -s "cd$CD_NO" "${WINEPREFIX}/drive_d"

(cd "${WINEPREFIX}/drive_c/MIA" && WINEARCH=win32 wine miarel.exe -avhpd)
          


If you also want the in-game music, some additional steps are required:
12) Assuming all tracks are ripped from the CD's in FLAC format.
4 audio tracks from CD #1 named from "track02.flac" to "track05.flac".
5 audio tracks from CD #2 mamed from "track02.flac" to "track06.flac".
Copy .flac files into the root of each respective directory "cd1" and "cd2".
13) Patch the "mcicda.dll" file in ~/opt/mia/drive_c/windows/system32/
14) Patch the "miarel.exe" file in ~/opt/mia/drive_c/MIA/
15) Run the following modified script to start the game:

#!/bin/sh
export WINEPREFIX=~/opt/mia

MPLAYER_FIFO=/tmp/mplayer.fifo # Do not change, hardcoded in patched mcicda.dll

sudo sysctl vm.mmap_min_addr=0 # Wine needs to be allowed to map low memory.

CD_NO=0
while [ "$CD_NO" != "1" ] && [ "$CD_NO" != "2" ]; do
  read -p "CD Number? (1 or 2) " CD_NO
done

rm -f "${WINEPREFIX}/drive_d"
ln -s "cd$CD_NO" "${WINEPREFIX}/drive_d"

if [ ! -p "$MPLAYER_FIFO" ]; then
  mkfifo "$MPLAYER_FIFO"
fi

cd "${WINEPREFIX}/drive_d"
mplayer -idle -slave -input file=$MPLAYER_FIFO 1&>/dev/null &
MPLAYER_PID=$!
cd -

(cd "${WINEPREFIX}/drive_c/MIA" && WINEARCH=win32 wine miarel.exe -avhpd)

kill $MPLAYER_PID
rm -f "$MPLAYER_FIFO"
          


To patch "miarel.exe", open it in a hex-editor and go to offset 0x1427c4. At this location the string "audio" should be present. Replace this with 0x31 0x30 0x38 0x38 0x00 which represents the string "1088" with an additional NULL terminator.

Patching "mcicda.dll" is more complicated as it requires a rebuild of Wine. Get the Wine source code and apply the following source code patch to "./dlls/mcicda/mcicda.c":

--- mcicda.c.orig	2020-05-13 17:55:02.433346437 +0200
+++ mcicda.c	2020-05-13 17:54:53.230346338 +0200
@@ -25,6 +25,12 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+
 #define WIN32_NO_STATUS
 #include "windef.h"
 #include "winbase.h"
@@ -79,10 +85,72 @@
 typedef HRESULT(WINAPI*LPDIRECTSOUNDCREATE)(LPCGUID,LPDIRECTSOUND*,LPUNKNOWN);
 static LPDIRECTSOUNDCREATE pDirectSoundCreate;
 
+static void mplayer_command(const char *command)
+{
+    int fd, written;
+
+    fd = open("/tmp/mplayer.fifo", O_NONBLOCK | O_WRONLY);
+    if (fd == -1) {
+        TRACE("No pipe\n");
+        return;
+    }
+
+    written = write(fd, command, strlen(command));
+    if (written <= 0) {
+        TRACE("Write failed\n");
+    }
+
+    close(fd);
+}
+
 static BOOL device_io(HANDLE dev, DWORD code, void *inbuffer, DWORD insize, void *outbuffer, DWORD outsize, DWORD *retsize, OVERLAPPED *overlapped)
 {
     const char *str;
-    BOOL ret = DeviceIoControl(dev, code, inbuffer, insize, outbuffer, outsize, retsize, overlapped);
+//    BOOL ret = DeviceIoControl(dev, code, inbuffer, insize, outbuffer, outsize, retsize, overlapped);
+
+    int i;
+    BOOL ret = TRUE;
+    CDROM_TOC *toc;
+
+    *retsize = 0;
+
+    switch (code) {
+    case IOCTL_CDROM_READ_TOC:
+        toc = (CDROM_TOC *)outbuffer;
+
+        toc->FirstTrack = 1;
+        toc->LastTrack = 6;
+
+        // Set up first track as data track.
+        toc->TrackData[0].TrackNumber = 1;
+        toc->TrackData[0].Control = 0x4;
+        toc->TrackData[0].Address[1] = 0;
+        toc->TrackData[0].Address[2] = 0;
+        toc->TrackData[0].Address[3] = 0;
+
+        // Set up remaining tracks as dummy audio tracks.
+        for (i = 1; i < toc->LastTrack; i++) {
+            toc->TrackData[i].TrackNumber = i + 1;
+            toc->TrackData[i].Control = 0;
+            toc->TrackData[i].Address[1] = i;
+            toc->TrackData[i].Address[2] = 0;
+            toc->TrackData[i].Address[3] = 0;
+        }
+
+        *retsize = CDROM_TOC_SIZE;
+        break;
+
+    case IOCTL_CDROM_STOP_AUDIO:
+        mplayer_command("stop\n");
+        break;
+
+    case IOCTL_CDROM_PAUSE_AUDIO:
+        mplayer_command("stop\n");
+        break;
+
+    default:
+        break;
+    }
 
 #define XX(x) case (x): str = #x; break
     switch (code)
@@ -906,6 +974,9 @@
     SUB_Q_CHANNEL_DATA          data;
     CDROM_TOC			toc;
 
+    int track_no;
+    char command[PATH_MAX];
+
     TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
 
     if (lpParms == NULL)
@@ -914,6 +985,20 @@
     if (wmcda == NULL)
 	return MCIERR_INVALID_DEVICE_ID;
 
+    // HIJACK START
+
+    mplayer_command("stop\n");
+
+    track_no = MCI_TMSF_TRACK(lpParms->dwFrom);
+    TRACE("Track no: %d\n", track_no);
+
+    snprintf(command, PATH_MAX, "loadfile track%02d.flac\n", track_no);
+    mplayer_command(command);
+
+    return 0;
+
+    // HIJACK END
+
     if (!MCICDA_ReadTOC(wmcda, &toc, &br))
         return MCICDA_GetError(wmcda);
          

To build the DLL file, it should be enough to run ./configure and make on the Wine source code. The resulting file will be named "mcicda.dll.so" but can be renamed to "mcicda.dll".

Topic: Configuration, by Kjetil @ 24/05-2020, Article Link

Dell 2005FPW Display Resolution Fix

I have an old Dell 2005FPW LCD display from around 2005. I had some problems getting this to display the native 1680x1050 resolution in Linux. Instead it would always want to display 1280x1024, and everything would look ugly. The cause of this seems to be bad EDID data being sent by the monitor, because I managed to fix it by manually creating a EDID firmware file with a resolution of 1680x1050 and the refresh rate forced to 59Hz, instead of the more common 60Hz.

There is a nice piece of software here on GitHub to create EDID firmware files from X modeline configuration. I used this together with this handy Online modeline generator.

Here is the modeline generated from the online tool:

# 1680x1050 @ 59.00 Hz (GTF) hsync: 64.07 kHz; pclk: 144.55 MHz
Modeline "1680x1050_59.00" 144.55 1680 1784 1968 2256 1050 1051 1054 1086 -HSync +Vsync
          


I had to trim away the excess ".00" from the string, or else the EDID firwmare file would be too big, 131 bytes instead of 128 bytes, so this should be the actual input to the 'modeline2edid' tool in the EDID generator package:

Modeline "1680x1050_59" 144.55 1680 1784 1968 2256 1050 1051 1054 1086 -HSync +Vsync
          


For reference, here is a hexdump of the newly created EDID firmware:

00000000  00 ff ff ff ff ff ff 00  31 d8 00 00 00 00 00 00  |..1......|
00000010  05 16 01 03 6d 2b 1b 78  ea 5e c0 a4 59 4a 98 25  |....m+.x^YJ.%|
00000020  20 50 54 00 00 00 b3 00  01 01 01 01 01 01 01 01  | PT............|
00000030  01 01 01 01 01 01 77 38  90 40 62 1a 24 40 68 b8  |......w8.@b.$@h|
00000040  13 00 b5 11 11 00 00 1e  00 00 00 ff 00 4c 69 6e  |...........Lin|
00000050  75 78 20 23 30 0a 20 20  20 20 00 00 00 fd 00 3b  |ux #0.    ....;|
00000060  3d 3f 41 0f 00 0a 20 20  20 20 20 20 00 00 00 fc  |=?A...      ...|
00000070  00 31 36 38 30 78 31 30  35 30 5f 35 39 0a 00 e1  |.1680x1050_59..|
          


The file needs to be loaded by putting it in /lib/firmware/edid/ and adding this to the Linux boot kernel parameters:

drm.edid_firmware=edid/1680x1050.bin
          


After this, the resolution became correct in both the framebuffer console and X on the computer where I use this LCD display. The computer has a NVIDIA GeForce FX 5200 graphics gard with the "nouveau" driver in use.

Topic: Configuration, by Kjetil @ 02/04-2020, Article Link

Linux Distribution for 386SX

I have a Commodore PC 50-II system with a Intel 386SX CPU running at 16MHz and only 5MB of RAM, in addition, the harddrive controller and harddrive is also missing. To get around this, I have installed a 3Com 3C509B-TPO ISA Network card and have managed to boot Linux on this ancient PC over the network instead.

At first I tried to use Buildroot, but I had to give up on this in the end, as it seems that pure 386 is not supported anywhere anymore. So instead, I have gone the route of building everything from scratch, so I could pick and choose specific source versions of GCC and the Linux kernel that supports 386 with math emulation. The end result is a cross-compiling toolchain for i386, a stripped down kernel and Busybox-based rootfs mounted over NFS from another host computer.

I ended up using these specific software versions:
* linux-2.4.37.9
* gcc-3.4.6
* busybox-1.01
* uClibc-0.9.33.2
* binutils-2.32

I also had to statically link everything. I tried with dynamic linking in the beginning but the system would hang during boot, and I didn't want to troubleshoot this any further.

I have made some scripts to greatly simplify the whole process of building the cross-compiling toolchain and all the binaries. Bundled in a file here.

Unpack this into a directory and then simply run the following:

./build.sh
./rootfs.sh
          

I have used these on a Slackware 14.2 box with GCC 5.3.0
The result will be a directory with the "rootfs" and a "bzImage" located inside the kernel build tree.

The rootfs is exported over NFS in /etc/exports like this:

/home/nfs/rootfs *(rw,sync,no_root_squash,no_all_squash,no_subtree_check)
          

Also note that the legacy NFSv2 protocol needs to be actived!

To prepare the kernel is the tricky part. To load it over TFTP with Etherboot you have to use the mkelf-linux script from the mknbi package. This package is not compilable on modern Linux distributions, so I ended up compiling and using it from an old Slackware 11.0 installation running in a QEMU virtual machine.

I used the command as follows:

mkelf-linux --output=pc50linux.nb --ip="192.168.0.3:192.168.0.2:192.168.0.1:255.255.255.0:pc50" --append="root=/dev/nfs nfsroot=/home/nfs/rootfs" bzImage
          

Where .3 is the booted client PC, .2 is the NFS server and .1 is the gateway and TFTP server.

The final step is to activate the TFTP/DHCP server. I used dnsmasq for this, with the following relevant configuration:

dhcp-host=00:ff:ff:ff:ff:ff,192.168.0.3,infinite,set:pxelinux
enable-tftp
tftp-root=/var/ftpd
dhcp-boot=net:pxelinux,/var/ftpd/pc50linux.nb,boothost,192.168.0.1
          


Some additional information: I have no Boot ROM on the Ethernet card, so I used a floppy disk to actually kick-start the network booting. More specifically, the "3c509.dsk" image made from compiling parts of the "Etherboot" package. Since this also isn't compilable on modern distributions, I had to use the Slackware 11.0 QEMU virtual machine again.

Commodore PC 50-II


Topic: Configuration, by Kjetil @ 01/12-2019, Article Link

Older articles