Porting Linux to the Sega MegaDrive via Mega EverDrive Hardware Extensions
A new open-source project, LinuxMD, ports the Linux kernel to the Motorola 68000-based Sega MegaDrive. The implementation bypasses the console's severe memory limitations by targeting the hardware extensions of the Mega EverDrive flash cartridge.
Hardware Requirements and Architectural Constraints
The stock Sega MegaDrive possesses only 64 KiB of main RAM, which is insufficient to host a modern monolithic kernel. To overcome this limitation, the LinuxMD project targets the console paired with a Mega EverDrive Core or Pro flash cartridge.
- An SSF2 mapper that exposes 4 MiB of pseudo-SRAM to the Motorola 68000 CPU.
- A hardware timer register utilized as the system's primary clocksource.
- An SD card interface protocol for block-level storage access.
Standard Sega MegaDrive emulators cannot run this port because they lack support for these proprietary cartridge-side features. To facilitate development without physical hardware, the project includes a custom fork of QEMU that emulates the EverDrive's mapper, storage protocol, and timer register.
Toolchain and Compilation Pipeline
The software stack is compiled using a custom-built m68k-linux toolchain. This toolchain is generated via Buildroot, targeting the flat-model (no-MMU) execution environment of the Motorola 68000.
- `buildtoolchain.sh`: Configures and builds the m68k-linux-gcc toolchain.
- `builduboot.sh`: Compiles a customized U-Boot bootloader.
- `buildlinux.sh`: Compiles the Linux kernel, producing an LZ4-compressed image.
- `buildrootfs.sh`: Packages the root filesystem into an EROFS image.
- `buildmedtool.sh`: Compiles the host-side utility (`medtool`) used to communicate with the EverDrive's USB debug interface.
Boot Sequence and Memory Map
The host system connects to the EverDrive via a USB-to-serial interface, which registers as a CDC ACM device (`ttyACM0`). The `medtool` utility establishes a terminal session over a UNIX socket, allowing tools like minicom to capture console output.
Upon launching `u-boot.bin` from the EverDrive menu, U-Boot initializes the system's 3.8 MiB of usable DRAM. It then loads the compressed kernel (`vmlinux.lz4`) and the EROFS root filesystem image (`m68k.erofs`) from the SD card.
- Architecture: Flat-model support (no-MMU) running on a generic device tree machine.
- CPU performance: Calibrated at 0.72 BogoMIPS.
- Memory Allocation: Out of 4096 KiB total, 2532 KiB is available to the user space. The kernel code occupies 1002 KiB, while 1368 KiB is reserved. No kernel memory protection is enforced due to the lack of an MMU.
- Console Routing: Kernel console messages are multiplexed to `ttyVDP0` (using the MegaDrive's Video Display Processor for on-screen rendering) and `ttyED0` (routing back over the EverDrive's serial link).
Filesystem Mount and Initialization
Storage virtualization is handled by a custom FIFO communication thread and block driver (`everdrive-blk`). This driver registers a block device (`edblk`) of 90,112 bytes to expose the `m68k.erofs` image stored on the cartridge.
The kernel mounts this EROFS root filesystem as a read-only device. Once mounted, the virtual filesystem pivots into the new root and launches the first user-space process: a lightweight init system from `smolutils` located at `/sbin/init`.