Early morning at Emerald Lake, Yoho National Park
67 mm   F6   1/80   ISO 200

Two weeks back I posted about running Doom on the Nikon Z 6II, where I also introduced the qemu-expeed emulator I built. Today I want to talk a bit about how this went, and how this has made me feel about using LLMs in the reverse engineering process. For decorative purposes, I inserted some pictures I shot with my Z 6II and the Z 24-200 in summer 2025.

Let me preface this by saying I don’t do this kind of thing professionally. By education I’m a mechanical engineer and by day I work on robotics software, with fancy filtering and control algorithms and quite a bit of math, which is on a far higher abstraction level than this project. In fact, this project was the first time I read assembly. Apart from general software skills, like knowing my way around Linux and Docker, probably most helpful was my bachelor’s in electrical engineering, which included a very decent course in chip design. (I’m grateful my alma mater allowed following a mechanical master after an electrical bachelor.)

Like just about any other software engineer these days, I’ve been using LLMs (often called “GenAI” or even just plain “AI”) at work, and I noticed they were quite decent at getting things to “work” (more on those quotation marks later). That made me wonder whether they could be of help in getting some insight into my Nikon camera.

Camera hacking has a long history, with Magic Lantern by far the most successful project. Originating around 2010 and the Canon EOS 5D Mark II, it has since spread to many Canon cameras and adds very relevant features like waveforms and raw video. Progress on Nikon cameras has been significantly more limited, however, and while Simeon Pilgrim and others of nikonhacker.com clearly put significant effort in this subject, their extensions were mostly limited to enabling and disabling existing features, and their project kind of fizzled out. Similar story for the other brands. As a result, Nikon cameras acquired the aura of being impenetrable.

Today, I know they (well, at least the recent Z-series) are actually extremely hackable once one gets through their obscurity. Coincidentally, I’m not alone in discovering this, as simultaneously the Wonder Lantern project arose, which currently provides firmware extensions for several Z-series cameras. (I’d like to be clear that none of my code or findings originate from the Wonder Lantern project, though their releases did push me to get my work out faster.)

From a firmware update file to running Doom

How about we use an emulator?

Poking at the Nikon firmware purely myself, like the previous projects, would only have led me to run into the same wall as everyone before. So I opted to use agentic LLMs and adapt the working strategy. In classical reverse engineering, the physical device is closely observed, trying to get in through exposed UART and JTAG headers. This approach isn’t very compatible with LLMs, which I don’t trust to leave alone probing, and neither did I want the reverse centaur of me probing on instruction. What I did know, however, is that these agentic LLMs work better the faster they’re confronted with the results of their actions. Therefore I chose to put emphasis on building a good emulator, a piece of code that makes my computer behave like the Z 6II’s hardware. Most importantly, this gave the agent a clear target to work towards - the further the program counter gets, the better.

This emulator-only approach has its limits though, and the reason is that while some hardware components were easy to identify (like the two Cortex-A7 cores and the ARM926 coprocessor), others are basically invisible (like the many hardware accelerators, peripherals, and flash areas not part of the firmware update package). Getting access to the camera’s internals was therefore key. My initial plan was to screw it open and dump bus traffic, though after some coaxing and trial-and-error, the agent got something far better to work: the read-RAM-over-PTP protocol, documented years ago in older Nikons, was still present on the more recent Z 6II, albeit changed slightly. This provided an extraordinary view on the camera’s internals - little need to attach a bus dumper if one can just read the communication buffers. This revealed the communication protocol with the microcontroller (an STM32F412) which interfaces the main Expeed with the buttons and dials as well as the battery. (Fun fact: in one of the first emulator boots, the emulated camera complained hard about not being powered by an authentic Nikon battery.)

Next to dumping bus traffic, this memory read primitive also made it straightforward to read the camera’s internal state because the Cortex-A7, being ARM, has MMIO, so next to RAM I could also read the peripheral registers. Comparing those reads with the same reads in the emulated machine allowed me to pinpoint where the two diverged and especially what correct emulation looks like.

