⚡ The main thing in 60 seconds (TL;DR)
⏱ ~ 20 мин чтения- Doom on a children's camera It all started with an idle question: what kind of firmware is in this camera? Ended up with two days and a few late nights...
- Doom on a children's camera It all started with an idle question: what kind of firmware is in this camera?
- During this time, an SDK, a local emulator, its own compiler and a full-fledged port of Doom appeared, which runs on the camera with only 891 KB of free RAM.

It all started with an idle question: what kind of firmware is in this camera? Ended up with two days and several late nights of reverse engineering a completely undocumented SoC (system on a chip). During this time, an SDK, a local emulator, its own compiler and a full-fledged port of Doom appeared, which runs on a camera with only 891 KB of free RAM. At the same time, she did not stop being a camera.
Let me clarify right away: this is not Doom for show. The controls are laid out in such a way that the game can actually be played. All sounds work, there is chiptune music, you can save and load, and all this runs at about 30 fps. Doom is in your pocket.
Have you done this before? It’s easier to ask where Doom hasn’t been ported yet, but I found only two similar examples. The first is Ilya Kurdyukov's video: there is a Spreadtrum SC6531 chip with 4–8 MB of RAM, and the author does not tell how it is done. The second is video LGR, where there is essentially a whole computer inside, again with a large amount of memory and a full SDK. Our task turned out to be much more difficult.
I documented everything I did in detail on GitHub: there is an analysis of the firmware and chip design, a utility for removing the firmware from your camera via USB, SDK, compiler patches and the Doom port. You can repeat everything yourself or apply the same techniques to something similar. This article tells how we got there, and the repository will help you get there.
Camera

Here she is. There is nothing useful on the box: no manufacturer, no address, no name, and the interface is also empty. It looks like it was made this way specifically so that it could be sold under any brand and so that no one would have to answer for it. The only identifying mark is the X9S model in the instructions.
USB identifiers didn't give anything either. This thing almost didn’t exist on the Internet, except for ads on AliExpress.
Then I looked at one of the pictures and found a clue in the EXIF: the manufacturer was listed as HX-Tech. This led me to the article by Sprite_tm (Jeroen Domburg) Kid-cam firmware modding. He had a slightly different camera with completely different firmware, and he wanted to change very little. His work gave us a good starting point (such as what processor to expect), but it was not enough. The camera had to be opened, otherwise there would be no further progress.
What's inside
I was afraid to open it: my daughter loves this camera, and I really didn’t want to break it. But I'm already too involved. I took out a soldering iron and unsoldered the battery so that I could safely work on the board.

Inside I found the markings of the chip, HX3302B (I didn’t find any mention of it anywhere else), and an eight-legged flash memory chip. It all came down to reading this microcircuit, and I was lucky: I had the right tool at hand, the XGecu T48 programmer, which I regularly use when repairing motherboards. You'd be surprised how common data corruption is on boards over 20 years old.

I have a clip that fits on top of the chip so as not to desolder it from the board, but installing such clips is painful, and they don’t hold well. Here I had to press it with both hands and press the mouse button with my little finger. It took several attempts, and I believed that there were no reading errors only when three dumps coincided.
The real work began with this dump.
Claude steps in
Not long before this, I spent a lot of time decompiling Indiana Jones and the Infernal Machine with an exact byte match, helping the OpenJones project. Therefore, I had a good understanding of how strong AI is at decompiling and reverse engineering, but I also knew its weak points and how to get the most out of it.
This experience came in handy: soon Claude and I were running Ghidra and taking the firmware apart. Sprite helped, which had already identified the processor and published a processor description for it for Ghidra. We quickly noticed that despite all the similarities between the chips, our firmware was completely different: the update file, for example, was called Xly100s.bin, for Sprite it was hx330x_sdk.bin.
First stitched edit
From the Sprite article we already knew that such cameras can be updated from a file on the SD card. Reading the firmware code, we first found out exactly how the recording proceeds, and the main thing is that the update partial: recording starts from the beginning of the flash memory and continues exactly the length of the file. Slide in a 1 MB file, and the first megabyte will be flashed, while the remaining three will remain untouched. This was important: we could make small point edits and rewrite only the necessary part, without touching everything that lies further.
Thanks to T48, we always had an emergency way back: the original firmware could be uploaded directly. But fiddling with the clip was laborious, and we wanted to avoid it. It was much easier to update from an SD card.
Additionally, although there is a checksum in the header, the camera never verifies that it is correct. Theoretically, to start flashing, it was enough to shift the timestamp in the header by a second. Judging by the code, an update check is performed every time the camera is turned on.
So we started with no real changes at all: just the first few kilobytes of flash memory with a changed timestamp. The goal was to run the flashing, see the update screen and make sure we were on the right track. Since only the time stamp was changed, reflashing cannot be safer.
We waited for a new label to appear on the version screen, but that didn't happen, and as far as we could tell, nothing happened at all. Therefore, for quite a long time we were looking for some secret launch conditions.
At the same time, I discovered that if you hold the shutter on the battery screen for 5 seconds, the camera goes into a special test mode labeled TEST ON. We found this line in the firmware and replaced it with HACK ON. The file turned out to be much larger, about 770 KB, and finally a progress bar appeared. And when we entered test mode again, the inscription was still there:

The hack actually took place, but we were looking for secret conditions in vain. Previous updates worked, they were just so small that the progress bar did not have time to appear, and our edits did not make a noticeable difference.
EXIF to the rescue
We now have the firmware method, and it’s time for the first real code edit. We chose an EXIF trick that Sprite cleverly used on its camera that gave valuable information about the device even before major changes.
If you haven’t encountered this, EXIF is a block of information at the very beginning of the image file: which camera was taken, when, with what settings (usually on the phone and where). In JPEG you can reserve up to 64 KB for it, and this camera uses about 730 bytes, about 1%, so there is plenty of free space without anyone looking there.
Sprite's idea was to use this location as a dumping ground for memory dumps. You change the code that writes the metadata of the photo so that instead it writes a piece of the memory of the camera itself, and then you read it from the SD card directly from the photo.
This trick itself allows you to remove up to 64 KB per photo, and from the camera's main RAM it worked the first time: one photo, one big piece. But with the memory that interested us most, with the small internal starting memory, nothing came of it. The snapshot is written to the SD card by a hardware unit that does not see this memory, so only zeros are returned. We had to force the camera's own processor to copy the memory into the photo, but there was only enough space for 4 KB at a time, so we made the process step by step. A counter in the camera's memory shifted the window after each shot, and each subsequent frame captured another 4 KB. Took 16 pictures and got all 64KB straight from the SD card.
It gave us a lot. The camera's internal memory matched byte for byte with the beginning of our firmware dump, as did part of the main RAM, which means those parts of the dump were correct. It also turned out that the code that the firmware calls and which we thought was hidden in the ROM, is in fact just part of the startup code in flash memory, so everything that the camera performs was already in the dump. (At the same time, our mistake was also revealed: the “ROM” that we kept trying to read returned only zeros, because we incorrectly calculated the addresses. It was the memory dump that finally helped to fix this.) And by sorting through the memory one megabyte at a time, we found out how much RAM there was in the camera: at the request for the third megabyte, it rebooted. So, two megabytes. But that's where the trick's possibilities ended. He gave us a map of the camera's memory, but didn't show us what the code actually did, so to really understand the firmware we had to look at the code itself.
First fix
There was a firmware method and a memory card, it remained to decide what to reverse first. One candidate asked himself, and it was especially nice to correct him because he always annoyed me. In the camera settings, one of the menu items is called Systerm Volume. It would seem that it’s easy to correct a typo: you find the text, change it, and you’re done. It’s just that there is no such text as text in the firmware. The search finds nothing in any encoding.

It turned out that the camera has its own bitmap font with several hundred glyphs (Latin, Cyrillic, Thai, Chinese, Korean, Arabic...), and each menu line is stored as a list of glyph numbers for each of the 18 supported languages. We had to parse the format of these tables, write a script that drew the lines in the font of the camera itself so that we could see what we were looking at, and then find the right English line. We are one step closer to understanding the code, and the annoying typo has disappeared.
Now tests
The first fix gave us more confidence, and we began to disassemble the firmware seriously, just to understand how it works. The area where games are launched was quickly found, and it seemed like the safest place for larger code. This code is launched only from the games menu; the update check is triggered earlier, immediately when the camera is turned on. No matter how we broke everything, there was always a way back.
We've been writing in assembly language so far and have made a series of small programs and benchmarks to collect data: button presses, how much RAM is actually free, how everything is laid out in memory, how fast the RAM is read and written, how fast the processor is, and how to work with the display.

