March 13, 2022

Hacking the Game & Watch on Gentoo

by orzel
Categories: Gentoo
Tags: , , ,
Comments: Leave a Comment

At the end of 2020, Nintendo has released a new version of his famous “Game & Watch” mini console. It looks like the old-school one, but has a real screen (with pixels, even color !), a modern microcontroller (a beefy STM32) and three mini-games, only one of which is actually a previous G&W.

The MCU is duly locked, but some smart people quickly found a way to unlock it. And then, they went on porting retro-go, which is a collection of emulators. As a result, you can play a lot of retro games on this console.

I’m not into games, let alone retro games. But a friend of mine has such a console, have seen the youtube video about the hack, and is like “I WANT THAT !!! DO SOMETHING !!”. So here it is.

The two main sources of code and documentation are:

https://github.com/ghidraninja/game-and-watch-backup : unlocking the MCU (and backup the original flash image)

https://github.com/kbeckmann/game-and-watch-retro-go : port of retro-go

This post is about how to apply this to gentoo, the problems encountered, and the fixes I’ve used.

Unlocking the MCU

First, you’ll need some software installed. Like the proper cross-toolchain for the stm32 target and openocd. It goes along:

emerge -u sys-devel/crossdev
crossdev arm-none-eabi
emerge dev-embedded/openocd

The scripts on github expects some fairly recent toolchain and openocd, but a current ~amd64 is uptodate enough. I dont know about “stable” Gentoo “amd64”.

I’ve then had two problems.

First, openocd would segfault, each time, always, and the backtrace shows a problem in libusb. At first, I tried compiling openocd myself (from a git clone), and from the dev-embedded/openocd-9999 ebuild. None solved the segfault. I solved this by going back with libusb, masking “1.0.25” and using “1.0.24-r2”, and then recompiling openocd.

Then, openocd would work fine, successfully connecting with my programming dongle, but it would not connect to the g&w. I only have the cheap chinese “stlink v2” kind, and the hack authors clearly recommend against it. I tried to reduce the speed (adapter speed 100 at the end of the file openocd/interface_stlink.cfg), but that would not cut it. The “solution”, was to redo, several times, the wiring between the dongle and the g&w. It would eventually work, and even very reliably so : full speed, never get disconnected, even with some upload taking quite some time.

After that everything went smooth, the MCU was unlocked, the original flash restored, the console would boot as expected.

Installing Retro-GO

It’s almost straighforward as well: you clone the repository, put some roms in the proper directories (roms/*), and do “make flash“. The only problem I’ve had is a linking error, about -lc_nano. This is a part of newlib, which is optional. Gentoo has a USE flag for it (“nano“), but by default crossdev wont set it. So you have to add it on the corresponding line of /etc/portage/package.use/cross-arm-none-eabi:

cross-arm-none-eabi/newlib -selinux -libraries multilib nano

And, of course, to emerge cross-arm-none-eabi/newlib again (emerge -1 …). After this, everything was ok. The script checks the memory, so you wont be surprised. The original flash (1MB) is small and the emulators are using much of it, so I can only put 1 to 3 games (depending on their size). But it works.

Hardware

Next step is to unsolder the flash and solder a new one. I already got the part. But this is now not at all Gentoo specific ! 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *