Linux for the Sega MegaDrive

Linux for the Sega MegaDrive

Linux successfully ported to Sega MegaDrive

The LinuxMD project has achieved a functional port of the Linux kernel to the Sega MegaDrive (known as the Sega Genesis in North America). This feat is made possible by using a Mega EverDrive Core or Pro cartridge to bypass the console's native memory limitations, providing the 4MB of RAM necessary to boot the kernel and a basic root filesystem.

Hardware Requirements and Memory Architecture

Running Linux on a MegaDrive requires specific hardware to overcome the system's original memory constraints. The standard MegaDrive does not have sufficient RAM to host a modern kernel, so the project relies on the following:

  • Sega MegaDrive Console: The target hardware.
  • Mega EverDrive Core or Pro: This cartridge is critical because it provides a special SSF2 mapper that grants the system 4MB of RAM, as well as a timer register and a protocol for loading files from an SD card.
  • USB Connection: A USB cable between the EverDrive and a PC is required for serial console interaction.

Because the MegaDrive's Motorola 68000 CPU lacks a Memory Management Unit (MMU), the project utilizes a kernel compiled with the -nommu option. This allows Linux to run on hardware that cannot support virtual memory, a configuration often used for embedded systems with limited resources.

Boot Process and Toolchain

Booting Linux on the MegaDrive involves a multi-stage process utilizing a custom toolchain and bootloader:

  1. Toolchain: The project uses Buildroot to create an m68k-linux toolchain capable of producing binaries for the 68000 CPU.
  2. Bootloader: U-Boot is used as the primary bootloader to load the kernel image (vmlinux.lz4) and the root filesystem (m68k.erofs) from the EverDrive's SD card.
  3. Kernel: The system boots a version of the Linux kernel (e.g., version 7.1.0-rc6) configured for the MegaDrive's specific architecture.
  4. Root Filesystem: A minimal rootfs is built using the EROFS filesystem, providing basic utilities via smolutils and the smolsh shell.

System Output and Interface

While the system can be managed via a serial console through medtool and minicom on a connected PC, the project includes a native video output implementation:

  • VDP Console: A custom console that utilizes the MegaDrive's Video Display Processor (VDP) to render text and system status directly to a television.
  • Visual Indicators: The VDP console features a green "heartbeat" box in the top right corner to indicate the kernel is running and a red box to signal disk activity.

Performance and Emulation

Currently, the system is noted to be "insanely slow," with the author stating that a standalone 12MHz 68000 system is more usable than the MegaDrive implementation. This is largely due to the slow interaction speeds with the EverDrive FIFO.

For those without the physical hardware, the project includes a fork of QEMU that emulates the MegaDrive and the EverDrive's specific mapper and timer, though the author notes that QEMU emulates the CPU too quickly to accurately reflect the real-world "feel" of the system.

Community Insights

Technical observers have highlighted the significance of the -nommu kernel configuration, as many previously believed the lack of an MMU made running Linux on such consoles impossible.

"The lowly 68000 in the Sega doesn’t have a memory management unit required for the full Linux experience, so what’s really running here is a kernel compiled with the -nommu option."

Other community members noted the historical symmetry of the project, pointing out that the MegaDrive's CPU loadout (68000 and Z80) mirrors that of early Unix machines like the TRS-80 Model 16.

Sources