Once the results were collected, we finally understood what we were dealing with:
CPU: ~120 MIPS (millions of simple instructions per second) at best, or ~82 if a branch occurs every few instructions.
L1 cache: 8 KB instruction and 8 KB data, ~164 MB/s read/write.
RAM: 2 MB, read ~65 MB/s, write ~37 MB/s. For our purposes, only 891 KB are free.
Flash memory: 4 MB (the same chip with firmware), read only ~4.4 MB/s. Code that fits in the instruction cache runs as fast from flash as it does from RAM, but code that doesn't is about 18 times slower.
Display: 320×240, 256 colors, palette can be changed.
The comparison isn't exactly direct, but it's something close to the 486 DX4/100 with its roughly 100 MIPS and memory speeds about the same as an early Pentium.
In other words, we had something like a fast 486 with Pentium-speed memory and less than a megabyte of RAM.
At this point I was already asking myself what my ultimate goal with this device was. But, looking at the numbers, I chuckled and asked a question: what do you think, will we launch Doom? The specs were very reminiscent of the machines it ran great on back in the day, just without the full 4MB of RAM it needed. We had half as much, and most of it was already taken.
Porting Doom
We started with doomgeneric, a version of Doom specifically designed to be easily portable to all sorts of stupid devices like our camera. You provide a few functions (draw a frame, read a key, tell the time) and it does the rest.
Since we already had our own compiler and emulator, it turned out to be quite simple to transfer the code to our version of OpenRISC. The real problem was how little memory we had. Doom is designed for a machine with 4 MB, there are only 2 of them in the camera, and only 891 KB of them are free after the firmware takes its share. They must fit two different things: the game code and its working memory, that is, textures, levels and sounds that it loads and shuffles during the game.
Looking for more RAM
Working memory is a bigger problem: Doom continually draws from a large pool while the game is running. So we went looking for more. We wrote a simple placeholder program that did everything the game needed (played sounds, read keys, drew on the screen, read from the SD card), and measured which areas of the camera's memory changed while it was running. Everything that the firmware had never touched became a candidate for borrowing.
Unfortunately, what looked safe often wasn't: recording there would reset the camera. We had to go back and forth for a long time until we squeezed everything out to the last byte and brought the volume available to Doom to about 1.4 MB, albeit in many disparate pieces.
This is a big step up from 891 KB, but it's still a long way from the 4 MB Doom was written for. New tricks were required.

