Linux for the Sega MegaDrive

Linux for the Sega MegaDrive

The LinuxMD project has successfully ported the Linux kernel to the Sega MegaDrive (known as the Sega Genesis in North America). This achievement is made possible by utilizing a Mega EverDrive cartridge to bypass the console's native memory limitations and provide the necessary hardware environment for a modern kernel to boot.

Hardware Requirements and Memory Management

Running Linux on a Sega MegaDrive requires specific hardware to expand the system's capabilities beyond its original 1980s specifications. The project relies on the Mega EverDrive Core or Pro cartridge, which provides Portability of the system's capabilities beyond its original 1980s specifications. The project relies on the Mega EverDrive Core or Pro cartridge, which provides 4MB of RAM via a special SSF2 mapper. This is critical because the native MegaDrive RAM is insufficient for the Linux kernel.

Key hardware requirements include:

  • A Sega MegaDrive/Genesis console.
  • A Mega EverDrive Core or Pro cartridge.
  • A USB cable connecting the EverDrive to a PC for serial console access.

Because the Motorola 68000 CPU in the MegaDrive lacks a Memory Management Unit (MMU), the project uses a kernel compiled with the -nommu option. This allows Linux to run in a flat memory model, which is the only way to execute the kernel on hardware without hardware-level memory protection.

Software Stack and Build Process

The LinuxMD environment is built using a combination of a custom toolchain, a bootloader, and a lightweight root filesystem. The build process involves several distinct stages:

  1. Toolchain: Built using Buildroot to create an m68k-linux toolchain capable of producing binaries for the 68000 CPU.
  2. Bootloader: Uses U-Boot to handle the initial loading of the kernel image.
  3. Kernel: A Linux kernel image (vmlinux.lz4) is compiled and loaded.
  4. Root Filesystem: An erofs image containing smolutils is used as the rootfs.
  5. Utility Tools: A custom tool called medtool is used to interact with the EverDrive for serial console communication.

For those without the physical hardware, the project includes a QEMU fork that emulates the MegaDrive and the EverDrive's specific mapper and timer registers, though the author notes that QEMU emulates the CPU significantly faster than the real hardware.

System Performance and Interface

While functional, this port currently faces significant performance bottlenecks. The author notes that system is "insanely slow," particularly when interacting with the EverDrive FIFO, and suggests that further optimization is required.

Despite the performance issues, the project implements two primary ways to interact with the system:

  • Serial Console: Accessed via a USB connection to a PC using medtool and minicom.
  • VDP Console: A custom console that utilizes the MegaDrive's native video output. This interface includes a "heartbeat" green box to indicate the kernel is running and a red box to indicate disk activity.

Community Insights and Technical Context

Technical discussions surrounding the complexity of the project highlight the historical and architectural curiosity of the port. Community members noted the similarity between the MegaDrive's CPU loadout (Motorola 68000 and Z80) and early Unix machines like the TRS-80 Model 16.

Regarding the console's memory constraints, one contributor observed:

"I was wondering how it was squeezed into 64KB of RAM but it uses the 4MB on the Everdrive cart. With that it makes sense, considering Linux can run on an N64 with 4MB of RAM."

Another user pointed out the specific architectural limitation regarding the MMU:

"The lowly 68000 68000 in the Sega is doesn't have a

MMU required for the full Linux experience, so what's really running here is a kernel compiled with the -nommu option."",

Sources