This approach worked pretty well and got the camera booted, but got stuck on the more complex tasks.

Open source

What helped there was the observation that, counter-intuitively, several things of this camera’s software are public, it’s just that Nikon (understandably) does not advertise this. The first one was the OS this camera runs, SMP T-Kernel 1.00.01, a Japanese RTOS. While its code is closed source, TRON Forum helpfully published a very detailed spec which made it straightforward to name all the firmware functions handling OS tasks.

With the already gathered facts in hand, and in combination with some general public knowledge such as that Nikon in the past partnered with Fujitsu and that Nikon’s Expeed is of Socionext Milbeaut lineage I started searching for datasheets and related code. This turned up the Socionext M10V/SC2000, a SoC similar to the Expeed 6 (PCIe Gen2, USB3 device), though with some differences such as having four instead of two Cortex-A7 cores and (as far as I’m aware) the Expeed 6 omitting the HEVC codec. Searching more on Socionext, GoPro caught my eye. As Mark Kirschenbaum of Hypoxic shared in his excellent reverse-engineering blog post, GoPro’s GP1 (their custom SoC that debuted in their HERO6) relates closely to the SC2000. Most importantly, GoPro runs Linux on one of the cores, and following the Linux GPL2 license, this meant they had to distribute their kernel source modifications. While usually not a lot of code, because the kernel takes care of interacting with the hardware, this was exactly what I needed. The GP2 (HERO10) release (I didn’t find a GP1 release) was helpful because it carries material related to both the M20V and the older M10V, and with that provided the register map of the inter-processor mailbox (IPCU, key for emulating the dual-core processor) as well as the SPI, I2C, HDMAC and EXIU peripherals.

Further searches on Linux releases of other manufacturers revealed that the Ricoh GR III and Pentax K-3 III run the SC2000, and their kernel provided the GPIO controller and confirmed the SPI block. Ricoh’s release includes Socionext’s Stubby bootloader, containing code for the M8M clock controller, which after adding some registers happens to fit the Expeed 6. Helpfully, Socionext spent considerable effort in mainlining their kit (thank you!), which gave the SD driver and XDMAC. One of their patches didn’t make it into mainline, but nevertheless provided me the Expeed 6’s counter block. Finally, the PCIe host bridge glue came from Socionext’s SynQuacer server processor. With this approach already having yielded fruitful results, I cast the net even wider, getting the Linux releases of the newer Nikon, Fuji, Panasonic and Sony cameras. Apart from a few remaining bits, this mostly yielded the knowledge that the Expeed 7 may have as siblings the Socionext M20V/SC2006 (Panasonic GH6 and S5II) and perhaps also the Fuji X-Processor 5 (Fuji X-H2). (Fun fact: the Z 6II shares its USB block, a Fujitsu “F_USB30DR”, with the Sony A7 III.)

Disclaimer: I did not have access to any of Nikon’s internal documentation; as such, I pieced this together from public sources, the firmware itself and a large number of educated guesses. Some of it may be wrong. Corrections are welcome at corrections@arnebaeyens.com.

Combined with many RAM reads and a lot of trial and error, this made for a camera with basic functionality working. A nice side effect of using known peripherals is that all of the otherwise fiddly items - like PCIe for example - got operational pretty quickly, and with functionality that generalizes beyond the exact sequence the firmware drives it.

Hiking up to Yoho Pass, overlooking Mount Burgess and the plains leading to Emerald Lake, Yoho National Park
29 mm   F8   1/125   ISO 100

The code

The Doom port thereafter only took an afternoon, as I already knew all the T-Kernel function addresses and had figured out how to execute code with a handful of well-placed RAM writes over PTP/USB. So, the project is a great success, the proof of the new age of AI? Let’s have a closer look.

