# game-and-watch-patch：任天堂 Game & Watch 自定义固件

> 面向马里奥和塞尔达两款 Game & Watch 掌机的自定义固件：把新编写的 C 代码修补进使用者自己的原厂固件备份，使原厂固件可与 retro-go 模拟器并存。Python 补丁工具会挂接原厂函数调用，重新定位原厂代码与数据并以 LZMA 压缩以腾出闪存，还能把两款机型的固件合并为一个镜像。仓库提交的符号表、交叉引用分析脚本和分析用 ELF 生成器支撑逆向工作，另有一份日志记录作者首次修补固件的过程。

- 类型：案例
- 目标：固件 · 游戏
- 类别：独立重建案例
- 关联：独立重建项目
- 来源复核于：2026-10-20
- 收录于：2026-11-02
- 原始资源：<https://github.com/BrianPugh/game-and-watch-patch>
- 一手来源：<https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/README.md>
- 目录页面：<https://awesomerea.org/zh/resources/game-and-watch-patch-cfw-case/>
- 记录 JSON：<https://awesomerea.org/resources/game-and-watch-patch-cfw-case/record.json>
- 英文版：[English](https://awesomerea.org/resources/game-and-watch-patch-cfw-case/index.md)

## 使用条件与局限

- 所审阅的 main 提交（2026-10-19）比最后一个标签 v0.12（2025-02-25）多 111 个提交，各版本均未附带二进制文件；代码重定位、合并镜像、分析工具和大部分测试都是在该标签之后加入的。README 列出的马里奥版功能（整个固件放入内部闪存、可移除歌曲彩蛋和睡眠插图、超时设置、时钟图形修改）多于塞尔达版，并称塞尔达版节省外部闪存的功能尚待实现。
- 需要使用者自己马里奥或塞尔达机型的内部与外部闪存备份，命名为 internal_flash_backup_<device>.bin 和 flash_backup_<device>.bin 放入仓库；补丁工具会拒绝 SHA-1 与原厂固件不符的镜像。仓库未提交任何固件、ROM 或密钥：tools/re/README.md 说明 .syms 文件只含项目自己的注释，并要求绝不提交由任天堂固件派生的 ELF；docs/mario.md 也说明仓库不托管任何 ROM 或 ROM 修改补丁。
- 目标硬件是掌机所用的 STM32H7B0 微控制器。构建需要 GNU Make、arm-none-eabi GCC 工具链和 Python 3.6+，以及 Pillow、NumPy、pycryptodome、pyelftools、capstone 和 colorama；烧录使用 gnwmanager，马里奥版的仅内部闪存模式还需要打过补丁的 OpenOCD，以使用未公开的额外 128 KB 内部闪存。基于 Ubuntu 22.04 的 Dockerfile 会为 x86-64 Linux 主机安装 gnwmanager 提供的 OpenOCD 和 Arm 工具链。
- tests/test_golden.py 按固定选项组合重新构建，并将输出的 SHA-1 与 tests/golden.json 比对；这些哈希针对 Arm GNU Toolchain 15.2.Rel1 记录，缺少原厂备份或 GCC 版本不同时会跳过。其他单元测试涵盖重定位、Thumb 汇编、布局和符号，tools/emu 则在 GWemu 模拟器中对修补后的镜像运行菜单测试。CI 只运行 pre-commit 代码检查并构建 Docker 镜像。
- COPYING 为 BSD-3-Clause（2020，Konrad Beckmann、Thomas Roth、STMicroelectronics）；随仓库提供的 ST CMSIS 与 HAL 源码保留各自声明，原厂固件和游戏仍归任天堂所有。仓库中的 CLAUDE.md 是写给 Claude Code 的指引。

## 一手来源

1. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/README.md>
2. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/COPYING>
3. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/Makefile>
4. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/requirements.txt>
5. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/docker/Dockerfile>
6. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/patches/firmware.py>
7. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/patches/amalgam.py>
8. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/tools/re/README.md>
9. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/tools/emu/README.md>
10. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/tests/test_golden.py>
11. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/tests/golden.json>
12. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/docs/journal.md>
13. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/docs/mario.md>
14. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/.pre-commit-config.yaml>
15. <https://github.com/BrianPugh/game-and-watch-patch/blob/857bb80fe77b60b6dabbadeae703577cc50f8645/CLAUDE.md>
16. <https://github.com/BrianPugh/game-and-watch-patch/releases/tag/v0.12>

## 同分区更多条目：游戏

- [GTA Mode：逆向 SimCity 3000 Unlimited 并开发原生插件](https://awesomerea.org/zh/resources/simcity-3000-gta-mode-case/index.md) · 案例
- [《声名狼藉：次子》原生 PC 移植](https://awesomerea.org/zh/resources/infamous-second-son-pc-port-case/index.md) · 案例
- [Left 4 Dead 2：还原 AI Director 的运行机制](https://awesomerea.org/zh/resources/l4d2-director-research-case/index.md) · 案例
- [MTG Arena Collection Export：重建 Frontdoor 卡牌收藏请求](https://awesomerea.org/zh/resources/mtg-arena-collection-export-case/index.md) · 案例
- [OpenPigeon：重建 GamePigeon iMessage 游戏消息](https://awesomerea.org/zh/resources/openpigeon-case/index.md) · 案例
- [ProjectCane：《Sly Cooper and the Thievius Raccoonus》原生 PC 移植](https://awesomerea.org/zh/resources/projectcane-sly1-pc-port-case/index.md) · 案例

## 关于此条目

说明已依据一手来源复核。
原创说明采用 MIT 许可；外部项目、论文与素材保留各自的权利和许可。