Bill Gates almost certainly never said this, but it was fitting.
Fragmentation made everything worse. Part of the problem was the memory itself: those 1.4 MB consisted of many individual chunks, so the largest block we could produce was much smaller than the total volume. The rest was up to Doom's memory management: it was designed for a machine with space to spare and didn't really care about where things went. Small allocations ended up in the middle of the space needed by large ones, and crushed it into unusable pieces, so that an object that needed 64 KB in one piece could not find them, although there was enough free memory. We have given small discharges a separate reserved area so that they do not interfere with larger ones.
In addition, Doom reads graphics, sounds, and levels from the SD card as needed and dumps them from RAM when memory becomes low; He already knows how to do this. We just made sure that the right things were thrown out, like sound effects, and that the level data was cleared at the end of the level. This way we didn’t have to reboot everything from the slow card.
Execute code from flash memory
The game code was a separate issue and claimed the same RAM. Usually the entire program is loaded into RAM, but there was not even close space for this. Instead, code can be executed directly from the flash memory chip, but the benchmark showed that this is brutally slow: code that did not fit in the processor's tiny cache ran from flash memory about 18 times slower than from RAM. But you don’t have to choose just one. Some of the code might live in RAM and the rest in flash memory, and the question came down to which parts went where.
To find out, we profiled Doom in our emulator and recorded which parts of the code were actually executed during the game. It turned out that 99% of the time was spent on approximately 29 KB of code out of 260 KB; everything else is the start code, menu, automap, screens between levels, etc. So we put that hot little core in RAM, and left everything that rarely runs in flash, where the slowness doesn't bother us. This freed up hundreds of kilobytes of RAM for working memory, and Doom ran at the same speed as the entire RAM version.
Speed, sound and music
In addition, we speeded up by bypassing the firmware's key event system and reading the keys directly. It turned out that the main firmware loop itself was eating up about 38 milliseconds of each frame, so we wrote our own game loop and the frame rate roughly doubled. Direct key reading also made it possible to make the power button playable so that it doesn't just turn off the camera.
When the game worked as it should, we took on the sound and music. The camera can only play one audio stream, and Doom expects to play many sounds at once, so we wrote a software mixer that mixes all of Doom's sound effects into this single stream.
With music it was more difficult. Doom music is stored as a compact score in the MUS format, which is very similar to MIDI: a list like “play this note on this instrument at this volume.” On PC, Doom plays it through an FM synthesizer chip, which is not in the camera. It would be possible to emulate this chip, but it is too heavy for the processor. We also considered the option of pre-rendering the music to MP3 and using the camera's built-in decoder, but this seemed inauthentic.
Instead, we wrote our own tiny synthesizer. He reads the score and plays it with 16 voices, each of which is a simple wave (square, triangle or sawtooth, depending on the type of instrument) with a base volume envelope, and noise for the drums. All this is mixed into the same thread as the sound effects, and costs about 2% of the processor. As a result, classic Doom music sounds like an old video game console, very chiptune-like.
Before we put it all on camera, we compiled a synth for the PC and rendered the first music files there so I could evaluate them. It was up to me to decide if they were good enough, and I immediately fell in love with them. The ability to test on a PC helped a lot. Here are the first 30 seconds of two Bobby Prince compositions: At Doom's Gate (E1M1) and Dark Halls (E1M3). This is a PC render from the same code that runs on the camera; No sound was recorded from the camera itself.
How to control Doom on camera?
Luckily the camera has four directional buttons, which solved the main problem, but the rest of the buttons required some compromises, if not some good solutions.
The shutter fires. This is obvious, and when held down, shooting continues, which became possible only after switching to direct key reading.
To change weapons, use the power button: a single press cycles through the weapons until you reach the one you want. Long press works like Escape and opens the menu. If the menu is already open, a short press is enough to return.
Since we took away the power button, it no longer turns off the camera. To turn it off, you need to select the option to exit the game in the Doom menu and confirm with the shutter, which works like Enter.
Loading and saving usually ask you to enter the name of the save, so we made it so that they are named by the slot number themselves (Save 1, Save 2, and so on).
Finally, there was no free button for “use,” so we track when you get close to something and keep pressing, and then the object activates. Step back and push again and it will trip a second time, which is ideal for turning breakers on and off. It works well, and a nice side effect is that you can just run on the doors and they open without any button.
When the menu is open in the middle of an intense game, the camera falters a bit. I suspect the reason is that the menu is rarely used and its code is in slow flash memory. I didn’t try to improve this: it doesn’t affect the gameplay, and you shouldn’t worry about such a borderline case.
I'm very pleased with the result: it plays great. It took only two days from the first firmware to working Doom, including late-night debugging, and I spent exactly the same amount of time on this article and documentation on GitHub.
Reading firmware via USB
When Doom started working, I wanted other owners of similar cameras to be able to use our work. The obvious solution would be to post my firmware dump, but this looked legally dubious and would only be useful to those who have exactly the same firmware. Even if I reversed everything back to C, there would still be resources there that I have no right to share. So I wanted to give people a way to dump themselves without opening the device. Unfortunately, there was no direct interface for this.
But we found a SCSI command on the USB device (yes, that same SCSI, it's still alive!), which allowed the computer to ask the camera to execute code at any address. Such a thing could be used quite universally to access the device, but any attempts to get Claude to do anything with it were thwarted due to security concerns, and this line of work stopped.
Luckily, my good friend Jack had a subscription to Kimi and loaned it to me for a few hours. Kimi had no such doubts. He went through the firmware, wrote a series of tests to understand what was happening, and eventually came up with an ingenious trick: write a small stub into the camera's RAM that reads the flash memory and returns it in small chunks, and then runs it again and again until everything is read. No firmware or opening of the camera is required. The camera's own processor becomes an intermediary for reading its own flash memory.
The dump taken by the programmer allowed us to check the result, and it matched. This is of little use to me myself, but I hope it will be useful to someone else! An important caveat: the reception uses specific addresses of this firmware, so it may well only work on this version. I'd be glad to know if someone tries it on a different one.
What would I do differently and what's next?
What would I do differently? I would put down the USB cable and say, “Jesus, Spode, find something better to do.”
But now we have solid documentation and some kind of SDK for something that previously did not exist on the Internet at all. Before returning the camera to my daughter, I installed the original firmware back, but now I can begin the second stage: simplifying the camera interface and updating the games, adding some of Spode's Playground. When she gets tired of it, I'll put Doom back on and the camera will sit on my shelf like a trophy.
If you have such a camera (or a similar one), the repository has everything: a utility for removing firmware via USB without opening it and a script that turns your dump into an update from Doom. I'd love to hear how it turns out for you.
💬 Discussion 0
BBCode & Emoji supportedParticipate in discussions, ask authors questions, and share benchmarks by joining the ProArena engineering community.