We shall start by running cloc (Count Lines Of Code) on all committed files. This rolls in at a whopping 344859 lines spread over 723 files. (For the non-software people reading this: usual write speed of a productive programmer is on the order of 100 lines/day, equating those 345 kloc to over 13 years of full-time development.) Now, to be fair, one third of that is due to me storing the firmware annotations in JSON in a line-hungry format. I also let the agent keep a log of all investigations, and this markdown file has grown to 60 kloc. Remaining we have 46 kloc of documentation, 64 kloc of Python tooling, 50 kloc of C code (which is mostly the emulator), and finally another few kloc of various type (git diffs, bash, Dockerfile etc.).

In classical (non-regulated) software development, having documentation expressed in dozens of kloc is basically unheard of. But before we pride ourselves in documenting our project so outstandingly well, let’s take five minutes to read some excerpts from these files.

A first one, from sensor.md, which ought to document the sensor and the Expeed’s front end:

Measured: the whole keyed property space is unset at boot […]

And §3.7 says what those four bytes are, which turns the measurement into an explanation. They read 1f ba 1f 10 — the magic that the region load-failure path stamps. This array is reserved region 0x08 (128 KB at 0xc20d2954), and its loader runs at boot and fails: measured in a block census, 0x103c31aa → 0x103c2bb6 → the storage helpers 0x102a9352/0x102a9308 all execute, and then so do the failure arms 0x103c31c8 (clear) and 0x103c31d0 (stamp the magic). The image template at 0x118b6bf0 is itself 12 non-zero bytes in 128 KB, so there is no factory data to fall back on either.

The keyed property area refers to a flash storage region next to the firmware which Nikon in the factory programs with various calibration and other settings. I dumped that flash region over PTP/USB and made it part of the emulated flash so the camera reads in the correct settings. The doc snippet above originates from before that (so it’s not applicable anymore) and, translated from ClaudeSplain(TM) to laymen’s, it reads “the firmware doesn’t run properly when it’s fed garbage”. Wow what a surprise!

Even worse is that the same applies for all other uses of the config area, which includes about every camera functionality, so it’s not even specific to the sensor. Let’s take another few lines from that file:

Since each Expeed has its own address space (FINDINGS §6 item 10), 0x20060000 on the master and 0x20060000 on the slave are different hardware: two instances of the block, of which the slave’s has considerably more in use. That fits the documented split — the master orchestrates capture while the slave does the pixel work (FINDINGS §10.5) — and it means an emulated sensor has to be installed per cluster, not once. The register file added to expeed6_sif.c is installed inside expeed6_install_soc(), so it already is.

This is Claude blowing things up beyond proportion:

  • “different hardware”: yes, they’re two different chips (the Z 6II runs two Expeed 6 processors), so of course it’s not the same instance. What the LLM is probably referring to is that the first time it put two Expeeds together, it didn’t configure QEMU correctly resulting in them operating in a shared address space, which of course didn’t work. Since then, it feels the need to mention this “learning” everywhere.
  • “an emulated sensor has to be installed per cluster”: uh please no, this camera has only one sensor! The intended meaning may be “emulated sensor frontend”, as the emulator (luckily) has only one sensor. The core issue here is that the next agent will take this wording for fact, perhaps even as a desired state and change the code and documentation toward that. Also, it tends to propagate existing, in this case sloppy, wording, resulting in that after some time, none of the words have the intention as you and I understand them. (And, for that matter, neither does the LLM, with the difference that it never actually understood them in the first place.)

Granted, the documentation also contains better parts. And somewhere, that 46 kloc does contain genuinely useful information. But finding it requires one to search by wading through seas of word salad. (For reference, before publishing qemu-expeed I stripped out all this “documentation”, and the docs in there are all handwritten.)

Unfortunately, this documentation is just the tip of the iceberg. The code is just as terrible. Of all the code, I went through one part, the MIPU, which is the block that converts a raw Bayer image into a YCC one ready for JPEG compression, and to do so applies the white balance, tone curves etc. It’s one of the easiest blocks to emulate because it’s observable: the image that comes out should match the JPEG the camera produces, end of story. Implementing a basic version of this should be a piece of cake, so I handed it off to Claude. How difficult can it be, converting a Bayer RGB image into a YCC one? Very difficult, apparently. Claude decided to implement auto exposure and auto white balance in this block. And then compared output pixel values for known inputs and outputs, and concluded they didn’t match the camera. After some coaching, the agent found the registers of the white balance gains, tone curves and other key processing steps, and with those implemented, the outputs matched pretty well. In doing so, Claude kept all its superfluous logic, treating it as “stand ins” and “fallbacks”. Because yes, if the firmware programs a gain of zero, then the MIPU must use the fallback gain! It did not occur to Claude that x times 0 simply equals 0…

My first efforts to let Claude clean up this code were fruitless. After some time, it explained the reason: it had added tests that assumed that particular auto white balance it dreamed up, and of course those failed when the agent used the registers the firmware wrote. But by rule tests must pass, so it didn’t want to delete those fallbacks. After some stern imperatives and exclamations, repeating them several times until all mentions of “fallback” and “stand in” had disappeared from mipu_model.c, Claude had cut several hundreds of lines, and the file became somewhat releasable. Is it always this bad? No. But it also isn’t anywhere reliably good.

This reverse-centaur babysitting requiring constant vigilance frustrates me to the bone. It takes all the joy, the learnings, the gained insight out of hacking.

Retrospect

Apart from the frustration, what bothers me is that this development process creates a long-term dependency on these machines. There’s no way back that doesn’t involve plowing by hand through a total mess of a codebase. Of course, I can add even more skills, agents, guardrails, testing setups and other harnesses, up to the point where one starts to question whether not to put that engineering effort directly into the project itself, as it’s not like these harnesses generalize and scale well. Equally, I can throw more tokens at it. Which, to be honest, would improve the documentation and code somewhat. But do I really want to burn several tonnes of CO2 equivalent a month on a hobby project? Even if it costs me only a hundred bucks because Anthropic subsidizes this? No, I don’t.

There are a few more reasons for my “no”. Main one: I don’t learn while prompting LLMs to write code. What’s now clearer than ever for me is that I learn by doing. For two days I worked on understanding the firmware image manually, starting with figuring out the firmware’s XOR key and reading the machine code, seeing which registers it programs and decoding the MMU, with the ARMv7-A Architecture Reference Manual next to me. In those two days my skills improved more than in two months of prompting.

I feel for the people working in commercial software development, with many companies facing the lose-lose choice themselves. How do you explain to a client that their flashy vibecoded weekend project is not going to grow into long-term viable business infrastructure? How do you make them pay for long-term quality when a competitor promises more for less?

I guess some readers didn’t expect this critique of LLMs, yet I felt I should write it because it would be dishonest to present only the success story.

The Cathedral Formation, taken from Takakkaw Falls camping grounds, Yoho National Park
73 mm   F8   1/160   ISO 100

Going forward with qemu-expeed

How shall we continue? Recently, the NLnet foundation, an organization which funds selected open source projects, published the following two rules on LLM (GenAI) use (formatting adapted for readability):

  1. It is not allowed to use generative AI for producing artefacts of any kind, including code, design, and documentation.
  2. It is allowed to employ GenAI in a read-only manner […]

I support this decision, because I feel it provides a good trade-off that limits the negative impacts of LLMs while keeping most of their strengths. It’s also close to the direction I want to take with qemu-expeed going forward. Building true understanding of the camera’s workings means you’ll get thorough, readable and mostly correct documentation. But it also means it’ll take time.

This article is part of my series on reverse engineering the Nikon Z 6II and its Expeed 6 processor. If you’d appreciate receiving an email when the next blog post lands, please send any message to qemu-expeed@arnebaeyens.com. (Of course you’re also welcome to subscribe to RSS.)